uni-app 一键登录报错 之前是正常返回手机号的
uni-app 一键登录报错 之前是正常返回手机号的
| 开发环境 | 版本号 | 项目创建方式 |
|---|---|---|
| uniCloud/App | 未知 | 未知 |
操作步骤:
uniCloud.callFunction({
name: 'login', // 你的云函数名称
data: {
'access_token': res.authResult.openid, // 客户端一键登录接口返回的access_token
'openid': res.authResult.access_token // 客户端一键登录接口返回的openid
}
})
预期结果:
正确返回手机号
实际结果:
返回错误信息
Error: errCode: 5000 | errMsg: 获取手机号码失败:参数错误
bug描述:
const res = await uniCloud.getPhoneNumber({
appid: '_*UNIC0F', // 替换成自己开通一键登录的应用的DCloud appid,使用callFunction方式调用时可以不传(会自动取当前客户端的appid),如果使用云函数URL化的方式访问必须传此参数
provider: 'univerify',
apiKey: '58299dd**19be66f3880c0e2', // 在开发者中心开通服务并获取apiKey
apiSecret: 'e8c95c6c11f4****4332f2cb03b8', // 在开发者中心开通服务并获取apiSecret
access_token: event.access_token,
openid: event.openid
})
更多关于uni-app 一键登录报错 之前是正常返回手机号的的实战教程也可以访问 https://www.itying.com/category-93-b0.html
4 回复
修改昵称报错 私信我一下我回复吧
apikey怎么获取到?
根据你提供的代码和错误信息,问题很可能出现在参数传递上。
从你的代码片段可以看出,你在客户端调用云函数时,将 access_token 和 openid 的值互相传反了。
错误分析:
在 uniCloud.callFunction 中,你传递的数据是:
data: {
'access_token': res.authResult.openid, // 这里实际传的是openid
'openid': res.authResult.access_token // 这里实际传的是access_token
}
而在云函数 getPhoneNumber 方法中,你需要的是:
access_token: event.access_token, // 应该接收真正的access_token
openid: event.openid // 应该接收真正的openid
解决方案:
修正客户端调用云函数时的参数顺序:
uniCloud.callFunction({
name: 'login',
data: {
'access_token': res.authResult.access_token, // 修正:传递access_token
'openid': res.authResult.openid // 修正:传递openid
}
})

