smsapi【2】.php:
<?php
$url='http://sms.webchinese.cn/web_api/?Uid=账号&Key=接口密钥&smsMob=手机号码&smsText=验证码:8888';
echo Get($url)
function Get($url)
{
$ch = curl_init();
// curl_init()需要php_curl.dll扩展
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
return $file_contents;
}
smsapi【1】.php:
<?php
/*
* 秒嘀验证码发送接口类
* By:somnus
* Time:2016-12-15 21:33
* */
class Smsapi{
protected $sendurl = "https://smssh1.253.com/msg/send/json";
//发送验证码
//成功返回0,失败返回错误代码
public function send($number,$cont){
$user = "xxxxxxx"; //短信平台帐号
$pass = "xxxxxxx"; //短信平台密码
//$sendurl = $this->sendurl."msg/send?un=".$user."&pw=".$pass."&phone=".$number."&msg=".urlencode($cont);
$postArr = array (
'account' => $user,
'password' => $pass,
'phone' => $number,
'msg' => urlencode($cont)
);
$result = $this->postHTTPS($this->sendurl,$postArr);
//$sendurl = $this->sendurl."sms?u=".$user."&p=".$pass."&m=".$number."&c=".urlencode($cont);
//$result =file_get_contents($sendurl);
$res = json_decode($result);
if($res->code !="0"){
return $res->code;
}else{
return 0;
}
return 0;
// $nowdate = date("YmdHis");
// $data = array(
// 'accountSid' => C('cfg_smssid'),
// 'smsContent' => $cont,
// 'to' => $number,
// 'timestamp' => $nowdate,
// 'sig' => md5(C('cfg_smssid').C('cfg_smstoken').$nowdate)
// );
// $res = $this->postHTTPS($this->sendurl,$data);
// $res = json_decode($res);
// if($res->respCode != "00000"){
// return $res->respCode;
// }
// return 0;
}
private function postHTTPS($url,$postFields) {
$postFields = json_encode($postFields);
$ch = curl_init ();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json; charset=utf-8' //json版本需要填写 Content-Type: application/json;
)
);
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_POST, 1 );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $postFields);
curl_setopt( $ch, CURLOPT_TIMEOUT,60);
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0);
$ret = curl_exec ( $ch );
if (false == $ret) {
$result = curl_error( $ch);
} else {
$rsp = curl_getinfo( $ch, CURLINFO_HTTP_CODE);
if (200 != $rsp) {
$result = "请求状态 ". $rsp . " " . curl_error($ch);
} else {
$result = $ret;
}
}
curl_close ( $ch );
return $result;
}
}