| | |
| | | // pages/rechargeMoney/rechargMoney.js |
| | | const { |
| | | get, |
| | | post |
| | | } = require('../../api/request.js'); |
| | | const md5 = require('js-md5'); |
| | | Page({ |
| | | |
| | | /** |
| | |
| | | userCode: "15584236", |
| | | balance: "1025元", |
| | | activeIndex: -1, |
| | | isClickable: false, |
| | | allRechargeList: [{ |
| | | time: "2024-05-12:20:20", |
| | | type: "远程", |
| | |
| | | if (index !== undefined) { |
| | | this.setData({ |
| | | activeIndex: parseInt(index), |
| | | isClickable: true |
| | | }); |
| | | } |
| | | }, |
| | | onPullDownRefresh() { |
| | | console.log("onPullDownRefresh") |
| | | }, |
| | | //创建订单并调起支付 |
| | | creatOrder() { |
| | | if (!this.data.isClickable) { |
| | | return; |
| | | } |
| | | const data = { |
| | | sessionId: "2024061708384800006", |
| | | vcId: "2024060610404500006", //虚拟卡ID |
| | | rechargeAmount: 1 //(单位是分) |
| | | }; |
| | | console.log("postCloseValaue" + data); |
| | | post({ |
| | | url: "https://44978f7456.imdo.co/sell/payment/placeOrder", |
| | | data: data |
| | | }).then(response => { |
| | | // 处理成功响应 |
| | | console.log('请求成功:', response); |
| | | const timeStamp = String(Math.floor(Date.now() / 1000)); |
| | | const nonceStr = timeStamp; |
| | | const prepayId = response.content.prepay_id; |
| | | const signType = 'MD5'; |
| | | |
| | | // 生成支付签名 |
| | | const paySign = this.generatePaySign({ |
| | | appId: getApp().globalData.APPID, |
| | | timeStamp: timeStamp, |
| | | nonceStr: nonceStr, |
| | | package: prepayId, |
| | | signType: signType |
| | | }); |
| | | |
| | | // 调起支付 |
| | | wx.requestPayment({ |
| | | timeStamp: timeStamp, |
| | | nonceStr: nonceStr, |
| | | package: prepayId, |
| | | signType: signType, |
| | | paySign: paySign, |
| | | success(res) { |
| | | console.log('支付成功', res); |
| | | }, |
| | | fail(err) { |
| | | console.log('支付失败', err); |
| | | } |
| | | }); |
| | | }).catch(error => { |
| | | if (error.code === "1002") {} |
| | | // 处理错误响应 |
| | | console.error('请求失败:', error); |
| | | |
| | | }); |
| | | }, |
| | | getRechargList() { |
| | | |
| | | }, |
| | | // 生成支付签名的函数 |
| | | generatePaySign(params) { |
| | | const sortedKeys = Object.keys(params).sort(); |
| | | const stringToSign = sortedKeys.map(key => `${key}=${params[key]}`).join('&') + `&key=your-mch-key`; |
| | | return md5(stringToSign).toUpperCase(); |
| | | } |
| | | }) |