多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
> 注意,此处文档是在我们平台 www.api51.cn 充值使用的接口,而非阿里云市场接口 # POST/GET请求 地址:http://www.api51.cn/api/smsApi/sendcode 如需https请修改为 https://www.api51.cn # 参数说明 | 参数 | 说明 | 备注 | | --- | --- | --- | | token | 识别用户的唯一令牌 | 在www.api51.cn注册后可获得 | | mobile | 手机号 | 如:180XXXXXXXX | | sign | 短信签名 | 确保已经申请通过,默认发送:API无忧 | | tpl_id | 短信模版ID | 确保已经申请通过 | | params | 短信模版变量 | 确保已经申请通过,多个以英文逗号隔开。如:张三,1234 | | country_code | 国家代码,可选参数,默认中国(86) | 如:86 参考国家代码表:http://help.api51.cn/432250 | # 返回示例: 发送成功 ~~~ { "result": 0, "errmsg": "OK", "ext": "", "sid": "8:5Komg28XqC78HBEDnOy20171019", "fee": 1 } ~~~ 发送失败 ~~~ { "result": 1016, "errmsg": "手机号格式错误", "ext": "" } ~~~ # php代码示例 ~~~ <?php /* 优化阿里云默认提供代码示例 php 5.3以上版本 支持 curl */ $host = "http://www.api51.cn";//如需https请修改为 https://www.api51.cn $path = "/api/smsApi/sendcode";//path为 single_sms_get 时为GET请求 $method = "0";//post=1 get=0 本接口都支持 $url = $host . $path; $data = array( 'token'=>'写你的token', 'mobile'=>'1892584891',//接收手机号 'params'=>'22,123',//模板变量,多个以英文逗号隔开 'sign'=>'API无忧',//登陆www.api51.cn申请成功的签名 'tpl_id'=>'47331',//登陆www.api51.cn申请成功的模版ID,我们提供常用模板:http://help.api51.cn/425602 ); $data = http_build_query($data); $result = api51_curl($url,$data,$method); echo $result; function api51_curl($url,$data=false,$ispost=0){ $headers = array(); array_push($headers, "Content-Type".":"."application/x-www-form-urlencoded; charset=UTF-8"); $httpInfo = array(); $ch = curl_init(); curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 ); curl_setopt( $ch, CURLOPT_USERAGENT , 'api51.cn' ); curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 300 ); curl_setopt( $ch, CURLOPT_TIMEOUT , 300); curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true ); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_FAILONERROR, false); if (1 == strpos("$".$url, "https://")) { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); } if($ispost) { curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt( $ch , CURLOPT_POST , true ); curl_setopt( $ch , CURLOPT_POSTFIELDS , $data ); curl_setopt( $ch , CURLOPT_URL , $url ); } else { curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); if($data){ curl_setopt( $ch , CURLOPT_URL , $url.'?'.$data ); }else{ curl_setopt( $ch , CURLOPT_URL , $url); } } $response = curl_exec( $ch ); if ($response === FALSE) { // echo "cURL Error: " . curl_error($ch); return false; } $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE ); $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) ); curl_close( $ch ); return $response; } ?> ~~~