wxml
<button bindtap='zfclick'>支付</button>
index.js
// 第一次签名
// const stringA = "appid=****&attach=支付测试&body=紫薯OR红薯&mch_id=***&nonce_str=0VDpjwNyCHVHWVNe¬ify_url=http://www.weixin.qq.com/wxpay/pay.php&openid=odtBs5SY7xRZ_vwDpw01anLnhg8o&out_trade_no=20190422352&spbill_create_ip=172.16.30.242&total_fee=1&trade_type=JSAPI";
// const stringSignTemp = stringA + "&key=***"; //注:key为商户平台设置的密钥key
// const sign = MD5(stringSignTemp).toUpperCase() = "106413A77D104A9A8F9E701D0AD50D1F"; //注:MD5签名方式
Page({
/**
* 页面的初始数据
*/
data: {
},
zfclick: function () {
// 请求支付
wx.requestPayment(
{
'timeStamp': '1555912632.057', //时间戳
'nonceStr': 'zAyit9jhBk0ivgOX', //随机串
'package': 'prepay_id=wx29082620893785cd4ba91ed32347390556',
'signType': 'MD5',
'paySign': '******', //签名
'success': function (res) {
console.log("支付成功");
console.log(res);
},
'fail': function (res) {
console.log(res);
},
'complete': function (res) { }
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
// 获取登陆的openid
wx.login({
success: function (res) {
console.log(res)
if (res.code) {
//发起网络请求
wx.request({
url: 'https://api.weixin.qq.com/sns/jscode2session',
data: {
appid: '***',
secret: '10161c9b673dfd0f0425082cda890eca',
js_code: res.code,
grant_type: 'authorization_code'
},
success(v) {
console.log(v)
}
})
} else {
console.log('登录失败!' + res.errMsg)
}
}
});
// 请求下单
// wx.request({
// url: 'https://api.mch.weixin.qq.com/pay/unifiedorder',
// })
}
})