...
|
...
|
@@ -58,9 +58,7 @@ let calcSigature = function(ticket_res, res) { // 计算signature |
|
|
let url = ticket_res.url;
|
|
|
let str = `jsapi_ticket=${ticket}&noncestr=${nonceStr}×tamp=${timestamp}&url=${url}`;
|
|
|
let signature = sha1(str);
|
|
|
|
|
|
console.log(str + '&signature=' + signature);
|
|
|
|
|
|
|
|
|
let result = {
|
|
|
appId: appID,
|
|
|
nonceStr,
|
...
|
...
|
@@ -69,7 +67,6 @@ let calcSigature = function(ticket_res, res) { // 计算signature |
|
|
signature
|
|
|
};
|
|
|
|
|
|
// console.log('result', result);
|
|
|
return res.jsonp(result);
|
|
|
};
|
|
|
|
...
|
...
|
@@ -85,7 +82,6 @@ let getResult = function(wechat_res, req, res, next) { // 向微信接口获取a |
|
|
.then(result => { // 先获取accessToken
|
|
|
let access_token = result.access_token;
|
|
|
|
|
|
console.log('token:', access_token);
|
|
|
return getTicket(req, access_token, next, appID, appSecret, mpPrefix)
|
|
|
.then(ticket_res => { // 通过accessToken获取ticket
|
|
|
if (ticket_res && ticket_res.ticket) {
|
...
|
...
|
@@ -94,7 +90,6 @@ let getResult = function(wechat_res, req, res, next) { // 向微信接口获取a |
|
|
let create_time = moment().format('YYYY-MM-DD HH:mm:ss');
|
|
|
let expired_time = moment().add(expired, 'seconds').format('YYYY-MM-DD HH:mm:ss');
|
|
|
|
|
|
// console.log('ticket_res:', ticket_res);
|
|
|
req.ctx(WechatModel).
|
|
|
saveAccessKeys(access_token, access_ticket, create_time, expired_time, type)
|
|
|
.then(() => {
|
...
|
...
|
@@ -132,14 +127,12 @@ const wechatShare = { |
|
|
|
|
|
req.ctx(WechatModel).getAccessKeys()
|
|
|
.then(keys_res => { // 先查询数据库中是否有access_token并且未过期
|
|
|
console.log(keys_res);
|
|
|
if (keys_res.length > 0) {
|
|
|
let access_token = keys_res[0].access_token;
|
|
|
let access_ticket = keys_res[0].access_ticket;
|
|
|
let expired = new Date(keys_res[0].access_expired).getTime();
|
|
|
let now = Date.now();
|
|
|
|
|
|
console.log('data_time!', expired, now, keys_res[0].access_expired);
|
|
|
if (now > expired) { // 过期则去 取新的token与ticket 并且更新数据库
|
|
|
return Promise.reject({
|
|
|
type: 'update'
|
...
|
...
|
|