60 lines
1.6 KiB
JavaScript
60 lines
1.6 KiB
JavaScript
exports.main = async (event, context) => {
|
|
let { access_token, openid, appid } = event
|
|
|
|
if (event.body) {
|
|
try {
|
|
const body = typeof event.body === 'string' ? JSON.parse(event.body) : event.body
|
|
access_token = body.access_token || body.accessToken || access_token
|
|
openid = body.openid || openid
|
|
appid = body.appid || appid
|
|
} catch (e) {
|
|
console.error('解析body失败:', e)
|
|
}
|
|
}
|
|
|
|
if (!access_token) {
|
|
return {
|
|
success: false,
|
|
message: 'access_token不能为空'
|
|
}
|
|
}
|
|
|
|
try {
|
|
const params = {
|
|
provider: 'univerify',
|
|
access_token: access_token,
|
|
openid: openid
|
|
}
|
|
|
|
if (appid) {
|
|
params.appid = appid
|
|
}
|
|
|
|
console.log('调用getPhoneNumber参数:', JSON.stringify(params))
|
|
|
|
const res = await uniCloud.getPhoneNumber(params)
|
|
|
|
console.log('getPhoneNumber返回:', JSON.stringify(res))
|
|
|
|
if (res && res.phoneNumber) {
|
|
return {
|
|
success: true,
|
|
phone: res.phoneNumber
|
|
}
|
|
} else {
|
|
return {
|
|
success: false,
|
|
message: '获取手机号失败',
|
|
error: res
|
|
}
|
|
}
|
|
} catch (error) {
|
|
console.error('获取手机号异常:', error)
|
|
return {
|
|
success: false,
|
|
message: '获取手机号异常',
|
|
error: error.message || error
|
|
}
|
|
}
|
|
}
|