微信小程序 手机号授权登录 偶尔后端解密失败

微信小程序wx.login获取code要在手机号授权前触发

复制代码
<button
			:id="code"
			:open-type="hasGetPrivacySetting ? 'getPhoneNumber|agreePrivacyAuthorization' : 'getPhoneNumber'"
			@getphonenumber="onGetPhoneNumber"
			class="btn"
			@click="clickPhoneNumber"
		>
		</button>

点击按钮是先触发 clickGetCode

复制代码
async clickGetCode() {
			  this.wxCode = await this.getCode()
			  console.log('this.wxCode', this.wxCode)
			},
			getCode() {
			  return new Promise((resolve, reject) => {
			    uni.login({
			      provider: 'weixin',
			      success: res => {
			        resolve(res.code)
			      },
			      fail: reject
			    })
			  })
			},

手机号授权后再将code和手机号加密串一起给后端

复制代码
			async onGetPhoneNumber(e) {
				// const code = await this.getCode()
				console.log('onGetPhoneNumber', e)
			    let that = this
			

			    if (e.detail.errMsg == "getPhoneNumber:ok") {
					loginMpWxMobile({
						form: {
						  code: that.wxCode,
						  encryptedData: e.detail.encryptedData,
						  isParty: true,
						  iv: e.detail.iv,
						  refereeId: 0
						}
					}).then(res => {
						
					})
			    } else {
					console.log('error', e)
			        wx.showToast({
			            title: "授权手机号失败",
			            icon: "none",
			        });
			    }
			
			},
相关推荐
speedoooo16 小时前
在现有App里嵌入一个AI协作者
前端·ui·小程序·前端框架·web app
万岳科技系统开发1 天前
私域直播小程序源码的整体架构设计与实现思路
学习·小程序
ee82ee1 天前
uniapp小程序底部键盘唤起问题处理,包含间隙处理,动画处理
微信小程序
qq_12498707531 天前
基于springboot健康养老APP的设计与实现(源码+论文+部署+安装)
java·spring boot·后端·mysql·微信小程序·毕业设计
汤姆yu1 天前
基于微信小程序的驾校预约与学习系统
学习·小程序·驾校预约
夏源1 天前
【微信小程序】实现引入 Echarts 并实现更新数据
微信小程序
speedoooo1 天前
未来的App不再需要菜单栏?
前端·ui·容器·小程序·web app
猿究院_xyz1 天前
微信小程序与echarts联动安卓真机测试出现黑色阴影
前端·javascript·微信小程序·小程序·echarts
说私域1 天前
不同类型企业构建私域流量的必要性及定制开发AI智能名片商城小程序的应用
大数据·人工智能·小程序
老华带你飞1 天前
健身房预约|基于springboot 健身房预约小程序系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·后端·小程序