Authored by 邱骏

update

... ... @@ -39,6 +39,8 @@ global.yoho.utils = {
yoho: Yoho
};
console.log('1234');
app.use(cookieSession({
name: 'yoho_activity',
secret: 'activity@yoho',
... ...
... ... @@ -62,7 +62,7 @@ let calcSigature = function(ticket_res) { // 计算signature
let str = `jsapi_ticket=${ticket}&noncestr=${nonceStr}&timestamp=${timestamp}&url=${url}`;
let signature = sha1(str);
// console.log({appID, ticket, nonceStr, timestamp, url, str, signature});
// console.log('calcSigature:',{appID, ticket, nonceStr, timestamp, url, str, signature});
return {
appId: appID,
nonceStr,
... ... @@ -108,14 +108,14 @@ const wechatShare = {
req.ctx(WechatModel).getAccessKeys()
.then(keys_res => { // 先查询数据库中是否有access_token并且未过期
// console.log('keys_res:', keys_res);
if (keys_res.code === 200) { // code=200说明数据库中查找到数据并且未过期
delete keys_res.code;
return Object.assign({
return Promise.resolve(Object.assign({
appID,
url
}, keys_res);
}, keys_res));
} else if (keys_res.code === 201) {
// code=201说明数据库中没有数据,或者数据已过期,根据返回的type判断是添加还是更新
... ... @@ -149,6 +149,7 @@ const wechatShare = {
}
})
.then(result => {
// console.log('result:', result);
let calc_res = calcSigature(result);
if (req.query.callback) {
... ...
... ... @@ -16,6 +16,12 @@ const excel = require('./controllers/excel');
const multipart = require('connect-multiparty');
const mutilpartMiddleware = multipart();
router.get('/test', (req, res) => {
req.session.test = '1234';
res.json({
test: req.session
});
});
router.get('/gettoken', qiniu.getToken);
router.get('/share/getSignPackage', wechat.getSignPackage);
router.get('/prize/checkPrize', prize.checkPrize);
... ...
... ... @@ -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);
},
/**
... ...
... ... @@ -95,10 +95,10 @@ module.exports = {
},
mysql: {
connect: {
host: '0.0.0.0',
host: 'localhost',
port: '3306',
user: 'root',
password: '123456'
password: ''
},
database: 'yoho_activity_platform',
},
... ... @@ -118,7 +118,6 @@ module.exports = {
wechatLogin: {
appID: 'wxb785b12717bc31e9',
appSecret: 'fb0bc348577b1e38576c6fe654da5135',
}
};
... ...
/*
true
@author: qiuj <jun.qiu@yoho.cn>
@date: 2018-08-16 14:27:44
*/
#注意:GO;分割执行块
#优惠券码表
DROP TABLE IF EXISTS `act_coupon_no`;
GO;
CREATE TABLE `act_coupon_no` (
`id` int(8) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`coupon_id` int(8) NOT NULL,
`coupon_no` varchar(50) DEFAULT NULL,
`send_flag` int(2) NOT NULL DEFAULT '0',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) DEFAULT CHARSET=utf8;
GO;
#用户领券信息表
DROP TABLE IF EXISTS `act_coupon_user`;
GO;
CREATE TABLE `act_coupon_user` (
`id` int(8) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`coupon_id` int(8) NOT NULL,
`coupon_no_id` int(8) NOT NULL,
`user_id` int(8) NOT NULL,
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) DEFAULT CHARSET=utf8;
GO;
#优惠券表
DROP TABLE IF EXISTS `act_coupon`;
GO;
CREATE TABLE `act_coupon` (
`id` int(8) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`coupon_name` varchar(50) NOT NULL,
`coupon_desc` varchar(400) DEFAULT NULL,
`shop_name` varchar(50) NOT NULL,
`shop_logo_url` varchar(200) NOT NULL,
`status` int(2) NOT NULL DEFAULT '0',
`type` int(2) NOT NULL DEFAULT '0',
`sort` int(8) NOT NULL DEFAULT '0',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) DEFAULT CHARSET=utf8;
... ...
module.exports = ['_migration', '20170913102356', '20170927092926', '20171025145423', '20171102104558', '20171115144710', '20180131104311', '20180402134610', '20180413105509', '20180719134813', '20180806151252'];
module.exports = ['_migration', '20170913102356', '20170927092926', '20171025145423', '20171102104558', '20171115144710', '20180131104311', '20180402134610', '20180413105509', '20180719134813', '20180806151252', '20180816142744'];
... ...