国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > PHP > 正文

php短信接口代碼

2020-03-22 18:27:59
字體:
供稿:網(wǎng)友
本文實例為大家分享了幾個常用的php短信接口代碼,供大家參考,具體內(nèi)容如下1. 短信調(diào)用html' target='_blank'>class
* User: Administrator * Date: 2016/5/8 0008 * Time: 下午 2:36class Sms{
'send' = 'http://www.phpstudy.net/v1/send.json', 'send_batch' = 'http://www.phpstudy.net/v1/send_batch.json', 'status' = 'http://www.phpstudy.net/v1/status.json', private $_api_url = array( 'send' = 'http://www.phpstudy.net/v1/send.json', 'send_batch' = 'http://www.phpstudy.net/send_batch.json', 'status' = 'http://www.phpstudy.net/v1/status.json', * @param array $param 配置參數(shù) * api_key api秘鑰,在luosimao短信后臺短信- 觸發(fā)發(fā)送下面可查看 * use_ssl 啟用HTTPS地址,HTTPS有一定性能損耗,可選,默認(rèn)不啟用 public function __construct( $param = array() ){ if( !isset( $param['api_key'] ) ){ die("api key error."); if( isset( $param['api_key'] ) ){ $this- _api_key = $param['api_key']; if( isset( $param['use_ssl'] ) ){ $this- _use_ssl = $param['use_ssl']; //觸發(fā),單發(fā),適用于驗證碼,訂單觸發(fā)提醒類 public function send( $mobile , $message = '' ){ $api_url = !$this- _use_ssl $this- _api_url['send'] : $this- _ssl_api_url['send']; $param = array( 'mobile' = $mobile , 'message' = $message, $res = $this- http_post( $api_url ,$param ); return @json_decode( $res ,TRUE ); //批量發(fā)送,用于大批量發(fā)送 public function send_batch( $mobile_list = array() , $message = array() , $time = '' ){ $api_url = !$this- _use_ssl $this- _api_url['send_batch'] : $this- _ssl_api_url['send_batch']; $mobile_list = is_array( $mobile_list ) implode( ',' , $mobile_list ) : $mobile_list; $param = array( 'mobile_list' = $mobile_list , 'message' = $message, 'time' = $time, $res = $this- http_post( $api_url ,$param ); return @json_decode( $res ,TRUE ); //獲取短信賬號余額 public function get_deposit(){ $api_url = !$this- _use_ssl $this- _api_url['status'] : $this- _ssl_api_url['status']; $res = $this- http_get( $api_url ); return @json_decode( $res ,TRUE ); * @param string $type 接收類型,用于在服務(wù)器端接收上行和發(fā)送狀態(tài),接收地址需要在luosimao后臺設(shè)置 * @param array $param 傳入的參數(shù),從推送的url中獲取,官方文檔:http://luosimao.com/docs/api/ public function recv( $type = 'status' , $param = array() ){ if( $type == 'status' ){ if( $param['batch_id'] && $param['mobile'] && $param['status'] ){ //狀態(tài) // do record }elseif( $type == 'incoming' ){ //上行回復(fù) if( $param['mobile'] && $param['message'] ){ // do record * @param string $api_url 接口地址 * @param array $param post參數(shù) * @param int $timeout 超時時間 * @return bool private function http_post( $api_url = '' , $param = array() , $timeout = 5 ){ if( !$api_url ){ die("error api_url"); $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $api_url ); curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_0 ); curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt( $ch, CURLOPT_HEADER, FALSE); if( parse_url( $api_url )['scheme'] == 'https' ){ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST , FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER , FALSE); curl_setopt( $ch, CURLOPT_HTTPAUTH , CURLAUTH_BASIC); curl_setopt( $ch, CURLOPT_USERPWD , 'api:key-'.$this- _api_key ); curl_setopt( $ch, CURLOPT_POST, TRUE); curl_setopt( $ch, CURLOPT_POSTFIELDS, $param ); $res = curl_exec( $ch ); $error = curl_error( $ch ); curl_close( $ch ); if( $error ){ $this- _last_error[] = $error; return FALSE; return $res; * @param string $api_url 接口地址 * @param string $timeout 超時時間 * @return bool private function http_get( $api_url = '' , $timeout = '' ){ if( !$api_url ){ die("error api_url"); $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $api_url ); curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_0 ); curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt( $ch, CURLOPT_HEADER, FALSE); if( parse_url( $api_url )['scheme'] == 'https' ){ curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST , FALSE); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER , FALSE); curl_setopt( $ch, CURLOPT_HTTPAUTH , CURLAUTH_BASIC); curl_setopt( $ch, CURLOPT_USERPWD , 'api:key-'.$this- _api_key ); $res = curl_exec( $ch ); $error = curl_error( $ch ); curl_close( $ch ); if( $error ){ $this- _last_error[] = curl_error( $ch ); return FALSE; return $res; public function last_error(){ return $this- _last_error;2.短信發(fā)送示例
//send 單發(fā)接口require 'sms.php';$sms = new Sms( array('api_key' = '86f52f3ce0647dc24da53eafe29fadd4' , 'use_ssl' = FALSE ) );$res = $sms- send_batch( array('13761428268') , '驗證碼:19272【phpstudy】');if( $res ){ if( isset( $res['error'] ) && $res['error'] == 0 ){ echo 'success'; }else{ echo 'failed,code:'.$res['error'].',msg:'.$res['msg'];}else{ var_dump( $sms- last_error() );exit;
3.批量發(fā)送示例
require 'sms.php';$sms = new Sms( array('api_key' = '86f52f3ce0647dc24da53eafe29fadd4' , 'use_ssl' = FALSE ) );
//send 單發(fā)接口$res = $sms- send_batch( array('13761428268') , '驗證碼:19272【phpstudy】');if( $res ){ if( isset( $res['error'] ) && $res['error'] == 0 ){ echo 'success'; }else{ echo 'failed,code:'.$res['error'].',msg:'.$res['msg'];}else{ var_dump( $sms- last_error() );exit;4.獲取余額示例
//deposit 余額查詢require 'sms.php';$sms = new Sms( array('api_key' = '86f52f3ce0647dc24da53eafe29fadd4' , 'use_ssl' = FALSE ) );$res = $sms- get_deposit();if( $res ){ if( isset( $res['error'] ) && $res['error'] == 0 ){ echo 'desposit:'.$res['deposit']; }else{ echo 'failed,code:'.$res['error'].',msg:'.$res['msg'];}else{ var_dump( $sms- last_error() );exit;以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助。PHP教程

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 扎兰屯市| 双流县| 新沂市| 邳州市| 武陟县| 盐津县| 仲巴县| 稷山县| 南安市| 同德县| 安溪县| 芦山县| 成安县| 三门峡市| 东港市| 平湖市| 保山市| 石泉县| 上饶县| 普安县| 临夏市| 乌兰浩特市| 澎湖县| 哈巴河县| 舒兰市| 武鸣县| 张家口市| 特克斯县| 丹江口市| 博罗县| 涿州市| 从化市| 响水县| 龙泉市| 崇义县| 龙海市| 大化| 大洼县| 田林县| 开化县| 巫山县|