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

微信小程序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",
			        });
			    }
			
			},
相关推荐
头发还在的女程序员2 小时前
家政SaaS平台开源:从供应商入驻到分账结算,源码如何设计?
小程序·开源
焦糖玛奇朵婷5 小时前
解锁扭蛋机小程序的五大优势
java·大数据·服务器·前端·小程序
web前端神器10 小时前
记录uniapp小程序的报错
小程序·uni-app·apache
weikecms12 小时前
外卖霸王餐api接口,美团+淘宝闪购接口
微信·小程序·微客云
Greg_Zhong12 小时前
微信小程序中进度条总结
微信小程序·自定义进度条·slider进度条
2501_916008891 天前
深入解析iOS应用启动性能优化策略与实践
android·ios·性能优化·小程序·uni-app·cocoa·iphone
TuCoder1 天前
制作景区导览小程序时,现有手绘图是否可以复用?
小程序·智慧景区·手绘地图·景区导览·电子导览·地图制作·ebmap
小小王app小程序开发2 天前
盲盒小程序一番赏玩法分析
小程序
这是个栗子2 天前
【微信小程序问题解决】删掉 “navigationStyle“: “custom“ 后仍触发了自定义导航栏
微信小程序·小程序·navigationstyle
liangdabiao2 天前
定制的乐高马赛克像素画生成器-微信小程序版本-AI 风格优化-一键完成所有工作
人工智能·微信小程序·小程序