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

微信小程序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",
			        });
			    }
			
			},
相关推荐
myzshare1 天前
实战分享:我是如何用SSM框架开发出一个完整项目的
java·mysql·spring cloud·微信小程序
sheji34161 天前
【开题答辩全过程】以 基于微信小程序的在线学习系统为例,包含答辩的问题和答案
学习·微信小程序·小程序
头发还在的女程序员1 天前
小剧场短剧影视小程序源码分享,搭建自己的短剧小程序
人工智能·小程序·短剧·影视·微剧
是江迪呀1 天前
小程序上线半年我赚了多少钱?
微信小程序·产品·创业
三天不学习2 天前
UniApp三端实时通信实战:SignalR在H5、APP、小程序的差异与实现
微信小程序·uni-app·signalr
qq_12498707532 天前
基于springboot归家租房小程序的设计与实现(源码+论文+部署+安装)
java·大数据·spring boot·后端·小程序·毕业设计·计算机毕业设计
说私域2 天前
留量为王,服务制胜:开源链动2+1模式、AI智能名片与S2B2C商城小程序的协同创新路径
人工智能·小程序·开源
游戏开发爱好者82 天前
如何使用 AppUploader 提交上传 iOS 应用
android·ios·小程序·https·uni-app·iphone·webview
百锦再2 天前
AI视频生成模型从无到有:构建、实现与调试完全指南
人工智能·python·ai·小程序·aigc·音视频·notepad++
恩创软件开发2 天前
创业日常2026-1-8
java·经验分享·微信小程序·小程序