Authored by 郝肖肖

财付通支付 签名

... ... @@ -14,7 +14,7 @@ const payHelpersBank = require('../bank');
const md5 = require('md5');
const logger = global.yoho.logger;
const PAY_URL = 'https://mapi.alipay.com/gateway.do';
const PAY_URL = 'https://mapi.alipay.com/gateway.do?';
const Alibank = {
... ... @@ -49,7 +49,7 @@ const Alibank = {
return {
code: 200,
data: {
href: PAY_URL + '?' + body
href: PAY_URL + body
}
};
},
... ...
... ... @@ -13,7 +13,7 @@ const sign = require('./sign');
const md5 = require('md5');
const logger = global.yoho.logger;
const PAY_URL = 'https://mapi.alipay.com/gateway.do';
const PAY_URL = 'https://mapi.alipay.com/gateway.do?';
const Alipay = {
... ... @@ -46,7 +46,7 @@ const Alipay = {
return {
code: 200,
data: {
href: PAY_URL + '?' + body
href: PAY_URL + body
}
};
},
... ...
/**
*
* @author: xiaoxiao.hao<xiaoxiao.hao>
* @date: 2017/3/24
*/
'use strict';
const helpers = global.yoho.helpers;
const moment = require('moment');
const sign = require('./sign');
const md5 = require('md5');
const logger = global.yoho.logger;
const PAY_URL = 'https://gw.tenpay.com/gateway/pay.htm?';
const Tenpay = {
pay(user, order, param, protocol) {
let payParams = JSON.parse(param.payParams);
let extraParam = JSON.stringify({
sign_id_ext: user.uid,
defaultbank: param.bankCode || ''
});
let params = {
partner: payParams.merchant_id, // 商户号
out_trade_no: order.order_code, // 商户订单号
total_fee: order.payment_amount * 100, // 总金额 以分为单位
return_url: protocol + ':' + helpers.urlFormat('/shopping/pay/callback/tenpay'), // 同步地址
notify_url: protocol + ':' + helpers.urlFormat('/shopping/pay/notify/tenpay'), // 异步通知地址
body: '有货订单号:' + order.order_code, // 商品描述
bank_type: 'DEFAULT', // 银行类型,默认为财付通
spbill_create_ip: '127.0.0.1', // 客户端IP
fee_type: '1', // 币种
subject: '有货订单号:' + order.order_code, // 商品名称,(中介交易时必填)
sign_type: 'MD5',
service_version: '1.0', // 接口版本号
input_charset: 'UTF-8', // 字符集
sign_key_index: '1', // 密钥序号
time_start: moment(order.create_time * 1000).format('YYYYMMDDHHmmss'), // 订单生成时间-yyyymmddhhmmss
time_expire: moment(order.pay_expire).format('YYYYMMDDHHmmss'), // 订单失效时间--yyyymmddhhmmss
attach: extraParam // 附加数据,原样返回
};
let signStr = md5(sign.raw(params) + '&key=' + payParams.merchant_key).toLowerCase();
let body = sign.rawUncode(params) + '&sign=' + signStr;
return {
code: 200,
data: {
href: PAY_URL + body
}
};
},
notify(data, param) {
let payParams = JSON.parse(param.payParams);
let orderCode = parseInt(data.out_trade_no, 10);
logger.info(`Alipay notify, params = ${JSON.stringify(data)}`);
if (!this.checkNotify(data, payParams)) {
return {payResult: -1};
}
return {
bankName: '',
orderCode: orderCode,
payResult: data.trade_status === 'TRADE_SUCCESS' ? 200 : 400,
totalFee: data.total_fee,
resultMsg: data.notify_type,
payOrderCode: orderCode,
tradeNo: data.trade_no,
bankBillNo: ''
};
},
checkNotify(data, payParams) {
let signValue = data.sign;
delete data.sign;
delete data.sign_type;
delete data.code;
let signStr = md5(sign.raw(data) + payParams.merchant_key);
return signValue === signStr;
}
};
module.exports = Tenpay;
... ...
... ... @@ -7,7 +7,7 @@
const ServiceAPI = global.yoho.ServiceAPI;
const helpers = global.yoho.helpers;
const sign = require('./sign');
const PAY_URL = 'https://gateway.95516.com/gateway/api/frontTransReq.do';
const PAY_URL = 'https://gateway.95516.com/gateway/api/frontTransReq.do?';
const unionpay = {
pay(user, order, info) {
... ... @@ -21,7 +21,7 @@ const unionpay = {
return {
code: 200,
data: {
href: `${PAY_URL}?${sign.raw(result.data)}`
href: `${PAY_URL}${sign.raw(result.data)}`
}
};
}
... ...
... ... @@ -11,6 +11,7 @@ const PayData = require('../models/pay');
const Alipay = require('./pay/alipay');
const Alibank = require('./pay/alibank');
const Wechat = require('./pay/wechat');
const Tenpay = require('./pay/tenpay');
const Unionpay = require('./pay/unionpay');
const Promise = require('bluebird');
const common = require('./pay/common');
... ... @@ -70,6 +71,9 @@ const Payment = {
case PayData.payments.alipay:
result = Alipay.pay(user, order, payInfo, protocol);
break;
case PayData.payments.tenpay:
result = Tenpay.pay(user, order, payInfo, protocol);
break;
case PayData.payments.alibank:
bankCode = paymentPars[1];
payInfo.bankCode = bankCode;// 设置默认银行
... ...
... ... @@ -151,44 +151,46 @@ const getPayInfo = (uid, code) => {
payDefault = payment[0][0].children[findIndex];
}
// 订单处理
if (orderInfo.attribute === 3) {
orderInfo.deliveryTimes = '自动发货 - 在您支付成功后,系统将立即为您发放二维码,您可以在您的订单中查看。';
} else {
orderInfo.deliveryTimes = orderInfo.delivery_time || '';
}
if (orderInfo.order_code) {
// 订单处理
if (orderInfo.attribute === 3) {
orderInfo.deliveryTimes = '自动发货 - 在您支付成功后,系统将立即为您发放二维码,您可以在您的订单中查看。';
} else {
orderInfo.deliveryTimes = orderInfo.delivery_time || '';
}
// 用于订单统计
orderInfo.uid = uid;
orderInfo.orderCount = 0;
if (payment[3].code === 200 && payment[3].data) {
orderInfo.orderCount = payment[3].data.count || 0;
}
orderInfo.isOldUser = orderInfo.orderCount > 1;
orderInfo.ordersGoodsNums = orderInfo.order_goods.length;
let sknList = [];
let skuList = [];
let goodsData = [];
let pinyouGoodsArr = [];
_.each(orderInfo.order_goods, function(el) {
sknList.push(el.product_skn);
skuList.push(el.product_sku);
goodsData.push({
goods_name: el.product_name,
product_sku: el.product_sku,
price: el.goods_price,
number: el.buy_number
// 用于订单统计
orderInfo.uid = uid;
orderInfo.orderCount = 0;
if (payment[3].code === 200 && payment[3].data) {
orderInfo.orderCount = payment[3].data.count || 0;
}
orderInfo.isOldUser = orderInfo.orderCount > 1;
orderInfo.ordersGoodsNums = orderInfo.order_goods.length;
let sknList = [];
let skuList = [];
let goodsData = [];
let pinyouGoodsArr = [];
_.each(orderInfo.order_goods, function(el) {
sknList.push(el.product_skn);
skuList.push(el.product_sku);
goodsData.push({
goods_name: el.product_name,
product_sku: el.product_sku,
price: el.goods_price,
number: el.buy_number
});
pinyouGoodsArr.push(`${el.product_skn},${el.buy_number}`);
});
pinyouGoodsArr.push(`${el.product_skn},${el.buy_number}`);
});
orderInfo.sknList = sknList;
orderInfo.skuList = skuList;
orderInfo.goodsData = goodsData;
orderInfo.goodsDatas = JSON.stringify(goodsData);
orderInfo.sknList = sknList;
orderInfo.skuList = skuList;
orderInfo.goodsData = goodsData;
orderInfo.goodsDatas = JSON.stringify(goodsData);
// 品友统计需要的商品数据
orderInfo.pinyouGoods = pinyouGoodsArr.join(';');
// 品友统计需要的商品数据
orderInfo.pinyouGoods = pinyouGoodsArr.join(';');
}
return {
pay: payment[0],
... ...