> For the complete documentation index, see [llms.txt](https://knowledgebase.offer18.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://knowledgebase.offer18.com/zh/lian-meng-ke/lian-meng-ke-api/otp-api.md).

# OTP API

OTP API 可用于在增值服务（VAS）活动中生成和验证 PIN，从而确保用户身份验证的安全性和高效性。

### **通用参数**

<table data-header-hidden><thead><tr><th width="150">路径</th><th width="150"> </th><th> </th></tr></thead><tbody><tr><td><strong>查询</strong></td><td><strong>类型</strong></td><td><strong>描述</strong></td></tr><tr><td>key</td><td>字符串</td><td>API 密钥</td></tr><tr><td>aid</td><td>整数</td><td>联盟 Id</td></tr><tr><td>mid</td><td>整数</td><td>您的广告主 MID</td></tr></tbody></table>

## 生成 OTP

```
POST https://api.offer18.com/api/af/otp_gen
```

### 请求参数

<table data-header-hidden><thead><tr><th width="212.5555419921875"></th><th width="191"></th><th></th></tr></thead><tbody><tr><td><strong>主体</strong></td><td><strong>类型</strong></td><td><strong>描述</strong>  </td></tr><tr><td>type</td><td>字符串</td><td>请求类型</td></tr><tr><td>userId</td><td>字符串</td><td>用户 ID（在合作伙伴下）</td></tr><tr><td>msisdn</td><td>字符串</td><td>手机号码（数字）</td></tr><tr><td>partner</td><td>字符串</td><td>合作伙伴名称</td></tr></tbody></table>

<pre data-overflow="wrap"><code><strong>https://api.offer18.com/api/af/otp_gen?key=000000000&#x26;aid=0000&#x26;mid=0000&#x26;msisdn=xxxxxxxx&#x26;partner=partnername&#x26;userId=xxxx
</strong></code></pre>

{% code title="成功" overflow="wrap" %}

```json
{
  "status": "200",
  "response": "otp_sent",
  "data": "6xxxxx00f3fa55axxxxxxxxxx567a" // 当合作伙伴 API 在响应中返回时，data[requestId] 键和值会返回 
} 
```

{% endcode %}

{% code title="失败" overflow="wrap" %}

```json
{     
  "status": "400",     
  "error": "invalid_user_credentials" 
}
```

{% endcode %}

***

## 验证 OTP

```
POST https://api.offer18.com/api/af/otp_verify
```

### 请求参数

<table data-header-hidden><thead><tr><th width="212.5555419921875"></th><th width="191"></th><th></th></tr></thead><tbody><tr><td><strong>主体</strong></td><td><strong>类型</strong></td><td><strong>描述</strong>  </td></tr><tr><td>userId</td><td>字符串</td><td>用户 ID</td></tr><tr><td>msisdn</td><td>字符串</td><td>手机号码</td></tr><tr><td>otp</td><td>字符串</td><td>用户收到的 OTP</td></tr><tr><td>partner</td><td>字符串</td><td>合作伙伴名称</td></tr><tr><td>request_id</td><td>字符串</td><td>用于跟踪的请求 ID</td></tr></tbody></table>

{% code overflow="wrap" %}

```
https://api.offer18.com/api/af/otp_verify?key=000000000&aid=0000&mid=0000&msisdn=xxxxxxxx&partner=partnername&userId=xxxx&request_id=xxxxx&otp=xxxxx
```

{% endcode %}

### 示例 API 响应

{% code title="成功" overflow="wrap" %}

```json
{     
  "status": "200",     
  "response": "otp_verified" 
} 
```

{% endcode %}

{% code title="失败" overflow="wrap" %}

```json
{     
  "status": "400",     
  "error": "invalid_user_credentials" 
}
```

{% endcode %}

***

{% hint style="info" %}
**为保证交互安全，请始终从服务器端调用 API。**
{% endhint %}
