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

微信小程序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",
			        });
			    }
			
			},
相关推荐
戈伊4 小时前
独立开发纪实:我如何用 Gemini CLI 和 Claude Code 打造一个“100% 含 AI 量”的小程序
微信小程序·ai编程
游戏开发爱好者84 小时前
iOS应用性能监控:Pre-Main与Main函数耗时分析及Time Profiler使用教程
android·ios·小程序·https·uni-app·iphone·webview
StarChainTech6 小时前
先享后付,正在悄悄改变电商的“信任游戏”
大数据·人工智能·游戏·微信小程序·小程序·软件需求
小羊Yveesss8 小时前
门店小程序外卖配送搭建实战:配送对接、运费策略与多门店调度方案
小程序·apache
tianxiaxue18 小时前
企业微信与小程序互联互通
小程序·企业微信
微擎应用16 小时前
全渠道批发订货商城小程序管理系统
大数据·小程序
杰建云1671 天前
多商家入驻小程序平台怎么做
人工智能·小程序
Giggle12181 天前
开发上门维修(家政)小程序系统的核心功能和便捷方案
大数据·小程序
2501_916008891 天前
ChatGPT前端开发学习指南:Visual Studio Code与谷歌浏览器安装配置详解
ide·vscode·ios·小程序·uni-app·编辑器·iphone
杰建云1671 天前
门店小程序怎么运营
大数据·小程序