登陆秒滴官网后可以获得相关信息
看精简的发送代码,就两个函数实现发送
date_default_timezone_set("Asia/Shanghai"); //http post function curl_post($postUrl,$data,$header = array()){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$postUrl); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); if(strpos($postUrl,"https") !== false){ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); } if(count($header)>0){ curl_setopt($ch, CURLOPT_HTTPHEADER, $header); } $data = curl_exec($ch); curl_close($ch); return $data; } //发送用户注册的验证码 function sendsmscode($tel,$code){ $sms = array( "url" => "https://api.miaodiyun.com/20150822/industrySMS/sendSMS",//固定、无需修改 "sid" => "53c412f78a7143a585014578a4000000", //对应官网后台的 ACCOUNT SID "token" => "8b7c4094d39c4141aa41a91fd8000000", //对应官网后台的 AUTH TOKEN ); $timespan = date("YmdHis"); $sign = md5("{$sms['sid']}{$sms['token']}{$timespan}"); $data = array( "accountSid" =>$sms['sid'], "templateid" =>"318247587", "param" =>"{$code},2",//验证码、时长(分) "to" =>$tel, "timestamp" =>$timespan, "sig" =>$sign, "respDataType" =>"JSON", ); $fields_string = ""; foreach ($data as $key => $value) { $fields_string .= $key . '=' . $value . '&'; } rtrim($fields_string, '&'); $header = array( "Content-type: application/x-www-form-urlencoded", "Accept: application/json" ); $json = curl_post($sms['url'],$fields_string,$header); if(strpos($json,"{")!==false){ $json = substr($json,strpos($json,"{")); } return json_decode($json,true); } $x = sendsmscode("18221228706","8652"); header("Content-type:text/html;charset=utf-8"); var_dump($x);
正确后返回
array(5) { ["respCode"]=> string(5) "00000" ["respDesc"]=> string(15) "请求成功。" ["failCount"]=> string(1) "0" ["failList"]=> array(0) { } ["smsId"]=> string(32) "a395adf8c1874ef59baa0959637845d0" }