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

微信小程序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",
			        });
			    }
			
			},
相关推荐
克里斯蒂亚诺更新10 小时前
微信小程序使用vant4 weapp自定义菜单 但是弹出层却被菜单遮挡的解决办法
微信小程序·小程序·notepad++
静Yu11 小时前
从一个九宫格素材小程序,看轻量工具产品该如何优化体验
前端·微信小程序
小羊Yveesss14 小时前
2026年微信小程序制作工具怎么选?
微信小程序·小程序
河北清兮网络科技16 小时前
深度解析:2026石家庄短视频APP开发真实成本、隐性开销与避坑方案
大数据·小程序·app·短剧app·广告联盟
微擎应用16 小时前
宠物门店系统 - 连锁宠物医院多门店小程序+公众号双端管理系统
小程序·宠物
脱脱克克17 小时前
使用 TRAE / VS Code + DeepSeek V4 开发微信小程序、网页
微信小程序·ai编程·环境配置
2501_9159214317 小时前
uni-app 上架 iOS 的完整流程(无需依赖 Mac)
android·macos·ios·小程序·uni-app·iphone·webview
前端 贾公子17 小时前
使用 wxappUnpacker 工具进行 MAC 微信小程序反编译
macos·微信小程序·小程序
CRMEB系统商城1 天前
CRMEB多商户系统(Java)v2.3公测版发布
java·开发语言·人工智能·小程序·开源·php
嫂子的姐夫2 天前
050-wx小程序合肥住房
爬虫·python·小程序·逆向