短信 >
短信接入示例
短信接入示例
功能概述
短信服务(Short Message Service)是网易网易云通信为用户提供的一种通信服务的能力,目前支持验证码类短信、通知类短信、运营类短信、语音类短信、国际短信等是事务性短信。
短信接口为标准的HTTP接口,以下示例包含了常见语言如何发起HTTP请求,帮助开发者更高效的接入短信接口。
注:最重要的四个参数,务必参考计算示例服务器API,否则会出现{"desc":"bad http header","code":414}
参数
参数说明
AppKey
开发者平台分配的appkey
Nonce
随机数(最大长度128个字符)
CurTime
当前UTC时间戳,从1970年1月1日0点0 分0 秒开始到现在的秒数(String)
CheckSum
SHA1(AppSecret + Nonce + CurTime),三个参数拼接的字符串,进行SHA1哈希计算,转化成16进制字符(String,小写)
Appkey,Appsecret获取步骤:
成为云信开发者
创建应用
打开App Key管理
短信URL请求:(务必请将您创建的模板和对应的URL请求对应上,否则会出现404错误)
管理后台创建的模板分为:
Java-发送短信/语音短信验证码
package com.netease.code;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import com.netease.checksum.CheckSumBuilder;
/**
* 发送验证码
* @author liuxuanlin
*
*/
public class SendCode {
//发送验证码的请求路径URL
private static final String
SERVER_URL="https://api.netease.im/sms/sendcode.action";
//网易云信分配的账号,请替换你在管理后台应用下申请的Appkey
private static final String
APP_KEY="fd460d34e786e7754e505bc4fab0f027";
//网易云信分配的密钥,请替换你在管理后台应用下申请的appSecret
private static final String APP_SECRET="xxxxxxxx";
//随机数
private static final String NONCE="123456";
//短信模板ID
private static final String TEMPLATEID="3057527";
//手机号
private static final String MOBILE="13888888888";
//验证码长度,范围4~10,默认为4
private static final String CODELEN="6";
public static void main(String[] args) throws Exception {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(SERVER_URL);
String curTime = String.valueOf((new Date()).getTime() / 1000L);
/*
* 参考计算CheckSum的java代码,在上述文档的参数列表中,有CheckSum的计算文档示例
*/
String checkSum = CheckSumBuilder.getCheckSum(APP_SECRET, NONCE, curTime);
// 设置请求的header
httpPost.addHeader("AppKey", APP_KEY);
httpPost.addHeader("Nonce", NONCE);
httpPost.addHeader("CurTime", curTime);
httpPost.addHeader("CheckSum", checkSum);
httpPost.addHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
// 设置请求的的参数,requestBody参数
List nvps = new ArrayList();
/*
* 1.如果是模板短信,请注意参数mobile是有s的,详细参数配置请参考“发送模板短信文档”
* 2.参数格式是jsonArray的格式,例如 "['13888888888','13666666666']"
* 3.params是根据你模板里面有几个参数,那里面的参数也是jsonArray格式
*/
nvps.add(new BasicNameValuePair("templateid", TEMPLATEID));
nvps.add(new BasicNameValuePair("mobile", MOBILE));
nvps.add(new BasicNameValuePair("codeLen", CODELEN));
httpPost.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));
// 执行请求
HttpResponse response = httpClient.execute(httpPost);
/*
* 1.打印执行结果,打印结果一般会200、315、403、404、413、414、500
* 2.具体的code有问题的可以参考官网的Code状态表
*/
System.out.println(EntityUtils.toString(response.getEntity(), "utf-8"));
}
}
Java-发送通知类和运营类短信
package com.netease.code;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import com.netease.checksum.CheckSumBuilder;
/**
* 发送模板短信请求
* @author liuxuanlin
*
*/
public class SendCode {
//发送验证码的请求路径URL
private static final String
SERVER_URL="https://api.netease.im/sms/sendtemplate.action";
//网易云信分配的账号,请替换你在管理后台应用下申请的Appkey
private static final String
APP_KEY="fd460d34e786e7754e505bc4fab0f027";
//网易云信分配的密钥,请替换你在管理后台应用下申请的appSecret
private static final String APP_SECRET="xxxxxxxx";
//随机数
private static final String NONCE="123456";
//短信模板ID
private static final String TEMPLATEID="3057527";
//手机号,接收者号码列表,JSONArray格式,限制接收者号码个数最多为100个
private static final String MOBILES="['13888888888','13666666666']";
//短信参数列表,用于依次填充模板,JSONArray格式,每个变量长度不能超过30字,对于不包含变量的模板,不填此参数表示模板即短信全文内容
private static final String PARAMS="['xxxx','xxxx']";
public static void main(String[] args) throws Exception {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(SERVER_URL);
String curTime = String.valueOf((new Date()).getTime() / 1000L);
/*
* 参考计算CheckSum的java代码,在上述文档的参数列表中,有CheckSum的计算文档示例
*/
String checkSum = CheckSumBuilder.getCheckSum(APP_SECRET, NONCE, curTime);
// 设置请求的header
httpPost.addHeader("AppKey", APP_KEY);
httpPost.addHeader("Nonce", NONCE);
httpPost.addHeader("CurTime", curTime);
httpPost.addHeader("CheckSum", checkSum);
httpPost.addHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
// 设置请求的的参数,requestBody参数
List nvps = new ArrayList();
/*
* 1.如果是模板短信,请注意参数mobile是有s的,详细参数配置请参考“发送模板短信文档”
* 2.参数格式是jsonArray的格式,例如 "['13888888888','13666666666']"
* 3.params是根据你模板里面有几个参数,那里面的参数也是jsonArray格式
*/
nvps.add(new BasicNameValuePair("templateid", TEMPLATEID));
nvps.add(new BasicNameValuePair("mobiles", MOBILES));
nvps.add(new BasicNameValuePair("params", PARAMS));
httpPost.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));
// 执行请求
HttpResponse response = httpClient.execute(httpPost);
/*
* 1.打印执行结果,打印结果一般会200、315、403、404、413、414、500
* 2.具体的code有问题的可以参考官网的Code状态表
*/
System.out.println(EntityUtils.toString(response.getEntity(), "utf-8"));
}
}[org.apache.http.HttpResponse]
[org.apache.http.NameValuePair]
[org.apache.http.message.BasicNameValuePair]
[org.apache.http.util.EntityUtils]
[org.apache.http.client.entity.UrlEncodedFormEntity]
[org.apache.http.client.methods.HttpPost]
[org.apache.http.impl.client.DefaultHttpClient]
PHP-验证码及通知运营类短信
/**
* 发送模板短信
* @author chensheng
***/
//使用示例
require('./ServerAPI.php');
//网易云信分配的账号,请替换你在管理后台应用下申请的Appkey
$AppKey = 'fd460d34e786e7754e505bc4fab0f027';
//网易云信分配的账号,请替换你在管理后台应用下申请的appSecret
$AppSecret = 'xxxxxxxx';
$p = new ServerAPI($AppKey,$AppSecret,'fsockopen'); //fsockopen伪造请求
//发送短信验证码
print_r( $p->sendSmsCode('6272','13888888888','','5') );
//发送模板短信
print_r( $p->sendSMSTemplate('6272',array('13888888888','13666666666'),array('xxxx','xxxx' )));
?><?php
/**
* 网易云信server API 简单实例
* Class ServerAPI
* @author chensheng dengyuan
* @created date 2018-02-02 13:45
*
*
***/
class ServerAPI{
public $AppKey; //开发者平台分配的AppKey
public $AppSecret; //开发者平台分配的AppSecret,可刷新
public $Nonce; //随机数(最大长度128个字符)
public $CurTime; //当前UTC时间戳,从1970年1月1日0点0 分0 秒开始到现在的秒数(String)
public $CheckSum; //SHA1(AppSecret + Nonce + CurTime),三个参数拼接的字符串,进行SHA1哈希计算,转化成16进制字符(String,小写)
const HEX_DIGITS = "0123456789abcdef";
/**
* 参数初始化
* @param $AppKey
* @param $AppSecret
* @param $RequestType [选择php请求方式,fsockopen或curl,若为curl方式,请检查php配置是否开启]
*/
public function __construct($AppKey, $AppSecret, $RequestType = 'curl'){
$this->AppKey = $AppKey;
$this->AppSecret = $AppSecret;
$this->RequestType = $RequestType;
}
/**
* API checksum校验生成
* @param void
* @return $CheckSum(对象私有属性)
*/
public function checkSumBuilder(){
//此部分生成随机字符串
$hex_digits = self::HEX_DIGITS;
$this->Nonce;
for ($i = 0; $i < 128; $i++) { //随机字符串最大128个字符,也可以小于该数
$this->Nonce .= $hex_digits[rand(0, 15)];
}
$this->CurTime = (string)(time()); //当前时间戳,以秒为单位
$join_string = $this->AppSecret . $this->Nonce . $this->CurTime;
$this->CheckSum = sha1($join_string);
//print_r($this->CheckSum);
}
/**
* 将json字符串转化成php数组
* @param $json_str
* @return $json_arr
*/
public function json_to_array($json_str){
if (is_array($json_str) || is_object($json_str)) {
$json_str = $json_str;
} else if (is_null(json_decode($json_str))) {
$json_str = $json_str;
} else {
$json_str = strval($json_str);
$json_str = json_decode($json_str, true);
}
$json_arr = array();
foreach ($json_str as $k => $w) {
if (is_object($w)) {
$json_arr[$k] = $this->json_to_array($w); //判断类型是不是object
} else if (is_array($w)) {
$json_arr[$k] = $this->json_to_array($w);
} else {
$json_arr[$k] = $w;
}
}
return $json_arr;
}
/**
* 使用CURL方式发送post请求
* @param $url [请求地址]
* @param $data [array格式数据]
* @return $请求返回结果(array)
*/
public function postDataCurl($url, $data){
$this->checkSumBuilder(); //发送请求前需先生成checkSum
$timeout = 5000;
$http_header = array(
'AppKey:' . $this->AppKey,
'Nonce:' . $this->Nonce,
'CurTime:' . $this->CurTime,
'CheckSum:' . $this->CheckSum,
'Content-Type:application/x-www-form-urlencoded;charset=utf-8'
);
//print_r($http_header);
// $postdata = '';
$postdataArray = array();
foreach ($data as $key => $value) {
array_push($postdataArray, $key . '=' . urlencode($value));
}
$postdata = join('&', $postdataArray);
// var_dump($postdata);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $http_header);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //处理http证书问题
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
if (false === $result) {
$result = curl_errno($ch);
}
curl_close($ch);
return $this->json_to_array($result);
}
/**
* 使用FSOCKOPEN方式发送post请求
* @param $url [请求地址]
* @param $data [array格式数据]
* @return $请求返回结果(array)
*/
public function postDataFsockopen($url, $data){
$this->checkSumBuilder();//发送请求前需先生成checkSum
$postdata = '';
foreach ($data as $key => $value) {
$postdata .= ($key . '=' . urlencode($value) . '&');
}
// building POST-request:
$URL_Info = parse_url($url);
if (!isset($URL_Info["port"])) {
$URL_Info["port"] = 80;
}
$request = '';
$request .= "POST " . $URL_Info["path"] . " HTTP/1.1\r\n";
$request .= "Host:" . $URL_Info["host"] . "\r\n";
$request .= "Content-type: application/x-www-form-urlencoded;charset=utf-8\r\n";
$request .= "Content-length: " . strlen($postdata) . "\r\n";
$request .= "Connection: close\r\n";
$request .= "AppKey: " . $this->AppKey . "\r\n";
$request .= "Nonce: " . $this->Nonce . "\r\n";
$request .= "CurTime: " . $this->CurTime . "\r\n";
$request .= "CheckSum: " . $this->CheckSum . "\r\n";
$request .= "\r\n";
$request .= $postdata . "\r\n";
print_r($request);
$fp = fsockopen($URL_Info["host"], $URL_Info["port"]);
fputs($fp, $request);
$result = '';
while (!feof($fp)) {
$result .= fgets($fp, 128);
}
fclose($fp);
$str_s = strpos($result, '{');
$str_e = strrpos($result, '}');
$str = substr($result, $str_s, $str_e - $str_s + 1);
print_r($result);
return $this->json_to_array($str);
}
/**
* 发送短信验证码
* @param $templateid [模板编号(由客服配置之后告知开发者)]
* @param $mobile [目标手机号]
* @param $deviceId [目标设备号,可选参数]
* @return $codeLen [验证码长度,范围4~10,默认为4]
*/
public function sendSmsCode($templateid, $mobile, $deviceId = '', $codeLen){
$url = 'https://api.netease.im/sms/sendcode.action';
$data = array(
'templateid' => $templateid,
'mobile' => $mobile,
'deviceId' => $deviceId,
'codeLen' => $codeLen
);
if ($this->RequestType == 'curl') {
$result = $this->postDataCurl($url, $data);
} else {
$result = $this->postDataFsockopen($url, $data);
}
return $result;
}
/**
* 发送模板短信
* @param $templateid [模板编号(由客服配置之后告知开发者)]
* @param $mobiles [验证码]
* @param $params [短信参数列表,用于依次填充模板,JSONArray格式,如["xxx","yyy"];对于不包含变量的模板,不填此参数表示模板即短信全文内容]
* @return $result [返回array数组对象]
*/
public function sendSMSTemplate($templateid, $mobiles = array(), $params = ''){
$url = 'https://api.netease.im/sms/sendtemplate.action';
$data = array(
'templateid' => $templateid,
'mobiles' => json_encode($mobiles),
'params' => json_encode($params)
);
if ($this->RequestType == 'curl') {
$result = $this->postDataCurl($url, $data);
} else {
$result = $this->postDataFsockopen($url, $data);
}
return $result;
}
}
?>
C#-发送短信/语音短信验证码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.Net;
using System.IO;
namespace server_http_api
{
class CheckSumBuilder
{
// 计算并获取CheckSum
public static String getCheckSum(String appSecret, String nonce, String curTime){
byte[] data = Encoding.Default.GetBytes(appSecret + nonce + curTime);
byte[] result;
SHA1 sha = new SHA1CryptoServiceProvider();
// This is one implementation of the abstract class SHA1.
result = sha.ComputeHash(data);
return getFormattedText(result);
}
// 计算并获取md5值
public static String getMD5(String requestBody){
if (requestBody == null)
return null;
// Create a new instance of the MD5CryptoServiceProvider object.
MD5 md5Hasher = MD5.Create();
// Convert the input string to a byte array and compute the hash.
byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(requestBody));
// Create a new Stringbuilder to collect the bytes
// and create a string.
StringBuilder sBuilder = new StringBuilder();
// Loop through each byte of the hashed data
// and format each one as a hexadecimal string.
for (int i = 0; i < data.Length; i++)
{
sBuilder.Append(data[i].ToString("x2"));
}
// Return the hexadecimal string.
return getFormattedText(Encoding.Default.GetBytes(sBuilder.ToString()));
}
private static String getFormattedText(byte[] bytes){
char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5',
'6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
int len = bytes.Length;
StringBuilder buf = new StringBuilder(len * 2);
for (int j = 0; j < len; j++) {
buf.Append(HEX_DIGITS[(bytes[j] >> 4) & 0x0f]);
buf.Append(HEX_DIGITS[bytes[j] & 0x0f]);
}
return buf.ToString();
}
}
class HttpClient
{
//发起Http请求
public static void HttpPost(string url, Stream data, IDictionary headers = null){
System.Net.WebRequest request = HttpWebRequest.Create(url);
request.Method = "POST";
if (data != null)
request.ContentLength = data.Length;
//request.ContentType = "application/x-www-form-urlencoded;charset=utf-8";
if (headers != null)
{
foreach (var v in headers)
{
if (v.Key is HttpRequestHeader)
request.Headers[(HttpRequestHeader)v.Key] = v.Value;
else
request.Headers[v.Key.ToString()] = v.Value;
}
}
HttpWebResponse response = null;
try
{
// Get the response.
response = (HttpWebResponse)request.GetResponse();
// Display the status.
Console.WriteLine(response.StatusDescription);
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
// Display the content.
Console.WriteLine(responseFromServer);
// Cleanup the streams and the response.
reader.Close();
dataStream.Close();
response.Close();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(response.StatusDescription);
}
}
}
class Program
{
static void Main(string[] args){
String url = "https://api.netease.im/sms/sendcode.action";
url += "?templateid=3030410&mobile=13888888888";//请输入正确的手机号
//网易云信分配的账号,请替换你在管理后台应用下申请的Appkey
String appKey = "fd460d34e786e7754e505bc4fab0f027";
//网易云信分配的密钥,请替换你在管理后台应用下申请的appSecret
String appSecret = "xxxxxxxx";
//随机数(最大长度128个字符)
String nonce = "12345";
TimeSpan ts = DateTime.Now.ToUniversalTime() - new DateTime(1970, 1, 1);
Int32 ticks = System.Convert.ToInt32(ts.TotalSeconds);
//当前UTC时间戳,从1970年1月1日0点0 分0 秒开始到现在的秒数(String)
String curTime = ticks.ToString();
//SHA1(AppSecret + Nonce + CurTime),三个参数拼接的字符串,进行SHA1哈希计算,转化成16进制字符(String,小写)
String checkSum = CheckSumBuilder.getCheckSum(appSecret, nonce, curTime);
IDictionary headers = new Dictionary();
headers["AppKey"] = appKey;
headers["Nonce"] = nonce;
headers["CurTime"] = curTime;
headers["CheckSum"] = checkSum;
headers["ContentType"] = "application/x-www-form-urlencoded;charset=utf-8";
//执行Http请求
HttpClient.HttpPost(url, null, headers);
}
}
}
C#-发送通知类和运营类短信
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.Net;
using System.IO;
namespace server_http_api
{
class CheckSumBuilder
{
// 计算并获取CheckSum
public static String getCheckSum(String appSecret, String nonce, String curTime){
byte[] data = Encoding.Default.GetBytes(appSecret + nonce + curTime);
byte[] result;
SHA1 sha = new SHA1CryptoServiceProvider();
// This is one implementation of the abstract class SHA1.
result = sha.ComputeHash(data);
return getFormattedText(result);
}
// 计算并获取md5值
public static String getMD5(String requestBody){
if (requestBody == null)
return null;
// Create a new instance of the MD5CryptoServiceProvider object.
MD5 md5Hasher = MD5.Create();
// Convert the input string to a byte array and compute the hash.
byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(requestBody));
// Create a new Stringbuilder to collect the bytes
// and create a string.
StringBuilder sBuilder = new StringBuilder();
// Loop through each byte of the hashed data
// and format each one as a hexadecimal string.
for (int i = 0; i < data.Length; i++)
{
sBuilder.Append(data[i].ToString("x2"));
}
// Return the hexadecimal string.
return getFormattedText(Encoding.Default.GetBytes(sBuilder.ToString()));
}
private static String getFormattedText(byte[] bytes){
char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5',
'6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
int len = bytes.Length;
StringBuilder buf = new StringBuilder(len * 2);
for (int j = 0; j < len; j++) {
buf.Append(HEX_DIGITS[(bytes[j] >> 4) & 0x0f]);
buf.Append(HEX_DIGITS[bytes[j] & 0x0f]);
}
return buf.ToString();
}
}
class HttpClient
{
//发起Http请求
public static void HttpPost(string url, Stream data, IDictionary headers = null){
System.Net.WebRequest request = HttpWebRequest.Create(url);
request.Method = "POST";
if (data != null)
request.ContentLength = data.Length;
//request.ContentType = "application/x-www-form-urlencoded;charset=utf-8";
if (headers != null)
{
foreach (var v in headers)
{
if (v.Key is HttpRequestHeader)
request.Headers[(HttpRequestHeader)v.Key] = v.Value;
else
request.Headers[v.Key.ToString()] = v.Value;
}
}
HttpWebResponse response = null;
try
{
// Get the response.
response = (HttpWebResponse)request.GetResponse();
// Display the status.
Console.WriteLine(response.StatusDescription);
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
// Display the content.
Console.WriteLine(responseFromServer);
// Cleanup the streams and the response.
reader.Close();
dataStream.Close();
response.Close();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(response.StatusDescription);
}
}
}
class Program
{
static void Main(string[] args){
String url = "https://api.netease.im/sms/sendtemplate.action";
url += "?templateid=3030410&mobiles=['13888888888','13666666666']¶ms=['xxxx','xxxx']";//请输入正确的手机号
//网易云信分配的账号,请替换你在管理后台应用下申请的Appkey
String appKey = "fd460d34e786e7754e505bc4fab0f027";
//网易云信分配的密钥,请替换你在管理后台应用下申请的appSecret
String appSecret = "xxxxxxxx";
//随机数(最大长度128个字符)
String nonce = "12345";
TimeSpan ts = DateTime.Now.ToUniversalTime() - new DateTime(1970, 1, 1);
Int32 ticks = System.Convert.ToInt32(ts.TotalSeconds);
//当前UTC时间戳,从1970年1月1日0点0 分0 秒开始到现在的秒数(String)
String curTime = ticks.ToString();
//SHA1(AppSecret + Nonce + CurTime),三个参数拼接的字符串,进行SHA1哈希计算,转化成16进制字符(String,小写)
String checkSum = CheckSumBuilder.getCheckSum(appSecret, nonce, curTime);
IDictionary headers = new Dictionary();
headers["AppKey"] = appKey;
headers["Nonce"] = nonce;
headers["CurTime"] = curTime;
headers["CheckSum"] = checkSum;
headers["ContentType"] = "application/x-www-form-urlencoded;charset=utf-8";
//执行Http请求
HttpClient.HttpPost(url, null, headers);
}
}
}
常见错误码
所有的短信HTTP请求均有response,response有两部分组成,
第一部分是code,代表code具体的内容,成功还是失败
第二部分是desc或者msg,代表错误原因描述(非code=200的情况,才会有desc)
414参数错误
1. checksum
{"desc":"checksum","code":414}
典型的checksum计算错误,需要自行核对计算checksum的参数算法,前提是保证这个appSecret是属于您在管理后台的应用下的。
2. bad http header
{"desc":"bad http header","code":414}
典型的请求http header计算错误,需要自行核对请求header中的4个参数,分别为Appkey,Nonce,Curtime,CheckSum。(上述文档可以查询这4个参数)
3. 'mobiles' should be json format
{"code":414,"msg":"'mobiles' should be json format"}
典型的mobiles的参数传的有问题,因为文档的要求是jsonArray的格式,所以需要保证这个mobiles的参数是jsonArray的。例如:Java的格式为“['xxx','xxxx']”,其他代码方式请自行参考解决。
4. 'params' should be json format
{"code":414,"msg":"'params' should be json format"}
典型的params的参数传的有问题,因为文档的要求是jsonArray的格式,所以需要保证这个params的参数是jsonArray的,并且要注意你的参数数量,例如:Java的格式为“['xxx','xxxx']”,其他代码方式请自行参考解决。
5. sms template specify by id not found
{"code":414,"msg":"sms template specify by id not found"}
典型的短信模板与您的Appkey对应不上,导致参数传的有问题。需要保证当前审核过的短信模板,与您的这个当前应用下的Appkey是一一对应的,否则就会出现这样的错误。
404对象不存在
1. template id not exist
{"code":404,"msg":"template id not exist"}
典型的短信模板与您发起的http请求的url不一致,首先要检查管理后台审核的模板是否与您的请求一致,比如通知类模板请求的url是sendTemplate.action,验证码模板请求的url是sendcode.action,这些在上述文档中都有描述,可以查看。
400 HTTP错误
1. HTTP Status 400
这个错误是HTTP常见错误, 400 请求出错 由于语法格式有误,服务器无法理解此请求,一般出现的情况,都是短信请求的参数body与短信请求的URL不匹配导致的,只要参考检查上述文档中的URL,以及文档中的body参数即可。
余额预警阙值
余额预警阙值,先可以登录管理后台,点击左侧“总览”,当前页有个“”余额预警”,可以自行配置,余额提醒。
短信回执抄送
现在云信支持短信的回执抄送,抄送详细解释在Server端文档,配置抄送地址在管理后台中的当前应用下,有个“消息抄送配置”,配置地址可以是地址,也可以是域名。短信的抄送只要通道给了回执,原封不动的给抄送出去,包括发送成功和失败(如黑名单,空号等等),如果通道那边没有给回执,那我们这边就不会抄送。另外,如果短信被反垃圾了,也不会有抄送,这个相当于,短信都没投递到通道服务商那边。
本篇文档内容是否对您有帮助?
有帮助
我要吐槽
如果遇到产品相关问题,您可 提交工单 或 在线客服 寻求帮助。
您的改进建议
×
问题类型
内容错误
内容没更新
描述不清
链接有误
步骤不完整
内容缺失(缺少代码/示例)
其他
更多建议
请输入您的建议或问题(至少5个字符,至多500个字符)
联系方式
标记内容
同时提交标记内容
提交
此文档对你是否有帮助
×
有帮助
我要吐槽
×
反馈成功
非常感谢您的反馈,我们会继续努力做得更好。