Commit 3e285ab1 authored by 李尚科's avatar 李尚科

wexin pay

parent 90359d5a
Pipeline #13535 passed with stage
in 9 minutes 41 seconds
...@@ -102,7 +102,7 @@ class CommonService extends Service { ...@@ -102,7 +102,7 @@ class CommonService extends Service {
}; };
await this.addCreditPay(pay_data); await this.addCreditPay(pay_data);
return { url: ret.mweb_url }; return { url: ret.mweb_url, order_id: order_id, trade_no: data.trade_no };
} else if (type === 'alipay') { } else if (type === 'alipay') {
//TODO //TODO
...@@ -185,9 +185,49 @@ class CommonService extends Service { ...@@ -185,9 +185,49 @@ class CommonService extends Service {
async WexinCheckPay(params) { async WexinCheckPay(params) {
const { ctx } = this; const { ctx } = this;
const { transaction_id, out_trade_no, nonce_str } = params; const { transaction_id, trade_no } = params;
const pay_info = await ctx.prometheusModel.CreditPay.one({ where: { trade_no: out_trade_no } });
if (!pay_info || pay_info.order_id) {
ctx.failed('pay info error');
}
const order_info = await ctx.service.credit.common.getOrderInfo(pay_info.order_id);
const nonce_str = ctx.helper.createNoncestr();
const url = 'https://api.mch.weixin.qq.com/pay/orderquery';
let data_obj = {
appid: this.config.MCH_APPID,
mch_id: this.config.MCH_ID,
transaction_id,
out_trade_no: trade_no,
nonce_str,
}
const sign = this.getWexinSign(data_obj);
data_obj.sign = sign;
const xml_data = ctx.helper.jsonToxml(data_obj);
const result_wexin = await ctx.curl(url, { timeout: 3000, method: 'POST', data: xml_data, headers: { 'content-type': 'text/html', }, streaming: false, dataType: 'text', });
if (result_wexin.status) {
ctx.failed('wexin orderquery error1');
}
const ret = await ctx.helper.xmlTojson(result_wexin.data);
if (ret.return_code !== 'SUCCESS' && ret.result_code !== 'SUCCESS') {
ctx.failed('wexin orderquery error2');
}
let ret_data = {};
for (let key in ret) {
ret_data[key] = ret[key][0];
}
if (ret_data.trade_state === 'SUCCESS') {
return false;
}
const price = order_info.price * 100 - order_info.preferential_price * 100;
if (price != ret_data.cash_fee) {
return false;
}
await ctx.prometheusModel.CreditPay.edit({ where: { id: pay_info.id }, params: { pay_result: JSON.stringify(ret_data), status: 1 } });
return true;
} }
/** /**
......
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