短信验证码、短信服务商接口---PHP---对接创蓝253云通讯平台
2018-02-07 17:27
555 查看
<?php
header("Content-type:text/html; charset=UTF-8");
class ChuanglanSmsApi {
//发送短信的接口地址
const API_SEND_URL='http://sms.253.com/msg/send?';
//查询余额的接口地址
constAPI_BALANCE_QUERY_URL='http://sms.253.com/msg/balance?';
const API_ACCOUNT='*******';//短信账号从 https://zz.253.com/site/login.html 里面获取。
const API_PASSWORD='*******';//短信密码从 from https://zz.253.com/site/login.html 里面获取。
/**
* 发送短信需要的接口参数
*
* @param string $mobile 手机号码
* @param string $msg 想要发送的短信内容
* @param string $needstatus 是否需要状态报告 '1'为需要 '0'位不需要。
*/
public function sendSMS( $mobile, $msg, $needstatus= 1) {
//发送短信的接口参数
$postArr = array (
'un' => self::API_ACCOUNT,
'pw' => self::API_PASSWORD,
'msg' => $msg,
'phone' => $mobile,
'rd' => $needstatus
);
$result =$this->curlPost( self::API_SEND_URL , $postArr);
return $result;
}
/**
*
*
* 查询余额
*/
public function queryBalance() {
// 查询接口参数
$postArr = array (
'un' => self::API_ACCOUNT,
'pw' => self::API_PASSWORD,
);
$result =$this->curlPost(self::API_BALANCE_QUERY_URL, $postArr);
return $result;
}
/**
* 处理接口返回值
*
*/
public function execResult($result){
$result=preg_split("/[,\r\n]/",$result);
return $result;
}
/**
* @param string $url
* @param array $postFields
* @return mixed
*/
private function curlPost($url,$postFields){
$postFields =http_build_query($postFields);
if(function_exists('curl_init')){
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_POST, 1 );
curl_setopt ( $ch, CURLOPT_HEADER, 0 );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $postFields );
$result = curl_exec ( $ch );
if(curl_errno($ch))
{
return 'Curl error: ' . curl_error($ch);
}
curl_close ( $ch );
}elseif(function_exists('file_get_contents')){
$result=file_get_contents($url.$postFields);
}
return $result;
}
//魔术获取
public function __get($name){
return $this->$name;
}
//魔术设置
public function __set($name,$value){
$this->$name=$value;
}
}
?>
如有缺漏,欢迎补充
header("Content-type:text/html; charset=UTF-8");
class ChuanglanSmsApi {
//发送短信的接口地址
const API_SEND_URL='http://sms.253.com/msg/send?';
//查询余额的接口地址
constAPI_BALANCE_QUERY_URL='http://sms.253.com/msg/balance?';
const API_ACCOUNT='*******';//短信账号从 https://zz.253.com/site/login.html 里面获取。
const API_PASSWORD='*******';//短信密码从 from https://zz.253.com/site/login.html 里面获取。
/**
* 发送短信需要的接口参数
*
* @param string $mobile 手机号码
* @param string $msg 想要发送的短信内容
* @param string $needstatus 是否需要状态报告 '1'为需要 '0'位不需要。
*/
public function sendSMS( $mobile, $msg, $needstatus= 1) {
//发送短信的接口参数
$postArr = array (
'un' => self::API_ACCOUNT,
'pw' => self::API_PASSWORD,
'msg' => $msg,
'phone' => $mobile,
'rd' => $needstatus
);
$result =$this->curlPost( self::API_SEND_URL , $postArr);
return $result;
}
/**
*
*
* 查询余额
*/
public function queryBalance() {
// 查询接口参数
$postArr = array (
'un' => self::API_ACCOUNT,
'pw' => self::API_PASSWORD,
);
$result =$this->curlPost(self::API_BALANCE_QUERY_URL, $postArr);
return $result;
}
/**
* 处理接口返回值
*
*/
public function execResult($result){
$result=preg_split("/[,\r\n]/",$result);
return $result;
}
/**
* @param string $url
* @param array $postFields
* @return mixed
*/
private function curlPost($url,$postFields){
$postFields =http_build_query($postFields);
if(function_exists('curl_init')){
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_POST, 1 );
curl_setopt ( $ch, CURLOPT_HEADER, 0 );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $postFields );
$result = curl_exec ( $ch );
if(curl_errno($ch))
{
return 'Curl error: ' . curl_error($ch);
}
curl_close ( $ch );
}elseif(function_exists('file_get_contents')){
$result=file_get_contents($url.$postFields);
}
return $result;
}
//魔术获取
public function __get($name){
return $this->$name;
}
//魔术设置
public function __set($name,$value){
$this->$name=$value;
}
}
?>
如有缺漏,欢迎补充
相关文章推荐
- PHP短信接口分享:适用于创蓝253平台下的短信验证码、短信服务接口
- Python---短信接口demo,对接创蓝253云通讯paas平台
- PHP下基于创蓝253接口的短信发送
- 创蓝253云通讯paas平台PHP短信接口demo分享
- C# 开发(创蓝253)手机短信验证码接口的实例
- C++短信接口demo:创蓝253平台下的短信验证码接口、短信营销接口
- C# 开发(创蓝253)手机短信验证码接口
- 手机验证码平台,怎么发送手机验证码,php开发手机验证码短信接口功能
- java的HttpClient4.5对接luosimao.com短信平台的短信接口
- 基于PHP的对接电子面单接口平台案例
- Python短信接口demo:创蓝253短信验证码接口、短信营销接口
- E php短信平台接口
- 短信平台-飞鸽传书云短信平台、短信平台-飞鸽传书云短信平台、专营短信接口、短信平台、短信软件、网关短信、短信网关、群发短信、短信api、短信验证码、短信群发,短信开发包!短信互联网加从飞鸽开始!专营短信接口、短信平台、短信软件、网关短信、短信网关、群发短信、短信api、短信验证码、短信群发,短信开发包!短信互联网加从飞鸽开始!
- 企信通PHP HTTP接口 发送短信
- ASP.NET后台手动调用POST提交并获取返回值 用于短信平台接口
- PHP 对接 支付宝 移动接口
- PHP-webservice 与C#对接 短信发送类
- 【工业串口和网络软件通讯平台(SuperIO)教程】八.SuperIO通讯机制与设备驱动对接的说明
- 天翼云开放平台短信接口php类
- uc.php接口调试,ucenter整合对接自己的系统的方法及Authracation has expiried原因