uniapp微信小程序实现微信支付的功能
微信小程序需要开通微信支付的功能,需要公司在微信开发平台上面申请开通微信支付的功能(管理员才拥有权限),只有在微信开发平台上申请通过了,才可以前后端结合实现微信支付的需求
1. 获取code
// 根据uniapp提供的api获取code
// this关键字代理
const _this = this
uni.login({
provider: 'weixin', // 使用微信登录
success: (res) => {
const {
code} = res;
// code => 0e1MTrFa1eDx9I0bRpJa1Mqfwf4MTrFJ
// 获取code成功后,获取openId
_this.getOpenId(code)
}
});
2. 获取openId
根据code,请求后端接口获取openId(此步需要后端配合提供接口)
// 后端提供接口,调用接口根据code获取到openId(可能还需要提供其他参数,根据后端需求来定)
getOpenId(code) {
getMiniOpenid(