This example for you to share a few common PHP SMS interface code, for your reference, the specific content as follows
<?php/** * user:administrator * DATE:2016/5/8 0008 * Time: PM 2:36/class sms{//luosimao API Key pri
Vate $_api_key = ';
Private $_last_error = Array ();
Private $_use_ssl = FALSE; Private $_ssl_api_url = Array (' Send ' => ' Http://www.jb51.net/v1/send.json ', ' send_batch ' => ' http://www.)
Jb51.net/v1/send_batch.json ', ' status ' => ' Http://www.jb51.net/v1/status.json ',); Private $_api_url = Array (' Send ' => ' Http://www.jb51.net/v1/send.json ', ' send_batch ' => ' http://www.jb51
. Net/send_batch.json ', ' status ' => ' Http://www.jb51.net/v1/status.json ',); /** * @param array $param configuration parameters * Api_key API secret key, Luosimao SMS background SMS-> trigger send below can view * Use_ssl enable HTTPS address, HTTPS has a certain performance loss, optional, /Public Function __construct ($param = Array ()) {if (!isset ($param [' Api_key ']) is not enabled by default {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 ']; }//Trigger, single, applicable to verification code, order trigger reminder class 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); //Bulk send, for bulk send public function send_batch ($mobile _list = Array (), $message = Array (), $time = ') {$api _ur L = $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); }
//Get SMS Account balance Public Function get_deposit () {$api _url =! $this->_use_ssl? $this->_api_url[' status ': $this->_s
sl_api_url[' status '];
$res = $this->http_get ($api _url);
Return @json_decode ($res, TRUE); /** * @param string $type receive type, used to receive uplink and send status on the server side, the receiving address needs to be set in Luosimao background * @param array $param incoming parameters, obtained from the push URL, official FILE: https://luosimao.com/docs/api/*/Public Function recv ($type = ' status ', $param = Array ()) {if ($type = = ' St
ATUs ') {if ($param [' batch_id '] && $param [' Mobile '] && $param [' status ']] {//status/do record }}elseif ($type = = ' incoming ') {//Uplink reply if ($param [' Mobile '] && $param [' message ']) {/ Do record}}/** * @param string $api _url interface address * @param array $param post parameter * @param int $time Out 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 interface Address * @param string $timeout 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;
The Public Function Last_error () {return $this->_last_error; }
}
The above is the entire content of this article, I hope to help you learn.