...
|
...
|
@@ -108,6 +108,9 @@ const userController = { |
|
|
*/
|
|
|
async newWechatUserCallback(req, res) {
|
|
|
let {code = 10005, state} = req.query;
|
|
|
console.log('query:', req.query);
|
|
|
console.log(req.session);
|
|
|
console.log('state:', _.get(req.session, 'user', ''));
|
|
|
|
|
|
try {
|
|
|
if (code.toString().length > 5 && state === _.get(req.session, 'user.wechatState', '')) {
|
...
|
...
|
@@ -115,6 +118,9 @@ const userController = { |
|
|
let appSecret = config.wechatLogin.appSecret;
|
|
|
let WECHAT_GET_TOKEN = 'https://api.weixin.qq.com/sns/oauth2/access_token';
|
|
|
let WECHAT_GET_USERINFO = 'https://api.weixin.qq.com/sns/userinfo';
|
|
|
|
|
|
console.log(WECHAT_GET_TOKEN + '?appid=' + appId + '&secret=' + appSecret + '&code=' + code + '&grant_type=authorization_code');
|
|
|
|
|
|
let tokenResult = await request({
|
|
|
url: WECHAT_GET_TOKEN,
|
|
|
qs: {
|
...
|
...
|
@@ -126,7 +132,7 @@ const userController = { |
|
|
json: true
|
|
|
});
|
|
|
|
|
|
console.log(tokenResult);
|
|
|
console.log('newWechatCallback', tokenResult);
|
|
|
|
|
|
if (!tokenResult.errcode) {
|
|
|
let access_token = tokenResult.access_token;
|
...
|
...
|
@@ -142,6 +148,7 @@ const userController = { |
|
|
});
|
|
|
|
|
|
let userInfoStr = JSON.stringify(userInfo);
|
|
|
console.log('userInfoStr:', userInfoStr);
|
|
|
|
|
|
let referer = `${siteUrl}/passport/user/wechatCallback`;
|
|
|
let note = referer.indexOf('?') > 0 ? '&' : '?';
|
...
|
...
|
@@ -176,19 +183,19 @@ const userController = { |
|
|
let WECHAT_LOGIN_URL =
|
|
|
`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appId}&redirect_uri=${redirect_uri}&response_type=code&scope=${scope}&state=${state}#wechat_redirect`;
|
|
|
|
|
|
if (referer && (referer.indexOf('yoho.cn'))) {
|
|
|
console.log('WECHAT_LOGIN_URL:', WECHAT_LOGIN_URL);
|
|
|
console.log('referer', referer, referer.indexOf('yoho.cn'));
|
|
|
if (referer && (referer.indexOf('yoho.cn') >= 0)) {
|
|
|
_.set(req.session, 'user.wechatReferer', referer);
|
|
|
_.set(req.session, 'user.wechatState', state);
|
|
|
res.redirect(WECHAT_LOGIN_URL);
|
|
|
console.log(req.session);
|
|
|
// res.redirect(WECHAT_LOGIN_URL);
|
|
|
} else {
|
|
|
res.json({
|
|
|
code: 200,
|
|
|
message: INVALID_REFERER
|
|
|
});
|
|
|
}
|
|
|
console.log(WECHAT_LOGIN_URL);
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
...
|
...
|
|