用户信息 /手机号 /获取手机号

# 获取手机号

> 接口应在服务器端调用,详细说明参见[服务端API](https://developers.weixin.qq.com/miniprogram/dev/framework/server-ability/backend-api.html)。

## 接口说明

### 接口英文名

getPhoneNumber

### 功能描述

该接口用于将 code 换取用户手机号。 说明,每个 code 只能使用一次,code的有效期为5min。

## 调用方式

### HTTPS 调用

```text
POST https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=ACCESS_TOKEN 
```

### 第三方调用

- 调用方式以及出入参和 HTTPS 相同,仅是调用的 token 不同
- 该接口所属的权限集 id 为:18
- 服务商获得其中之一权限集授权后,可通过使用[authorizer_access_token](https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/token/api_authorizer_token.html)代商家进行调用

### 请求参数

| 属性                                  | 类型   | 必填 | 说明                                                         |
| :------------------------------------ | :----- | :--- | :----------------------------------------------------------- |
| access_token / cloudbase_access_token | string | 是   | 接口调用凭证,该参数为 URL 参数,非 Body 参数。access_token和cloudbase_access_token二选一 其中access_token可通过[getAccessToken](https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/access-token/auth.getAccessToken.html)接口获得; 如果是第三方代调用请传入[authorizer_access_token](https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/token/api_authorizer_token.html); cloudbase_access_token可通过[getOpenData](https://developers.weixin.qq.com/miniprogram/dev/wxcloudrun/src/guide/weixin/token.html)接口获得 |
| code                                  | string | 是   | [手机号获取凭证](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/getPhoneNumber.html) |

### 返回参数

|      | 属性                                                         | 类型   | 说明           |
| :--- | :----------------------------------------------------------- | :----- | :------------- |
|      | errcode                                                      | number | 错误码         |
|      | errmsg                                                       | string | 错误信息       |
|      | phone_info                                                   | object | 用户手机号信息 |
|      | 属性类型说明phoneNumberstring用户绑定的手机号(国外手机号会有区号)purePhoneNumberstring没有区号的手机号countryCodestring区号watermarkobject数据水印属性类型说明timestampnumber用户获取手机号操作的时间戳appidstring小程序appid |        |                |

## 调用示例

> 示例说明: HTTPS请求示例

### 请求数据示例

```json
{
"code": "e31968a7f94cc5ee25fafc2aef2773f0bb8c3937b22520eb8ee345274d00c144"
} 
```

### 返回数据示例

```json
{
    "errcode":0,
    "errmsg":"ok",
    "phone_info": {
        "phoneNumber":"xxxxxx",
        "purePhoneNumber": "xxxxxx",
        "countryCode": 86,
        "watermark": {
            "timestamp": 1637744274,
            "appid": "xxxx"
        }
    }
} 
```

### 错误码

| 错误码 | 错误码取值   | 解决方案                       |
| :----- | :----------- | :----------------------------- |
| -1     | system error | 系统繁忙,此时请开发者稍候再试 |
| 40029  | code 无效    | js_code无效                    |

|      |      |      |
| :--- | :--- | :--- |
|      |      |      |
|      |      |      |
|      |      |      |