收藏
回答

错误码:-80422,[getPhoneNumber] is wrong API name?

微信小程序真机调试报错:
message:Error: 系统错误,错误码:-80422,error: [getPhoneNumber] is wrong API name [20251202 01:21:50]

exports.main = async (event, context) => {
  console.log('=== getPhoneNumberByCode 云函数开始执行 ===')
  console.log('事件参数:', JSON.stringify(event, null, 2))
  
  try {
    const { code } = event
    
    // 参数验证
    if (!code) {
      console.error('❌ 缺少必要参数: code')
      return {
        success: false,
        code: 'MISSING_PARAM',
        message: '缺少必要参数: code',
        timestamp: Date.now()
      }
    }
    
    // 验证 code 格式
    if (typeof code !== 'string' || code.length < 10) {
      console.error('❌ code 格式错误:', code)
      return {
        success: false,
        code: 'INVALID_CODE_FORMAT',
        message: 'code格式错误',
        timestamp: Date.now()
      }
    }
    
    // 使用云调用 API 获取手机号
    console.log('📞 调用微信开放接口获取手机号...')
    
    try {
      // 注意:这里需要使用云调用,这是微信云开发的正确方式
      const result = await cloud.openapi.phonenumber.getPhoneNumber({
        code: code
      })
      
      console.log('✅ 微信开放接口返回:', JSON.stringify(result, null, 2))
      
回答关注问题邀请回答
收藏

1 个回答

  • 智能回答 智能回答 本次回答由AI生成
    2025-12-02
    有用
登录 后发表内容