网易云短信API

网易云短信API:
验证码短信
[php]
$mobile=’手机号’;
$templateid=’模板ID’;
$params='[xxx,yyy,zzz]’;
header("Content-Type:text/html; charset=utf-8");
$AppKey = ‘AppKey’;
$AppSecret = ‘AppSecret’;
$Nonce = rand(100000,999999);
$CurTime = time();
$CheckSum = sha1($AppSecret.$Nonce.$CurTime);
$url = ‘https://api.netease.im/sms/sendcode.action’;
$head_arr = array();
$head_arr[] = ‘Content-Type: application/x-www-form-urlencoded’;
$head_arr[] = ‘charset: utf-8’;
$head_arr[] = ‘AppKey:’.$AppKey;
$head_arr[] = ‘Nonce:’.$Nonce;
$head_arr[] = ‘CurTime:’.$CurTime;
$head_arr[] = ‘CheckSum:’.$CheckSum;
$data = array();
$data[‘templateid’] = $templateid;
$data[‘mobile’] = $mobile;
$data[‘params’] = $params;
// var_dump($data);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $head_arr);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER,false);
// var_dump(curl_error($ch));
$result = curl_exec($ch);
curl_close($ch);
$resArr = (array) json_decode($result);
// $resArr = (array) json_decode(‘{"code":200,"msg":"sendid","obj":1}’);
// var_dump($resArr);
echo $resArr[‘obj’];
[/php]
通知类短信:
[php]
$mobile=array("18536562541");
$templateid=’3059447′;
$params=array("666");
$params[]="888";
header("Content-Type:text/html; charset=utf-8");
$AppKey = ‘AppKey’;
$AppSecret = ‘AppSecret ‘;
$Nonce = rand(100000,999999);
$CurTime = time();
$CheckSum = sha1($AppSecret.$Nonce.$CurTime);
$url = ‘https://api.netease.im/sms/sendtemplate.action’;
$head_arr = array();
$head_arr[] = ‘Content-Type: application/x-www-form-urlencoded’;
$head_arr[] = ‘charset: utf-8’;
$head_arr[] = ‘AppKey:’.$AppKey;
$head_arr[] = ‘Nonce:’.$Nonce;
$head_arr[] = ‘CurTime:’.$CurTime;
$head_arr[] = ‘CheckSum:’.$CheckSum;
$data = array();
$data[‘templateid’] = $templateid;
$data[‘mobiles’] = json_encode($mobile);
$data[‘params’] = json_encode($params);
// var_dump($data);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $head_arr);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER,false);
// var_dump(curl_error($ch));
$result = curl_exec($ch);
curl_close($ch);
$resArr = (array) json_decode($result);
// $resArr = (array) json_decode(‘{"code":200,"msg":"sendid","obj":1}’);
var_dump($resArr);
// echo $result;
[/php]
获取短信状态:
[php]
header("Content-Type:text/html; charset=utf-8");
$AppKey = ‘AppKey ‘;
$AppSecret = ‘AppSecret ‘;
$Nonce = rand(100000,999999);
$CurTime = time();
$CheckSum = sha1($AppSecret.$Nonce.$CurTime);
$url = ‘https://api.netease.im/sms/querystatus.action’;
$head_arr = array();
$head_arr[] = ‘Content-Type: application/x-www-form-urlencoded’;
$head_arr[] = ‘charset: utf-8’;
$head_arr[] = ‘AppKey:’.$AppKey;
$head_arr[] = ‘Nonce:’.$Nonce;
$head_arr[] = ‘CurTime:’.$CurTime;
$head_arr[] = ‘CheckSum:’.$CheckSum;
$data = array();
$data[‘sendid’] = $sendid; //短信ID
// var_dump($data);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $head_arr);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER,false);
// var_dump(curl_error($ch));
$result = curl_exec($ch);
curl_close($ch);
$resArr = json_decode($result,true);
// $resArr = (array) json_decode(‘{"code":200,"obj":[{"updatetime":1494383263495,"status":1,"mobile":"1853254514"}]}’);
return $resArr[‘obj’][0];
[/php]

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注