Commit 26742971 authored by 任国军's avatar 任国军

wechat pay return more

parent 59872c69
Pipeline #24465 passed with stage
in 11 seconds
......@@ -454,6 +454,7 @@ class InstitutionSubService extends Service {
}
results.push({
title: '体验课',
value: 1,
class: classList,
});
......@@ -465,6 +466,7 @@ class InstitutionSubService extends Service {
}
results.push({
title: '低价课',
value: 2,
class: classList,
});
......@@ -476,6 +478,7 @@ class InstitutionSubService extends Service {
}
results.push({
title: '精品课',
value: 3,
class: classList,
});
......
......@@ -375,9 +375,10 @@ class UserService extends Service {
ctx.failed('课程不存在');
}
const orderNo = '12' + moment().format('YYYYMMDDHHMMSS') + await this.getRandomNumber(6);
if (ctx.isEmpty(order)) {
const data = {
order_no: '11' + moment().format('YYYYMMDDHHMMSS') + await this.getRandomNumber(6),
order_no: orderNo,
user_uuid: userUuid,
class_id: id,
pay: classInfo.pay_price,
......@@ -387,9 +388,9 @@ class UserService extends Service {
order = await ctx.classModel.V5.CourseUserOrder.findOne({ where: { user_uuid: userUuid, class_id: id, is_deleted: 0 }, order: [[ 'id', 'asc' ]] });
}
await ctx.classModel.V5.CourseUserOrder.update({ pay: classInfo.pay_price, type: 1, redeem: '', status: 0 }, { where: { id: order.id } });
await ctx.classModel.V5.CourseUserOrder.update({ pay: classInfo.pay_price, order_no: orderNo, type: 1, redeem: '', status: 0 }, { where: { id: order.id } });
let response = await this.service.course.v5.wechat.pay({ pay: order.pay, order_no: order.order_no, body: `趣选课-${order.order_no}` });
let response = await this.service.course.v5.wechat.pay({ pay: order.pay, order_no: orderNo, body: `趣选课-订单${orderNo}` });
response = await ctx.helper.xmlTojson(response);
if (ctx.isEmpty(response)) {
......@@ -401,13 +402,29 @@ class UserService extends Service {
if (response.result_code[0] === 'FAIL') {
ctx.failed(response.err_code_des[0]);
}
const appId = await this.service.course.v5.wechat.getAppId();
const timeStamp = moment().unix();
const arr = [ `appId=${appId}`, `timeStamp=${timeStamp}`, `nonceStr=${response.nonce_str[0]}`, `package=prepay_id=${response.prepay_id[0]}` ];
const signType = await this.service.course.v5.wechat.sign(arr);
const ret = {
trade_type: response.trade_type[0],
prepay_id: response.prepay_id[0],
appId,
timeStamp,
nonceStr: response.nonce_str[0],
package: `prepay_id=${response.prepay_id[0]}`,
signType,
};
return ret;
}
// 我的订单列表
async getUserOrderList() {
const { ctx } = this;
}
}
module.exports = UserService;
......@@ -366,6 +366,24 @@ class WechatService extends Service {
ret = ret.replace(/^\ufeff/i, '').replace(/^\ufffe/i, '');
return ret;
}
// 签名
async sign(arr) {
const { ctx } = this;
if (ctx.isEmpty(arr)) {
return '';
}
arr.sort();
let sign = ctx.helper.md5(arr.join('&') + '&key=xuepenQuXuanKeweixinzhifu2020063');
sign = sign.toUpperCase();
return sign;
}
async getAppId() {
return 'wx07a5f0ed5bdf4751';
}
}
module.exports = WechatService;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment