Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

原先作为sessionId的依据为FromUserName,应考虑到多个商家可能出现用户id重复的问题 #29

Merged
merged 4 commits into from
Aug 13, 2013
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions lib/wechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,13 @@ var respond = function (handler) {
if (req.sessionStore) {
var storage = req.sessionStore;
var _end = res.end;
var openid = message.FromUserName;
var userOpenid = message.FromUserName;
var serviceOpenid = message.ToUserName;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

缩进也有问题

var _str = serviceOpenid + ":" + userOpenid;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不用hash吧?

var _hash = crypto.createHash("md5");
_hash.update(_str);
var _hashmsg = hash.digest('hex');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的hash未定义。测试都broken了

var hashid = _hashmsg.toString();
res.end = function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var openid = message.FromUserName + ':' + message.ToUserName;

只改这一句就好了

_end.apply(res, arguments);
if (req.wxsession) {
Expand Down Expand Up @@ -166,12 +172,12 @@ var respond = function (handler) {
res.reply.apply(res, arguments);
};

storage.get(openid, function (err, session) {
storage.get(hashid, function (err, session) {
if (!session) {
req.wxsession = new Session(openid, req);
req.wxsession = new Session(hashid, req);
req.wxsession.cookie = req.session.cookie;
} else {
req.wxsession = new Session(openid, req, session);
req.wxsession = new Session(hashid, req, session);
}
done();
});
Expand Down