2024-04-27 11:47:31 +08:00

35 lines
934 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 下面仅展示客户端使用post方式发送content-type为application/json请求的场景
exports.main = async (event) => {
let body = event.body
if (event.isBase64Encoded) {
body = Buffer.from(body, 'base64')
}
const {
access_token,
openid
} = JSON.parse(body)
if (!access_token || !openid) {
return { // 不建议把完整手机号返回给前端
success: false,
error: {
code: 'params is not fund',
message: '参数错误',
}
}
}
const res = await uniCloud.getPhoneNumber({
provider: 'univerify',
appid: '__UNI__3A527D1', // DCloud appid不同于callFunction方式调用使用云函数Url化需要传递DCloud appid参数
access_token: access_token,
openid: openid
})
console.log(res); // res里包含手机号
return { // 不建议把完整手机号返回给前端
success: true,
info: {
code: 0,
message: '获取手机号成功',
data: res,
}
}
}