Authored by 郭成尧

alipay-base-ok

/**
* 支付成功页
* 支付
* @author: jing.li<jing.li@yoho.cn>
* @date: 2016/10/25
*/
... ... @@ -9,6 +9,9 @@
const mRoot = '../models';
const payModel = require(`${mRoot}/pay`);
const headerModel = require('../../../doraemon/models/header'); // 头部model
const co = require('bluebird').coroutine;
const helpers = global.yoho.helpers;
const AliServer = require('../../serverAPI/pay/alipay');
/**
* 支付中心
... ... @@ -55,24 +58,82 @@ const payCenter = (req, res, next) => {
* 支付宝跳转页
* @param req
* @param res
* @param next
*/
const goAlipay = (req, res, next) => {
const goAlipay = (req, res) => {
let orderCode = req.query.order_code;
let uid = req.user.uid;
let sessionKey = req.session.TOKEN;
let paymentType = req.query.payment_type;
if (!orderCode || !uid || !sessionKey) {
res.redirect('/');
}
payModel.goAlipay({
orderCode: orderCode,
uid: uid,
sessionKey: sessionKey
}).then(result => {
co(function*() {
let orderDetail = yield payModel.getOtherDetail({
uid: uid,
orderCode: orderCode,
sessionKey: sessionKey
});
if (!orderDetail) {
return res.json({
code: 400,
msg: '没有找到该订单!'
});
}
}).catch(next);
if (orderDetail.is_cancel === 'Y') {
let url = helpers.urlFormat('/home/orders/detail', {order_code: orderCode});
return res.json({
code: 400,
msg: '订单已经取消'
}).redirect(url);
}
/* TODO 要不搞点儿日志? */
let prePayInfo = yield payModel.savePrePayInfo({
uid: uid,
orderCode: orderCode,
payment: paymentType
});
let totalFee = orderDetail.payment_amount * 100;
let payExpire = orderDetail.pay_expire; // TODO 需要特殊处理一下
let reqParams = {
orderCode: orderCode,
totalFee: totalFee,
goodsName: '有货订单号:' + orderCode,
orderTime: orderDetail.create_time,
payExpire: payExpire
};
let payRequestPars = AliServer.getPayRequestPars(reqParams);
if (!payRequestPars) {
return res.json({
code: 400,
msg: '支付系统繁忙,请稍后再试'
});
}
let paymentRecod = yield payModel.updateOrderPayment({
orderCode: orderCode,
payment: paymentType,
uid: uid
});
if (!paymentRecod) {
return res.json({
code: 400,
msg: '系统繁忙,请稍后再试'
});
}
return res.redirect(payRequestPars.pay_url + payRequestPars.pars);
})();
};
// 货到付款
... ...
... ... @@ -84,6 +84,38 @@ const _getOthersBuy = (param) => {
};
/**
* 选择支付,校验时间间隔,插入数据
* @returns {*|Promise.<TResult>}
* @private
*/
const savePrePayInfo = (params) => {
return api.get('', {
method: 'app.order.savePrePayInfo',
uid: params.uid,
orderCode: params.orderCode,
payment: params.payment
}, {code: 200}).then(result => {
return result && result.data;
});
};
/**
* 更新订单的支付方式
* @param params
* @returns {*|Promise.<TResult>}
*/
const updateOrderPayment = (params) => {
return api.get('', {
method: 'app.SpaceOrders.updateOrdersPaymentByCode',
order_code: params.orderCode,
payment: params.payment,
uid: params.uid
}, {code: 200}).then(result => {
return result && result.data;
});
};
/**
* 支付相关的数据处理函数
*/
const payTool = {
... ... @@ -156,21 +188,6 @@ const payCenter = (params) => {
});
};
/**
* 支付宝跳转页数据处理
* @param param
* @returns {*|Promise.<TResult>}
*/
const goAlipay = (param) => {
return _getOtherDetail({
uid: param.uid,
orderCode: param.orderCode,
sessionKey: param.sessionKey
}).then(result => {
return result;
});
};
// 货到付款
const getPayCod = (param) => {
return api.all([
... ... @@ -244,8 +261,10 @@ const getPayAli = (param) => {
};
module.exports = {
getOtherDetail: _getOtherDetail,
savePrePayInfo,
updateOrderPayment,
payCenter,
goAlipay,
getPayCod,
getPayAli
};
... ...
/**
* Created by yoho on 2016/12/26.
*/
'use strict';
const Config = global.yoho.config;
const AlipayConfig = global.yoho.config.alipayConfig;
const helpers = global.yoho.helpers;
const _ = require('lodash');
const md5 = require('md5');
const getPayRequestPars = (params) => {
let parameter = _.compact({
service: AlipayConfig.service,
partner: AlipayConfig.partner,
_input_charset: AlipayConfig.inputCharset,
notify_url: Config.domains.service, // TODO 不确定
return_url: helpers.urlFormat(AlipayConfig.returnUrl),
payment_type: AlipayConfig.paymentType,
seller_id: AlipayConfig.partner,
it_b_pay: new Date('Y-m-d H:i', params.payExpire),
out_trade_no: params.orderCode,
subject: params.goodsName,
total_fee: params.totalFee / 100,
show_url: helpers.urlFormat('/home/orderdetail', {order_code: params.orderCode})
});
let resultParam = '';
let resultSign = '';
_.forEach(parameter, (value, key) => {
resultParam += key + '=' + encodeURIComponent(value) + '&';
resultSign += key + '=' + value + '&';
});
resultParam = _.trimEnd(resultParam, '&');
resultSign = _.trimEnd(resultSign, '&');
return {
pay_url: AlipayConfig.payUrl,
pars: resultParam + '&sign=' + md5(resultSign) + '&sign_type=' + AlipayConfig.signType
};
};
module.exports = {
getPayRequestPars
};
... ...
... ... @@ -16,21 +16,21 @@ module.exports = {
siteUrl: '//m.yohobuy.com',
assetUrl: '//127.0.0.1:5001',
domains: {
// api: 'http://api-test3.yohops.com:9999/',
// service: 'http://service-test3.yohops.com:9999/',
// liveApi: 'http://testapi.live.yohops.com:9999/',
// singleApi: 'http://api-test3.yohops.com:9999/',
// imSocket: 'ws://im.yohobuy.com:10240',
// imCs: 'http://im.yohobuy.com/api',
// imServer: 'http://im.yohobuy.com/server'
api: 'http://api-test3.yohops.com:9999/',
service: 'http://service-test3.yohops.com:9999/',
liveApi: 'http://testapi.live.yohops.com:9999/',
singleApi: 'http://api-test3.yohops.com:9999/',
imSocket: 'ws://im.yohobuy.com:10240',
imCs: 'http://im.yohobuy.com/api',
imServer: 'http://im.yohobuy.com/server'
api: 'http://api.yoho.cn/',
service: 'http://service.yoho.cn/',
liveApi: 'http://api.live.yoho.cn/',
singleApi: 'http://single.yoho.cn/',
imSocket: 'ws://imsocket.yohobuy.com:10000',
imCs: 'http://imhttp.yohobuy.com/api',
imServer: 'http://imhttp.yohobuy.com/server'
// api: 'http://api.yoho.cn/',
// service: 'http://service.yoho.cn/',
// liveApi: 'http://api.live.yoho.cn/',
// singleApi: 'http://single.yoho.cn/',
// imSocket: 'ws://imsocket.yohobuy.com:10000',
// imCs: 'http://imhttp.yohobuy.com/api',
// imServer: 'http://imhttp.yohobuy.com/server'
},
subDomains: {
host: '.m.yohobuy.com',
... ... @@ -86,7 +86,21 @@ module.exports = {
appSecret: 'ce21ae4a3f93852279175a167e54509b'
}
},
zookeeperServer: '192.168.102.168:2188'
zookeeperServer: '192.168.102.168:2188',
alipayConfig: {
payUrl: 'https://mapi.alipay.com/gateway.do?',
service: 'alipay.wap.create.direct.pay.by.user',
partner: '2088701661478015',
inputCharset: 'utf-8',
notifyUrl: 'payment/alipay_notify',
returnUrl: '/shopping/pay/aliwapreturn',
signType: 'MD5',
paymentType: '1',
alipayKey: 'kcxawi9bb07mzh0aq2wcirsf9znusobw',
sellerMail: 'zfb@yoho.cn',
merchantUrl: 'http://m.yohobuy.com/home/orders/detail?order_code=',
cacert: 'cacert.pem'
}
};
if (isProduction) {
... ...