Authored by 郭成尧

wechat-pay-params-add

... ... @@ -3,7 +3,7 @@
* @Author: Targaryen
* @Date: 2017-01-04 15:17:51
* @Last Modified by: Targaryen
* @Last Modified time: 2017-02-20 15:20:23
* @Last Modified time: 2017-02-20 17:47:03
*/
'use strict';
... ... @@ -114,6 +114,11 @@ const pay = (req, res, next) => {
let payment = req.query.payment;
let paymentCode = common.getPaymentCode(payment);
let openId = req.cookies['weixinOpenId' + orderCode];
let ip = req.ip;
if (ip.substr(0, 7) === '::ffff:') {
ip = ip.substr(7);
}
if (!orderCode || !uid) {
return res.redirect('/');
... ... @@ -144,7 +149,8 @@ const pay = (req, res, next) => {
Payment.pay(user, orderDetail.data, payment, {
protocol: req.protocol,
openId: openId
openId: openId,
ip: ip
}).then(result => {
if (result && paymentCode === payModel.payments.wechat) {
return res.json(result);
... ...
... ... @@ -2,7 +2,7 @@
* @Author: Targaryen
* @Date: 2017-01-03 17:42:41
* @Last Modified by: Targaryen
* @Last Modified time: 2017-02-20 10:15:03
* @Last Modified time: 2017-02-20 17:46:16
*/
'use strict';
... ... @@ -15,6 +15,7 @@ const Promise = require('bluebird');
const co = Promise.coroutine;
const sign = require('./sign');
const md5 = require('md5');
const moment = require('moment');
const common = require('./common');
/**
... ... @@ -108,9 +109,13 @@ const tools = {
out_trade_no: 'YOHOBuy_' + params.orderCode,
total_fee: params.totalFee * 100,
trade_type: 'JSAPI',
time_start: moment().format('YYYYMMDDHHmmss'),
time_expire: moment().add(2, 'hours').format('YYYYMMDDHHmmss'),
spbill_create_ip: params.ip,
openid: params.openId,
sign_type: 'MD5'
};
let signStr = md5(sign.raw(unifiedParams) + '&key=' + WxPayConfig.key).toUpperCase();
_.assign(unifiedParams, { sign: signStr });
... ... @@ -158,13 +163,14 @@ const Wechat = {
/**
* 异步拉起微信支付相关处理
*/
pay(user, order, openId) {
pay(user, order, openId, ip) {
return co(function* () {
let unifiedOrderResult = yield tools.unifiedOrder({
orderCode: order.order_code,
totalFee: parseFloat(order.payment_amount),
openId: openId
openId: openId,
ip: ip
});
if (unifiedOrderResult) {
... ...
... ... @@ -20,7 +20,7 @@ const Payment = {
/**
* 统一支付入口
* reqParams: 需要从 controller 传递的参数,支付宝需要 req.protocol,微信需要 openId
* reqParams: 需要从 controller 传递的参数,支付宝需要 req.protocol,微信需要 openId、ip
*/
pay(user, order, payType, reqParams) {
return co(function*() {
... ... @@ -54,7 +54,7 @@ const Payment = {
}
if (method === PayModel.payments.wechat) {
result = yield Wechat.pay(user, order, reqParams.openId);
result = yield Wechat.pay(user, order, reqParams.openId, reqParams.ip);
} else {
payInfo = yield PayModel.getPaymentInfo(method);
... ...