## 短信发送接口

### 接口地址
[https://sms.dun.163.com/v2/sendsms](https://sms.dun.163.com/v2/sendsms)

### 接口描述

该接口主要功能

- 发送短信到用户


### 请求参数
公共参数已省略，详细见 [公共参数](/help/documents/210177261692964864)，其他参数如下：

| 参数名称       | 类 型    | 是否必选 | 最大长度 | 描述      |
| ----------- | ------ | ---- | ---- | ------- |
| mobile       | String | Y    | 11   | 手机号；若发送国际短信，请去掉手机号前的0 |
| params | String | Y    | 500 | {"code":"123","time":"20180816"}   |
| templateId   |String    | Y | 20    | 模板id   |
| paramType | String | Y    |  | 该字段必填：“json”   |
| internationalCode | String | N | | 国内短信业务不需要此参数。调用国际短信时，在此传国家代码。[国家代码大全](http://support.dun.163.com/documents/2018101001?docId=312416649339916288)     |




### 响应结果

响应字段如下，响应通用字段已省略，详细见[响应通用字段](/help/documents/210177825688440832)：

data 数据结构

| 参数名称   | 类型     | 描述                                       |
| ------ | ------ | ---------------------------------------- |
| result | Number | 接口调用状态，200:正常，其他值：调用出错，返回码见 [响应结果码](/help/documents/210182483777605632#响应结果码) |
| requestId | String | 本次请求的唯一标识符，通过该符号查询短信发送状态接口可以查询短信发送状态 |



### 响应结果码

响应返回码（result）。当返回码不为 200 时， 表示请求未正常执行。

所有接口调用返回值均包含 result 字段， 返回码表如下：

| 返回码 | 结果码描述 | 说明         |
| :----- | ---------- | ------------ |
| 200    | ok         | 接口调用成功 |
|  203  | service exception | 服务异常  |
| 206  | mobile error           | 手机号码不正确   |
| 216  | content error         | 短信内容包含非法关键字                     |
| 222  | over maximum limits   | 超过日最大条数的限制       |



### 请求示例

```java
    /** 产品密钥ID，产品标识 */
    private final static String SECRETID = "your_secret_id";
    /** 产品私有密钥，服务端生成签名信息使用，请严格保管，避免泄露 */
    private final static String SECRETKEY = "your_secret_key";
    /** 业务ID，易盾根据产品业务特点分配 */
    private final static String BUSINESSID = "your_business_id";
    /** 本机认证服务身份证实人认证在线检测接口地址 */
    private final static String API_URL = "https://sms.dun.163.com/v2/sendsms";
    /** 实例化HttpClient，发送http请求使用，可根据需要自行调参 */
    private static HttpClient httpClient = HttpClient4Utils.createHttpClient(100, 100, 2000, 2000, 2000);

    /**
     *
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
        Map<String, String> params = new HashMap<String, String>();
        // 1.设置公共参数
        params.put("secretId", SECRETID);
        params.put("businessId", BUSINESSID);
        params.put("version", "v2");
        params.put("timestamp", String.valueOf(System.currentTimeMillis()));
        //32随机字符串
        //params.put("nonce", getRandomStr(32));
        params.put("nonce", "dh2u81hdah129zjk2hlla118snebd2q1");
        // 2.设置私有参数d
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", "123");
        jsonObject.put("time", "20180816");
        params.put("mobile", "18883110011");
        //使用JSON格式填充模板
        params.put("paramType", "json");
        params.put("params", jsonObject.toJSONString());
        params.put("templateId", "10000");
        //需要上行的时候,这里需要设置为true
        params.put("needUp", "true");

        // 3.生成签名信息
        String signature = SignatureUtils.genSignature(SECRETKEY, params);
        params.put("signature", signature);
        // 4.发送HTTP请求，这里使用的是HttpClient工具包，产品可自行选择自己熟悉的工具包发送请求
        String response = HttpClient4Utils.sendPost(httpClient, API_URL, params);
        //5.解析报文返回
        ApiResponse apiResponse = gson.fromJson(response, ApiResponse.class);
        //6.返回结果
        String requestId = apiResponse.getData().getRequestId();
    }
       
```

### 响应示例
当请求成功时，输出示例如下：
```json
{
	"code": 200,
	"msg": "ok",
	"data": 
  	{
  	  "result" : 200,
  	  "requestId" : "7bgsdg2sdhfwi34hkhui"
	}
}
```