# 验证码短信发送接口


# 接口地址

http://api.1cloudsp.com/api/v2/single_send

用户通过HTTP(或HTTPS)的POST或GET方式提交短信发送请求。编码采用 UTF-8 编码。


# 请求参数

参数名 是否必填 类型 示例 描述
accesskey String xxxxxxxxxx 秘钥key
secret String yyyyyyyyyy 秘钥secret
sign String 测试签名 平台上申请的接口短信签名或者签名ID(须审核通过),采用utf8编码
templateId String 123456 平台上申请的接口短信模板Id(须审核通过)
mobile String 18100000000 接收短信的手机号码(只支持单个手机号)
content String 先生##9:40##快递公司##1234567 (示例模板:{1}您好,您的订单于{2}已通过{3}发货,运单号{4}) 发送的短信内容是模板变量内容,多个变量中间用 ## 或者 $$ 隔开,采用utf8编码

# 返回参数

参数名 类型 说明 描述
code String 请求状态数 0表示请求成功,非0表示请求失败;详细参考 错误码列表
msg String 状态说明
smUuid String 短信的唯一码

# 请求示例

package apiserver;
import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;

import com.alibaba.fastjson.JSONObject;

public class ApiTest {

    //普通短信
    private void sendsms() throws Exception {
        HttpClient httpClient = new HttpClient();
        PostMethod postMethod = new PostMethod("http://api.1cloudsp.com/api/v2/single_send");
        postMethod.getParams().setContentCharset("UTF-8");
        postMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,new DefaultHttpMethodRetryHandler());

        String accesskey = "xxxxxxxxxx"; //用户开发key
        String accessSecret = "yyyyyyyyyy"; //用户开发秘钥

        NameValuePair[] data = {
                new NameValuePair("accesskey", accesskey),
                new NameValuePair("secret", accessSecret),
                new NameValuePair("sign", "123"),
                new NameValuePair("templateId", "100"),
                new NameValuePair("mobile", "13900000001"),
                new NameValuePair("content", URLEncoder.encode("先生##9:40##快递公司##1234567", "utf-8"))//(示例模板:{1}您好,您的订单于{2}已通过{3}发货,运单号{4})
        };
        postMethod.setRequestBody(data);
        postMethod.setRequestHeader("Connection", "close");

        int statusCode = httpClient.executeMethod(postMethod);
        System.out.println("statusCode: " + statusCode + ", body: "
                    + postMethod.getResponseBodyAsString());
    }

    public static void main(String[] args) throws Exception {
        ApiTest t = new ApiTest();
        //普通短信
        t.sendsms();
    }
}

# 返回示例

{
    "code": "0",
    "msg": "SUCCESS",
    "smUuid": "xxxx"
}

# 详细说明

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.5.3</version>
</dependency>
<dependency>
    <groupId>commons-httpclient</groupId>
    <artifactId>commons-httpclient</artifactId>
    <version>3.1</version>
</dependency>