1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
| toPay() { var that = this if (that.data.hasAddress) { console.log(that.data.address) console.log(that.data) that.getListAfterPay(that)
var p = new Promise((resolve,reject)=>{ var out_trade_no = (new Date().getTime() + app.RndNum(6)).toString()
var stringA = "appid="+app.globalData.appid + "&attach=test" + "&body=JSAPItest" + "&device_info=WEB" + "&mch_id="+app.globalData.mch_id + "&nonce_str="+that.data.nonce_str + "¬ify_url=http://www.weixin.qq.com/wxpay/pay.php" + "&openid="+that.data.openid + "&out_trade_no="+out_trade_no + "&spbill_create_ip="+that.data.spbill_create_ip + "&time_expire="+app.beforeNowtimeByMin(-15) + "&time_start="+app.CurrentTime() + "&total_fee="+parseInt(that.data.total*100) + "&trade_type=JSAPI";
var stringSignTemp = stringA +"&key="+app.globalData.apikey var sign = md5.md5(stringSignTemp).toUpperCase() var openid = that.data.openid
resolve([sign,openid,out_trade_no]) }) p.then(e => { var xmlData = '<xml>'+ '<appid>'+app.globalData.appid+'</appid>'+ '<attach>test</attach>'+ '<body>JSAPItest</body>'+ '<device_info>WEB</device_info>'+ '<mch_id>'+app.globalData.mch_id+'</mch_id>' + '<nonce_str>'+that.data.nonce_str+'</nonce_str>' + '<notify_url>http://www.weixin.qq.com/wxpay/pay.php</notify_url>' + '<openid>'+that.data.openid+'</openid>'+ '<out_trade_no>'+e[2]+'</out_trade_no>'+ '<spbill_create_ip>'+that.data.spbill_create_ip+'</spbill_create_ip>'+ '<time_expire>'+app.beforeNowtimeByMin(-15)+'</time_expire>'+ '<time_start>'+app.CurrentTime()+'</time_start>'+ '<total_fee>'+parseInt(that.data.total * 100)+'</total_fee>'+ '<trade_type>JSAPI</trade_type>'+ '<sign>'+e[0]+'</sign>'+ '</xml>' wx.request({ url: 'https://api.mch.weixin.qq.com/pay/unifiedorder', method: 'POST', header: { "content-type":"text/xml", "charset": "utf-8" }, data: xmlData, success(res) { if (res) { var prepay_id = res.data.split("<prepay_id><![CDATA[")[1].split("]]></prepay_id>")[0]; var timeStamp = Math.round((Date.now()/1000)).toString() var nonceStr = app.RndNum() var stringB = "appId=" + app.globalData.appid + "&nonceStr=" + nonceStr + "&package=" + 'prepay_id=' + prepay_id + "&signType=MD5" + "&timeStamp=" + timeStamp var paySignTemp = stringB + "&key=" + app.globalData.apikey console.log(paySignTemp) var paySign = md5.md5(paySignTemp).toUpperCase() console.log(paySign) wx.requestPayment({ appId: app.globalData.appid, timeStamp: timeStamp, nonceStr: nonceStr, package: 'prepay_id=' + prepay_id, signType: 'MD5', paySign: paySign, success: function(e){ console.log(e) } }) } } })
})
}else{ wx.showModal({ title: 'Oh No', content: '请填写收货地址~', }) } },
getListAfterPay: function (that) { var p = new Promise((resolve, reject) => { let theList = [] that.data.orders.forEach((val, idx, obj) => { var { name, num, price } = val var tmpInfo = { name, num, price } theList.push(tmpInfo) }) resolve(theList) }).then(res => { that.setData({ myList: res }) }) }, })
|