请求示例:
{AppSecret}:签约后技术人员会提供
{url}:sms.1oc.cn
{mobphone} 手机号
{smstemplate}短信模板
{code} 替换短信模板中的变量
CURL
curl -i -k --get --include 'https://{url}/?module=sms&file=send&action=send&mobphone={mobphone}&code={code}&smstemplate={smstemplate}' -H 'Authorization:{AppSecret}'PHP
$host="https://{url}";
$path = "/";
$method="GET";
$appsecret="{AppSecret}";
$headers=array();
array_push($headers,"Authorization:".$appsecret);
$querys="module=sms&file=send&action=send&mobphone={mobphone}&code={code}&smstemplate={smstemplate}";
$bodys="";
$url=$host.$path."?".$querys;
$curl=curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST,$method);
curl_setopt($curl, CURLOPT_URL,$url);
curl_setopt($curl, CURLOPT_HTTPHEADER,$headers);
curl_setopt($curl, CURLOPT_FAILONERROR,false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_HEADER,true);
if(1==strpos("$".$host,"https://"))
{
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,false);
}
var_dump(curl_exec($curl));JAVA
public static void main(String[] args) {
String host = "https://{url}";
String path = "/";
String method = "GET";
String appsecret = "{AppSecret}";
Mapheaders = new HashMap();
headers.put("Authorization",appsecret);
Mapquerys = new HashMap();
querys.put("module", "sms");
querys.put("file", "send");
querys.put("action", "send");
querys.put("mobphone", "{mobphone}");
querys.put("code", "{code}");
querys.put("smstemplate", "{smstemplate}");
try {
/**
* 重要提示如下:
* HttpUtils请从
* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
* 下载
*
* 相应的依赖请参照
* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
*/
HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
System.out.println(response.toString());
//获取response的body
//System.out.println(EntityUtils.toString(response.getEntity()));
} catch (Exception e) {
e.printStackTrace();
}
}Python
import urllib, urllib2, sys
import ssl
host = 'https://{url}'
path = '/'
method = 'GET'
appsecret = "{AppSecret}";
querys = 'module=sms&file=send&action=send&mobphone={mobphone}&code={code}&smstemplate={smstemplate}'
bodys = {}
url = host + path + '?' + querys
request = urllib2.Request(url)
request.add_header('Authorization',appsecret)
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
response = urllib2.urlopen(request, context=ctx)
content = response.read()
if (content):
print(content)失败响应
{
"code": 400, //指返回结果码,并非http状态码
"msg": "校验失败",
"mid": ""
}成功响应
{
"code": 200,
"msg": "ok",
"mid": "1151894566D2EDD9" //唯一,短信状态获取用到
}通话记录POST至returnurl地址,数据如下:
{"mid":"1151894566D2EDD9","stat":"DELIVRD"}stat状态码说明:
错误代码 说明 DELIVRD 短信投递成功 EXPIRED Message validity period has expired DELETED Message has been deleted. REJECTED Message is in a rejected state MA:0001 全局黑名单号码 MA:0002 内容非法 MA:0003 无法找到下级路由 MA:0004 错误的内容长度 MA:0005 目的号码格式错误 MA:0006 系统拒绝 MA:0009 未定义错误 MA:0011 未知系统内部错误 MA:0015 余额不足 MA:0017 签名无效 MA:0021 号码格式错误 MA:0022 下发次数限制 MA:0023 客户黑名单号码 MA:0024 内容未报备 MA:0025 不支持该短信 MA:0026 分条发送,组包超时 MA:0027 通道黑名单 MA:0028 全局黑名单号段 MA:0029 通道黑名单号段 MA:0030 直接产生拒绝报告 MA:0033 地区拦截 MA:0044 号段拦截 MO:200 不支持分条短信 MO:0254 转发提交超时 MO:0255 转发提交过程中,连接断开 MO:NNNN NNNN为对外提交过程中,上级网关的返回值,具体含义需上级网关解释


