- 开发引导
- API文档
- 客户发送接口
- 客户余额及已发送查询
- 客户非法关键词查询
- 客户状态报告接口
- 客户上行接口
- 代码示例
- Php代码示例
- Java代码示例
- 短信状态码
- 中国电信错误码
- 中国联通错误码
- 中国移动错误码
- 常见问题
Php代码示例
Demo代码下载 Php代码示例
<?php //查询余额 $baseUrl= "http://客户端地址"; $smsUrl = $baseUrl."/sms.aspx?dataType=json"; $statusApiUrl = $baseUrl."/statusApi.aspx?dataType=json"; $callApiUrl = $baseUrl."/callApi.aspx?dataType=json"; $userid = "您的用户id"; $account = "您的账户名"; $password = "您的密码"; $mobile = "11位手机号1,11位手机号2,11位手机号3"; $content = "【签名】这里是短信的内容"; function posturl($url,$data){ $o=''; foreach ($data as $k=>$v) { $o.="$k=".$v.'&'; } $post_data=substr($o,0,-1); $headerArray =array("Content-type:application/x-www-form-urlencoded;charset='utf-8'","Accept:application/json"); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url);// 要访问的地址 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);// 对认证证书来源的检查 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,FALSE);// 从证书中检查SSL加密算法是否存在 curl_setopt($curl, CURLOPT_POST, 1);// 发送一个常规的Post请求 curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环 curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环 curl_setopt($curl,CURLOPT_HTTPHEADER,$headerArray); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);// 获取的信息以文件流的形式返回 $output = curl_exec($curl); curl_close($curl); return json_decode($output,true); } //查询余额 function queryOverage() { $post_data = array( 'userid' => $userid , 'account' => $account, 'password' => $password ); $res = posturl($smsUrl, $post_data); echo $res; } //查询屏蔽词 function queryKeyWord($content) { $post_data = array( 'userid' => $userid , 'account' => $account, 'password' => $password, 'content'=> urlencode($content) ); $res = posturl($smsUrl,$post_data); echo $res; } //发送短信 function sendSms($mobile,$content) { $post_data = array( 'userid' => $userid , 'account' => $account, 'password' => $password, 'mobile'=> $mobile, 'content'=> urlencode($content) ); $res = posturl($smsUrl,$post_data); echo $res; } //查询状态报告 function queryStatusReport() { $post_data = array( 'userid' => $userid , 'account' => $account, 'password' => $password ); $res = posturl($statusApiUrl,$post_data); echo $res; } //查询回复 function queryCall() { $post_data = array( 'userid' => $userid , 'account' => $account, 'password' => $password ); $res = posturl($callApiUrl,$post_data); echo $res; }