Skip to content

Commit

Permalink
timeStamp is not a string for app bug fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Mirshat committed Nov 30, 2017
1 parent de2d596 commit 3ca455a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 33 deletions.
33 changes: 16 additions & 17 deletions lib/WechatPayment.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ var WechatPayment = function () {
prepayid: prepayId,
package: 'Sign=WXPay',
noncestr: _utils2.default.createNonceStr(),
timestamp: parseInt(new Date().getTime() / 1000)
timestamp: parseInt(new Date().getTime() / 1000).toString()
};
configData.sign = _utils2.default.sign(configData, this.options.apiKey);
return configData;
Expand Down Expand Up @@ -350,7 +350,7 @@ var WechatPayment = function () {
_context.prev = 0;

if (!(type == 'payment')) {
_context.next = 16;
_context.next = 15;
break;
}

Expand All @@ -372,42 +372,41 @@ var WechatPayment = function () {
return _context.abrupt('return', null);

case 12:
req.wxmessage = notification;
return _context.abrupt('return', notification);

case 14:
_context.next = 24;
case 13:
_context.next = 23;
break;

case 16:
_context.next = 18;
case 15:
_context.next = 17;
return _utils2.default.parseXML(xml);

case 18:
case 17:
_notification = _context.sent;
decryptedData = _utils2.default.decryptByAes256Cbc(_notification.req_info, apiKey);
_context.next = 22;
_context.next = 21;
return _utils2.default.parseXML(decryptedData);

case 22:
case 21:
finalData = _context.sent;
return _context.abrupt('return', finalData);

case 24:
_context.next = 29;
case 23:
_context.next = 28;
break;

case 26:
_context.prev = 26;
case 25:
_context.prev = 25;
_context.t0 = _context['catch'](0);
return _context.abrupt('return', _context.t0);

case 29:
case 28:
case 'end':
return _context.stop();
}
}
}, _callee, this, [[0, 26]]);
}, _callee, this, [[0, 25]]);
}));

function checkNotification(_x2, _x3) {
Expand Down Expand Up @@ -440,7 +439,7 @@ var WechatPayment = function () {
case 0:
xml = data.toString('utf8');
_context2.next = 3;
return WechatPayment.checkNotification(notification, apiKey, type);
return WechatPayment.checkNotification(xml, apiKey, type);

case 3:
notification = _context2.sent;
Expand Down
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
"description": "微信支付 for nodejs,创建统一支付订单,查询订单,关闭订单,申请退款,查询退款详情,企业付款,即转账到个人微信钱包,查询企业付款详情 Payment API of Weixin (WeChat) for APP and also JSAPI",
"main": "lib/index.js",
"scripts": {
"watch": "mocha --compilers js:babel-core/register --watch tests/",
"test": "mocha --reporter spec --timeout 2000 --recursive tests/",
"test-cov": "istanbul cover ./node_modules/mocha/bin/_mocha -- -t 2000 --recursive -R spec tests/",
"test-html": "mocha --reporter mochawesome tests/"
"watch": "gulp watch",
"test": "gulp test",
"build": "gulp build"
},
"dependencies": {
"babel-runtime": "^6.23.0",
Expand Down Expand Up @@ -70,4 +69,4 @@
},
"bugs": "https://github.com/OtkurBiz/wechat-payment-node/issues",
"homepage": "https://github.com/OtkurBiz/wechat-payment-node"
}
}
13 changes: 6 additions & 7 deletions src/WechatPayment.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default class WechatPayment {
prepayid: prepayId,
package: 'Sign=WXPay',
noncestr: utils.createNonceStr(),
timestamp: parseInt(new Date().getTime() / 1000)
timestamp: parseInt(new Date().getTime() / 1000).toString(),
}
configData.sign = utils.sign(configData, this.options.apiKey);
return configData;
Expand Down Expand Up @@ -206,10 +206,10 @@ export default class WechatPayment {
passphrase: this.options.mch_id
}
}, function (err, response, body) {
if ( err ) return reject(err);
if (err) return reject(err);
utils.parseXML.parseXML(body).then(function (result) {
if ( !result || result.result_code === 'FAIL' ) reject(result);
else resolve(result);
if (!result || result.result_code === 'FAIL') reject(result);
else resolve(result);
}).catch(reject);
});
});
Expand Down Expand Up @@ -284,14 +284,13 @@ export default class WechatPayment {
static async checkNotification(xml, apiKey, type = 'payment') {
try {
if (type == 'payment') {
let notification = await utils.parseXML(xml);
let notification = await utils.parseXML(xml);
let dataForSign = Object.assign({}, notification);
delete dataForSign.sign;
let signValue = utils.sign(dataForSign, apiKey);
if (signValue != notification.sign) {
return null;
} else {
req.wxmessage = notification;
return notification;
}
} else {
Expand All @@ -315,7 +314,7 @@ export default class WechatPayment {
utils.pipe(req, async function (err, data) {
var xml = data.toString('utf8');
let notification = await WechatPayment.checkNotification(xml, apiKey, type);
fn.apply(_this, [notification, req, res, next]);
fn.apply(_this, [notification, req, res, next]);
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/WechatPaymentForWeb.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default class WechatPaymentForWeb {
let configData = {
jsapi_ticket: jsApiTicket,
nonceStr: nonceStr,
timestamp: parseInt(new Date().getTime() / 1000) + '',
timestamp: parseInt(new Date().getTime() / 1000).toString(),
url: url
}
let string = utils.buildQueryStringWithoutEncode(configData);
Expand Down
6 changes: 3 additions & 3 deletions tests/WechatPaymentForWeb.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import fs from 'fs';

var wechatConfig = require('../config/wechatForWeb.json');

describe('Wechat payment 测试', function () {
describe('Wechat Payment 构造函数', function () {
describe('Wechat payment for web 测试', function () {
describe('Wechat Payment for web 构造函数', function () {
let options = {
//appid: wechatConfig.appId,
mch_id: wechatConfig.mchId,
Expand All @@ -18,7 +18,7 @@ describe('Wechat payment 测试', function () {
expect(fcn).to.throw("Seems that app id or merchant id is not set, please provide wechat app id and merchant id.");
});

it('成功构造wechat payment instance', function () {
it('成功构造wechat payment for web instance', function () {
options['appid'] = wechatConfig.appId;
let wechatPaymentInstance = new WechatPaymentForWeb(options);
expect(wechatPaymentInstance.options).to.not.be.empty;
Expand Down

0 comments on commit 3ca455a

Please sign in to comment.