参数配置
源码前端
async function hook($req = request, $resp = response, $modules = modules) { let api = $modules.weixinPayApi; let data = await api.read($req); //读取信息 await api.success($resp); //返回成功信息 let order_id = data["out_trade_no"];//订单号 let result_code = data["result_code"];//支付结果:SUCCESS为成功 / let transaction_id = data["transaction_id"];//交易id if (result_code == "SUCCESS") { //支付成功 } else { //支付失败 } }
配置
源码vue
async function run($input, $output, $modules = modules) { let result = await $modules.weixinPayApi.getPayParams({ body: "title",//名称 out_trade_no: $input.order_id,//订单号 total_fee: $input.total, // 1分钱 openid: $input.openid,//openid notify_url: "https://platform.bnocode.com/api/open/5f43669bd40c150945a51b34/weixinpay"//回调地址 }); //返回结果 $output.result = JSON.stringify(result); }
其中的回调地址为第一点建立的webhook所生成的路径node
源码git
//获取当前微信的openID window.vue.$store.dispatch("weixin/getOpenid").then(openid => { //调用“后台调用支付API”的功能 $view.cmd({ type: "program", value: { flow: "5f607c7f8bc6f05918a9d3f8", data, skip: true } }, { callback: (value) => {//获取API返回的交易信息 let config = JSON.parse(value.data); //发起支付 window.vue.$store.dispatch("weixin/get").then(wx => { window.vue.$store.dispatch("weixin/pay", config).then(() => { //成功处理 }).catch(() => { //失败处理 }) }) } }); })