Commit 7e7353f1 by linboxuan

uncommuneSve orderConfirm

parent 5abd5ab7
...@@ -3,15 +3,17 @@ var settings = require("../../../../config/settings"); ...@@ -3,15 +3,17 @@ var settings = require("../../../../config/settings");
const AppServiceBase = require("../../app.base"); const AppServiceBase = require("../../app.base");
const axios = require('axios') const axios = require('axios')
const md5 = require('md5') const md5 = require('md5')
var AlipaySdk = require('alipay-sdk').default;
var WXPay = require('wx-pay');
var xml2js = require('xml2js');
//产品操作类 //产品操作类
class UtilsUcommuneService extends AppServiceBase { class UtilsUcommuneService extends AppServiceBase {
constructor() { constructor() {
super(); super();
this.centerOrderUrl = settings.centerOrderUrl(); this.centerOrderUrl = settings.centerOrderUrl();
this.centerChannelUrl = settings.centerChannelUrl(); this.centerChannelUrl = settings.centerChannelUrl();
this.redisClient = system.getObject("util.redisClient");
this.utilsAuthSve = system.getObject("service.utilsSve.utilsAuthSve"); this.utilsAuthSve = system.getObject("service.utilsSve.utilsAuthSve");
// this.alipay = settings.alipay();
this.WXpay = settings.wxpay();
} }
//--------------------------------优客工厂相关接口-start----------------------------------------------------- //--------------------------------优客工厂相关接口-start-----------------------------------------------------
...@@ -79,113 +81,215 @@ class UtilsUcommuneService extends AppServiceBase { ...@@ -79,113 +81,215 @@ class UtilsUcommuneService extends AppServiceBase {
pobj.actionType = "getOrderDetails" // 获取订单详细信息 用来拼接字符串 totalsum为总金额,返回给前端 pobj.actionType = "getOrderDetails" // 获取订单详细信息 用来拼接字符串 totalsum为总金额,返回给前端
var reqUrl = this.centerOrderUrl + "action/order/springBoard"; var reqUrl = this.centerOrderUrl + "action/order/springBoard";
var orderResult = await this.restPostUrl(pobj, reqUrl); var orderResult = await this.restPostUrl(pobj, reqUrl);
console.log(orderResult) if(orderResult.status != 0) {
if(actionBody.payWay == 1) { // 支付宝 return system.getResult(null, "Failed to get orderResult 100470");
var reqUrl = "https://yf-api.gongsibao.com/pay/v1/createSign"; } else {
var obj = { if(actionBody.payWay == 1) { // 支付宝
"app": "ukgc", //应用名称 固定 let sign = await PayUtil.getSign(null,"1")
"key": "a1519e2eab53dfb909e4c32a86b2ea2b", //应用 key 固定 let params = {
"payParam": [ //微信或者支付宝的拼接参数 "partner" : "2019022163300183" ,
{ "seller_id" : "353494220@qq.com" ,
"name": "app_id", "out_trade_no" : orderResult.data.channelOrderNo ,
"value": "2019022163300183" "subject" : orderResult.data.channelItemName ,
}, "body" : orderResult.data.channelItemName ,
{ "total_fee" : orderResult.data.payTotalSum ,
"name": "charset", "service" : "alipay.trade.app.pay" ,
"value": "UTF-8" "payment_type" : "1" ,
}, "_input_charset" : "utf-8" ,
{ "it_b_pay" : "10m" ,
"name": "method", "notify_url" : this.centerChannelUrl + "orderNotify/aliPayNotify" ,
"value": "alipay.trade.app.pay" "enable_paymethod" : "balance,moneyFund,coupon,pcredit,pcreditpayInstallment,creditCard,creditCardExpress,creditCardCartoon,credit_group,debitCardExpress,mcard,pcard,promotion" ,
}, "sign" : sign ,
{ "sign_type" : "RSA2",
"name": "sign_type", }
"value": "RSA2" let str = "";
}, for(var k in params) {
{ console.log(k)
"name": "timestamp", str += k + "=\"" + params[k] + "\"&";
"value": "2014-07-24 03:07:50" }
}, str = str.substr(0,str.length-1)
{ console.log(str)
"name": "version", return system.getResultSuccess(str);
"value": "1.0" // let alipayAgentInformation = await this.redisClient.get("alipayAgentInformation")
} // if(!alipayAgentInformation) {
], // console.log("11111")
"paymentType": "1", //支付方式 1 支付宝 3 微信 // let res = await axios.post('https://yf-api.gongsibao.com/pay/v1/getPayConfig',{
// "app": "ukgc", //应用名称 固定
// "key": "a1519e2eab53dfb909e4c32a86b2ea2b", //应用 key 固定
// "paymentType": "1", //支付方式 1 支付宝 3 微信
// "sign":"D6C4DE28278BC3AAF1C5B22E834F3850"
// })
// if(res.status == 200) {
// alipayAgentInformation = res.data
// await this.redisClient.set('alipayAgentInformation',JSON.stringify(res.data))
// console.log("缓存alipayAgentInformation")
// } else {
// return system.getResult(null, "actionBody.token can not be empty,100410");
// }
// }
// let agentInformation = JSON.parse(alipayAgentInformation)
// let alipay = new AlipaySdk({
// appId: agentInformation.appid,
// privateKey: agentInformation.publicKey,
// // alipayPublicKey: agentInformation.publicKey,
// });
// const params = {
// bizContent: {
// out_trade_no: '12312312321212', // 商户网站唯一订单号
// subject: encodeURIComponent('苹果电脑'),//商品的标题/交易标题/订单标题/订单关键字等
// total_amount: 0.2,//实际付款金额
// body: encodeURIComponent('Mac Pro1'),//对一笔交易的具体描述信息。如果是多种商品,请将商品描述字符串累加传给body
// product_code: 'QUICK_MSECURITY_PAY',
// notifyUrl:this.centerChannelUrl + "orderNotify/aliPayNotify"
// }
// }
// let alipayResponse = await alipay.exec('alipay.trade.app.pay', params);
// console.log(alipayResponse)
// return system.getResultSuccess(alipayResponse)
// var newobj = JSON.stringify(obj).replace(/\s*/g,"");
// newobj += "ab53dfb909e4c32a"
// newobj = md5(newobj).toUpperCase()
// obj.sign = newobj
// let res = await axios.post(reqUrl, obj)
// console.log(res);
// const params = {
// bizContent: {
// out_trade_no: '12312312321212', // 商户网站唯一订单号
// subject: encodeURIComponent('苹果电脑'),//商品的标题/交易标题/订单标题/订单关键字等
// total_amount: 0.2,//实际付款金额
// body: encodeURIComponent('Mac Pro1'),//对一笔交易的具体描述信息。如果是多种商品,请将商品描述字符串累加传给body
// product_code: 'QUICK_MSECURITY_PAY',
// notifyUrl:this.centerChannelUrl + "orderNotify/aliPayNotify"
// }
// }
// let alipayResponse = await this.alipay.exec('alipay.trade.app.pay', params);
// console.log(alipayResponse);
} }
var newobj = JSON.stringify(obj).replace(/\s*/g,""); if(actionBody.payWay == 3) { // 微信
newobj += "ab53dfb909e4c32a" let sign = await PayUtil.getSign(null,"3")
newobj = md5(newobj).toUpperCase() let params = {
obj.sign = newobj "partner" : "2019022163300183" ,
let res = await axios.post(reqUrl, obj) "seller_id" : "353494220@qq.com" ,
console.log(res); "out_trade_no" : orderResult.data.channelOrderNo ,
// const params = { "subject" : orderResult.data.channelItemName ,
// bizContent: { "body" : orderResult.data.channelItemName ,
// out_trade_no: '12312312321212', // 商户网站唯一订单号 "total_fee" : orderResult.data.payTotalSum ,
// subject: encodeURIComponent('苹果电脑'),//商品的标题/交易标题/订单标题/订单关键字等 "service" : "alipay.trade.app.pay" ,
// total_amount: 0.2,//实际付款金额 "payment_type" : "1" ,
// body: encodeURIComponent('Mac Pro1'),//对一笔交易的具体描述信息。如果是多种商品,请将商品描述字符串累加传给body "_input_charset" : "utf-8" ,
// product_code: 'QUICK_MSECURITY_PAY', "it_b_pay" : "10m" ,
// notifyUrl:this.centerChannelUrl + "orderNotify/aliPayNotify" "notify_url" : this.centerChannelUrl + "orderNotify/aliPayNotify" ,
// } "enable_paymethod" : "balance,moneyFund,coupon,pcredit,pcreditpayInstallment,creditCard,creditCardExpress,creditCardCartoon,credit_group,debitCardExpress,mcard,pcard,promotion" ,
// } "sign" : sign ,
// let alipayResponse = await this.alipay.exec('alipay.trade.app.pay', params); "sign_type" : "RSA2",
// console.log(alipayResponse);
}
if(actionBody.payWay == 3) { // 微信
var reqUrl = "https://yf-api.gongsibao.com/pay/v1/createSign";
var obj = {
"app": "ukgc", //应用名称 固定
"key": "a1519e2eab53dfb909e4c32a86b2ea2b", //应用 key 固定
"payParam": [ //微信或者支付宝的拼接参数
{
"name": "app_id",
"value": "2019022163300183"
},
{
"name": "charset",
"value": "UTF-8"
},
{
"name": "method",
"value": "alipay.trade.app.pay"
},
{
"name": "sign_type",
"value": "RSA2"
},
{
"name": "timestamp",
"value": "2014-07-24 03:07:50"
},
{
"name": "version",
"value": "1.0"
} }
], let str = "";
"paymentType": "3", //支付方式 1 支付宝 3 微信 for(var k in params) {
console.log(k)
str += k + "=\"" + params[k] + "\"&";
} }
var newobj = String(obj).replace(/\s*/g,""); str = str.substr(0,str.length-1)
newobj += "secret(ab53dfb909e4c32a)" console.log(str)
newobj = md5(newobj).toUpperCase() return system.getResultSuccess(str);
obj.sign = newobj
let res = await axios.post(reqUrl,obj) // let wxAgentInformation = await this.redisClient.get("wxAgentInformation")
console.log(res); // if(!wxAgentInformation) {
console.log(this.WXpay) // console.log("11111")
var wxpay = this.WXpay; // let res = await axios.post('https://yf-api.gongsibao.com/pay/v1/getPayConfig',{
var out_trade_no='20160203'+Math.random().toString().substr(2, 10); // "app": "ukgc", //应用名称 固定
wxpay.createUnifiedOrder({ // "key": "a1519e2eab53dfb909e4c32a86b2ea2b", //应用 key 固定
body: '充值兑换宝币', // "paymentType": "3", //支付方式 1 支付宝 3 微信
out_trade_no: out_trade_no, // "sign":"23F763A515AEF5DFC0A2BC04CC21463F"
total_fee: 1, // })
spbill_create_ip: '192.168.2.210', // if(res.status == 200) {
notify_url: 'http://www.gongsibao.com', // wxAgentInformation = res.data
trade_type: 'NATIVE', // await this.redisClient.set('wxAgentInformation',JSON.stringify(res.data))
product_id: '1234567890' // console.log("缓存wxAgentInformation")
},function(err, res) { // } else {
console.log(res); // return system.getResult(null, "actionBody.token can not be empty,100410");
return system.getResult(res) // }
}) // }
// let agentInformation = JSON.parse(wxAgentInformation)
// var unifiedorderUrl = "https://api.mch.weixin.qq.com/pay/unifiedorder";
// const opts = {
// out_trade_no: '12312312321212', // 商户网站唯一订单号
// total_fee: 0.2,//实际付款金额
// body: encodeURIComponent('Mac Pro1'),//对一笔交易的具体描述信息。如果是多种商品,请将商品描述字符串累加传给body
// spbill_create_ip: this.centerChannelUrl,
// notify_url:this.centerChannelUrl + "orderNotify/aliPayNotify",
// trade_type: 'NATIVE',
// attach: ""
// }
// opts.nonce_str = opts.nonce_str || WxPayUtil.generateNonceString();
// opts.appid = agentInformation.appid;
// opts.mch_id = agentInformation.mchid;
// opts.device_info = "WEB";
// opts.sign = WxPayUtil.sign(opts);
// var postXml = WxPayUtil.buildXML({ xml: opts });
// axios.post(unifiedorderUrl, postXml).then(function(result) {
// // console.log("微信付款单请求result.data",result.data);
// WxPayUtil.parseXML(result.data,function(json){
// func(json)
// });
// }).catch(function(error){
// console.log("微信生成付款单错误",error);
// })
// let wepay = new WXPay({
// appId: agentInformation.appid,
// mch_id: agentInformation.mchid,
// });
// let res = await wepay.createUnifiedOrder({
// body: '扫码支付测试',
// out_trade_no: '20140703'+Math.random().toString().substr(2, 10),
// total_fee: 1,
// spbill_create_ip: '192.168.2.210',
// notify_url: 'http://wxpay_notify_url',
// trade_type: 'NATIVE',
// product_id: '1234567890'
// },function(err,res) {
// console.log(err);
// console.log(res);
// })
// console.log(res)
// let res = await axios.post(reqUrl,obj)
// console.log(res);
// console.log(this.WXpay)
// var wxpay = this.WXpay;
// var out_trade_no='20160203'+Math.random().toString().substr(2, 10);
// wxpay.createUnifiedOrder({
// body: '充值兑换宝币',
// out_trade_no: out_trade_no,
// total_fee: 1,
// spbill_create_ip: '192.168.2.210',
// notify_url: 'http://www.gongsibao.com',
// trade_type: 'NATIVE',
// product_id: '1234567890'
// },function(err, res) {
// console.log(res);
// return system.getResult(res)
// })
}
} }
} }
...@@ -209,5 +313,51 @@ class UtilsUcommuneService extends AppServiceBase { ...@@ -209,5 +313,51 @@ class UtilsUcommuneService extends AppServiceBase {
//--------------------------------优客工厂相关接口--end---------------------------------------------------- //--------------------------------优客工厂相关接口--end----------------------------------------------------
} }
PayUtil = {
getSign: async function(appid,paymentType) {
let requrl = "https://yf-api.gongsibao.com/pay/v1/createSign"
let params = {
"app": "ukgc",
"key": "a1519e2eab53dfb909e4c32a86b2ea2b",
"payParam": [
{
"name": "app_id",
"value": appid || "2019022163300183"
},
{
"name": "charset",
"value": "UTF-8"
},
{
"name": "method",
"value": "alipay.trade.app.pay"
},
{
"name": "sign_type",
"value": "RSA2"
},
{
"name": "timestamp",
"value": Date.now().toString()
},
{
"name": "version",
"value": "1.0"
}
],
"paymentType": paymentType,
}
var signstr = JSON.stringify(params);
signstr += "ab53dfb909e4c32a"
signstr = md5(signstr).toUpperCase()
params.sign = signstr
let res = await axios.post(requrl, params)
if(res.data.code = 200) {
return res.data.value
}
return system.getResult(null, "Failed to get sign, 100460");
},
}
module.exports = UtilsUcommuneService; module.exports = UtilsUcommuneService;
...@@ -114,7 +114,7 @@ module.exports = function (app) { ...@@ -114,7 +114,7 @@ module.exports = function (app) {
"addOrder", "getH5PayUrl", "getOrderQrCode", "queryOrderStatus", "getOrderInfo", "getOrderDeliveryInfo", "getOrderDetails", "addOrder", "getH5PayUrl", "getOrderQrCode", "queryOrderStatus", "getOrderInfo", "getOrderDeliveryInfo", "getOrderDetails",
"getOrderDeliveryFlowInfo", "getOrderDeliveryFlowList", "getOrderLogInfo", "updateContacts", "updateTmOrder", "delOrder", "getOrderDeliveryFlowInfo", "getOrderDeliveryFlowList", "getOrderLogInfo", "updateContacts", "updateTmOrder", "delOrder",
"submitProgramme", "getProgrammeListByUser", "getProgrammeInfoByNeedNo", "abolishProgramme", "getAliPayInfo", "submitProgramme", "getProgrammeListByUser", "getProgrammeInfoByNeedNo", "abolishProgramme", "getAliPayInfo",
"getPaidLogoListByUser","getCollectibleLogoListByUser","collectLogo","getLogoMaterial","cancelCollectLogo","icpNotify","createName","getNameDetail" "getPaidLogoListByUser","getCollectibleLogoListByUser","collectLogo","getLogoMaterial","cancelCollectLogo","icpNotify","createName","getNameDetail","orderConfirm"
]; ];
if (lst.indexOf(req.body.actionType) >= 0) { if (lst.indexOf(req.body.actionType) >= 0) {
var userpin = req.headers["userpin"] || ""; var userpin = req.headers["userpin"] || "";
......
...@@ -7925,6 +7925,14 @@ ...@@ -7925,6 +7925,14 @@
"resolved": "https://registry.npmjs.org/validator/-/validator-9.4.1.tgz", "resolved": "https://registry.npmjs.org/validator/-/validator-9.4.1.tgz",
"integrity": "sha512-YV5KjzvRmSyJ1ee/Dm5UED0G+1L4GZnLN3w6/T+zZm8scVua4sOhYKWTUrKa0H/tMiJyO9QLHMPN+9mB/aMunA==" "integrity": "sha512-YV5KjzvRmSyJ1ee/Dm5UED0G+1L4GZnLN3w6/T+zZm8scVua4sOhYKWTUrKa0H/tMiJyO9QLHMPN+9mB/aMunA=="
}, },
"var": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/var/-/var-0.4.0.tgz",
"integrity": "sha512-olxlLAssnt9UPL5UAErYTaCJhpwaDfkuSxOEB5eUclEJbl4xi7EhOIaOh6Y8KTQHIKUnyd2DygRLSnTaXtXuGg==",
"requires": {
"lodash": "^4.17.4"
}
},
"vary": { "vary": {
"version": "1.1.2", "version": "1.1.2",
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
...@@ -8134,18 +8142,18 @@ ...@@ -8134,18 +8142,18 @@
} }
}, },
"xml2js": { "xml2js": {
"version": "0.4.19", "version": "0.4.23",
"resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.19.tgz", "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.23.tgz",
"integrity": "sha512-esZnJZJOiJR9wWKMyuvSE1y6Dq5LCuJanqhxslH2bxM6duahNZ+HMpCLhBQGZkbX6xRf8x1Y2eJlgt2q3qo49Q==", "integrity": "sha512-ySPiMjM0+pLDftHgXY4By0uswI3SPKLDw/i3UXbnO8M/p28zqexCUoPmQFrYD+/1BzhGJSs2i1ERWKJAtiLrug==",
"requires": { "requires": {
"sax": ">=0.6.0", "sax": ">=0.6.0",
"xmlbuilder": "~9.0.1" "xmlbuilder": "~11.0.0"
} }
}, },
"xmlbuilder": { "xmlbuilder": {
"version": "9.0.7", "version": "11.0.1",
"resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-9.0.7.tgz", "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz",
"integrity": "sha1-Ey7mPS7FVlxVfiD0wi35rKaGsQ0=" "integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA=="
}, },
"xmlhttprequest-ssl": { "xmlhttprequest-ssl": {
"version": "1.5.5", "version": "1.5.5",
......
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