/*
*@api php对接短信接口 */
class ChuanglanSmsApi { /** * * * @param string $mobile * @param string $msg * @param string $needstatus * @param string $product * @param string $extno */ public function sendSMS( $mobile, $msg, $needstatus = 'false', $product = '', $extno = '') { global $chuanglan_config; // $postArr = array ( 'account' => $chuanglan_config['api_account'], 'pswd' => $chuanglan_config['api_password'], 'msg' => $msg, 'mobile' => $mobile, 'needstatus' => $needstatus, 'product' => $product, 'extno' => $extno ); $result = $this->curlPost( $chuanglan_config['api_send_url'] , $postArr); return $result; } /** * * * */ public function queryBalance() { global $chuanglan_config;
$postArr = array ( 'account' => $chuanglan_config['api_account'], 'pswd' => $chuanglan_config['api_password'], ); $result = $this->curlPost($chuanglan_config['api_balance_query_url'], $postArr); return $result; } /** * 处理返回值 * */ public function execResult($result){ $result=preg_split("/[,\r\n]/",$result); return $result; } /** * 通过CURL发送HTTP请求 * @param string $url //请求URL * @param array $postFields //请求参数 * @return mixed */ private function curlPost($url,$postFields){ $postFields = http_build_query($postFields); $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 ); curl_close ( $ch ); return $result; } //魔术获取 public function __get($name){ return $this->$name; } //魔术设置 public function __set($name,$value){
$this->$name=$value; } }
$api =new ChuanglanSmsApi();//调用api ?>
本文来源:https://www.wddqw.com/doc/23808789bd64783e09122bc7.html