PHP SMS Interface code, PHP SMS Interface _php Tutorial

Source: Internet
Author: User

PHP SMS Interface code, PHP SMS interface


This example for everyone to share a few common PHP SMS interface code, for your reference, the specific content as follows

1. SMS Call class

<?php/** * User:administrator * DATE:2016/5/8 0008 * Time: PM 2:36 */class sms{//luosimao API Key Private $_api_   key = ";    Private $_last_error = Array ();   Private $_use_ssl = FALSE; Private $_ssl_api_url = Array (' send ' = ' http://www.bkjia.com/v1/send.json ', ' send_batch ' = ' http://www.b   Kjia.com/v1/send_batch.json ', ' status ' = ' Http://www.bkjia.com/v1/status.json ',); Private $_api_url = Array (' send ' = ' http://www.bkjia.com/v1/send.json ', ' send_batch ' = ' Http://www.bkjia   . Com/send_batch.json ', ' status ' = ' Http://www.bkjia.com/v1/status.json ',); /** * @param array $param configuration parameters * Api_key API Key, in Luosimao SMS background SMS-trigger send below can view * Use_ssl enable HTTPS address, HTTPS has a certain performance loss, optional, default does not Enable */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 ']; }}//Trigger, single, for verification code, order trigger alert 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 sending 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); }//Get SMS Account balance 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 receive type, used to receive upstream and send status on the server side, receive address needs in LUOSIMAO background settings * @param array $param incoming parameters, from the push URL, Official document: HT tps://luosimao.com/docs/api/*/Public Function recv ($type = ' status ', $param = Array ()) {if ($type = = ' status ')    {if ($param [' batch_id '] && $param [' Mobile '] && $param [' status ']) {//state//Do record}      }elseif ($type = = ' incoming ') {//Upstream reply if ($param [' Mobile '] && $param [' message ']) {//Do record }}}/** * @param string $api _url interface address * @param array $param post parameter * @param int $timeout Time Out * @return BOOL */Private Function http_post ($api _url = ", $param = Array (), $timeout = 5) {if (! $api _url) {die (" E    Rror 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 Time Out * @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. Sample SMS Sending

The Send single interface require ' sms.php '; $sms = new SMS (Array (' api_key ' = ' 86f52f3ce0647dc24da53eafe29fadd4 ', ' use_ssl ' = + F alse)); $res = $sms->send_batch (Array (' 13761428268 '), ' Captcha: 19272 "for" home "), 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. Bulk Send sample

Require ' sms.php '; $sms = new SMS (Array (' api_key ' = ' 86f52f3ce0647dc24da53eafe29fadd4 ', ' use_ssl ' = FALSE)); 
  //send Single Interface $res = $sms->send_batch (Array (' 13761428268 '), ' captcha: 19272 ' home for help '), 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. Example of obtaining balances

Deposit balance query 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 ' Despos It: '. $res [' Deposit '];  } else{    Echo ' Failed,code: '. $res [' Error ']. ', msg: '. $res [' msg '];}  } else{  var_dump ($sms->last_error ());} Exit

The above is the whole content of this article, I hope that everyone's study has helped.

http://www.bkjia.com/PHPjc/1127909.html www.bkjia.com true http://www.bkjia.com/PHPjc/1127909.html techarticle PHP SMS Interface code, PHP SMS interface This example for everyone to share a few common PHP SMS interface code for your reference, the specific content as follows 1. SMS Call class php/** * User ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.