流程图:
简单流程就是用户发起支付,我们自己的后台拿到后向微信支付系统请求下单接口,拿到一个prepay_id,预支付id,用在调用支付接口时使用,小程序请求下单接口文档:
https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_1.shtml
拿到预支付id后,后台可以将和预支付id一起返回的信息生成签名支付信息返回到前端,前端拿到后正式调用支付接口:
https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_4.shtml
调用后可通过回调拿到支付信息
注意事项:
1.需要调用wx.login()的success回调拿到临时登录凭证code,拿到code后需要在后台用code取请求微信的auth.code2Session端口拿到openid用户的唯一标识,具体说明见:
https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html
2.发现微信之前的getuserinfo获取用户信息端口已经改成了wx.getUserProfile
<view class="container">
<button open-type="getUserInfo" bindtap="getUserProfile"> 登录</button>
</view>
······················································
getUserProfile(e) {
wx.login({
success(r){
console.log(r)
}
})
// 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
wx.getUserProfile({
desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success: (res) => {
console.log(res)
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
})
},
})