Authored by 郭成尧

Merge branch 'hotfix/wx-share' into 'master'

微信分享appi 改成活动的

把微信分享的appId 和appSecret 修改成了可配置的 默认值是原先的值(女生志)

See merge request !59
... ... @@ -6,9 +6,13 @@
const wechatModel = require('../models/wechat');
exports.wechatShare = (req, res, next) => {
wechatModel.calcSignature({
let params = {
appId: req.query.appId || 'wxb52ec6a352f0b090', //此处使用的是 女生志 的appId
secret: req.query.secret || '9fe6bedb0b7f30986a168c7fc44f34c0',
url: req.query.url || 'http://www.yohobuy.com/'
}).then((result) => {
};
wechatModel.calcSignature(params).then((result) => {
res.jsonp(result);
}).catch(next);
};
... ...
... ... @@ -12,8 +12,8 @@ const logger = global.yoho.logger;
const cache = global.yoho.cache;
// 此处请勿使用有货公众号的 appId, 此处使用的是 女生志 的appId
const appId = 'wxb52ec6a352f0b090';
const secret = '9fe6bedb0b7f30986a168c7fc44f34c0';
// const appId = 'wxb52ec6a352f0b090';
// const secret = '9fe6bedb0b7f30986a168c7fc44f34c0';
const sha1 = (str) => {
const generator = crypto.createHash('sha1');
... ... @@ -27,7 +27,7 @@ const ticketCacheKey = 'wechatShare:ticket';
// 微信 JS 接口签名校验工具 http://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=jsapisign
let _getAccessToken = Promise.coroutine(function* () {
let _getAccessToken = Promise.coroutine(function* (appId, secret) {
let accessToken = yield cache.get(accessTokenCacheKey);
if (accessToken) {
... ... @@ -35,6 +35,7 @@ let _getAccessToken = Promise.coroutine(function* () {
}
logger.info('get accessToken from wechat API');
return request({
url: 'https://api.weixin.qq.com/cgi-bin/token',
qs: {
... ... @@ -55,7 +56,7 @@ let _getAccessToken = Promise.coroutine(function* () {
});
});
let _getTicket = Promise.coroutine(function* () {
let _getTicket = Promise.coroutine(function* (appId, secret) {
let ticket = yield cache.get(ticketCacheKey);
if (ticket) {
... ... @@ -66,7 +67,7 @@ let _getTicket = Promise.coroutine(function* () {
return request({
url: 'https://api.weixin.qq.com/cgi-bin/ticket/getticket',
qs: {
access_token: yield _getAccessToken(),
access_token: yield _getAccessToken(appId, secret),
type: 'jsapi'
},
json: true
... ... @@ -86,8 +87,7 @@ let calcSignature = Promise.coroutine(function* (data) {
data = Object.assign({
nonceStr: Math.random().toString(36).substr(2, 15),
timestamp: Math.floor(Date.now() / 1000) + '',
ticket: yield _getTicket(),
appId: appId
ticket: yield _getTicket(data.appId, data.secret)
}, data);
const str = `jsapi_ticket=${data.ticket}&noncestr=${data.nonceStr}&timestamp=${data.timestamp}&url=${data.url}`;
... ...