'use strict';
// 云函数
exports.main = async function (event){
const res = await uniCloud.getPhoneNumber({
appid: '__UNI__3D620F8', // 替换成自己开通一键登录的应用的DCloud appid
provider: 'univerify',
apiKey: '', // 在开发者中心开通服务并获取apiKey
apiSecret: '', // 在开发者中心开通服务并获取apiSecret
access_token: event.access_token,
openid: event.openid
})
// 执行入库等操作,正常情况下不要把完整手机号返回给前端
return res
}
uni.login({
provider: 'univerify',
univerifyStyle: {
fullScreen: true,
icon: {
path: "static/img/sys/0409/192.png"
},
authButton: {
normalColor: "#005792",
},
otherLoginButton: {
visible: false
},
buttons: { // 自定义页面下方按钮仅全屏模式生效(3.1.14+ 版本支持)
iconWidth: "80px", // 图标宽度(高度等比例缩放) 默认值:45px
list: [{
provider: "other",
iconPath: "/static/img/other-login.png" // 图标路径仅支持本地图片
}, ]
}
},
success: (res) => {
let {
access_token,
openid
} = res.authResult
uniCloud.callFunction({
name: 'localPhoneNumber', // 你的云函数名称
data: {
access_token: access_token, // 客户端一键登录接口返回的access_token
openid: openid // 客户端一键登录接口返回的openid
}
}).then(result => {
this.login(result.result.phoneNumber)
}).catch(err => {
uni.closeAuthView()
})
},
fail: (fail) => {
if (fail.code == 30008 && fail.provider == 'other') {
uni.closeAuthView()
}
}
})


zipe (作者)
就是那个一键登录的云函数,获取不到有时候获取不到传入的参数,偶发性的,国庆后我再去看下,发您。
2021-09-30 21:54
zipe (作者)
真机调试 连接的云端函数 调用云函数报错 【连接本地调试服务失败,请检查客户端是否和主机在同一局域网下】
2021-09-30 22:30