1、配置回调地址
2、小程序和微信支付进行绑定
3、小程序支付需要获取openId
4、uniapp中支付的关键代码
uni.requestPayment({
"provider": "wxpay",
"orderInfo": {
"appid": "wx499********7c70e", // 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致
"noncestr": "c5sEwbaNPiXAF3iv", // 随机字符串
"package": "Sign=WXPay", // 固定值
"partnerid": "148*****52", // 微信支付商户号
"prepayid": "wx202254********************fbe90000", // 统一下单订单号
"timestamp": 1597935292, // 时间戳(单位:秒)
"sign": "A842B45937F6EFF60DEC7A2EAA52D5A0" // 签名,这里用的 MD5/RSA 签名
},
success(res) {},
fail(e) {}
})
5、证书(退款需要)
6、获取uniapp前端获取openId
wx.login({
success: res => {
console.log(res.code,'code=====');
const appid = 'wx5c*********c7ea0'; // 微信小程序appid
const secret = 'a5fd***************ea80c6866dc0'; // 微信小程序secret
//调用request请求api转换登录凭证
wx.request({
url: 'https://api.weixin.qq.com/sns/jscode2session?appid='+appid+'&secret='+secret+'&grant_type=authorization_code&js_code=' + res.code,
header: {
'content-type': 'application/json'
},
success: function (result) {
if(result.statusCode === 200) {
console.log(result.data.openid,'openid=======');
uni.setStorageSync('openid', result.data.openid);
uni.setStorageSync('session_key', result.data.session_key);
}
}
})
}
})