destoon 短信发送函数及短信接口修改
//?$DT在common.inc.php中定義,?$CACHE = cache_read('module.php');?$DT = $CACHE['dt'];? 從緩存里讀取網站配置信息。
//$db?數據庫類,$DT 全局配置,$DT['sms']?開啟手機短信,$DT_TIME系統時間,$DT_IP 當前ip地址,$_username當前用戶
//DT_CLOUD_UID? DT_CLOUD_KEY 在common.inc.php 中定義?
//define('DT_CLOUD_UID', $CFG['cloud_uid']);?? //$CFG 加載根目錄下 config.inc.php?,所以短信發送接口用戶名和密碼在這里設置。新版dt在 后臺系統設置-》網站設置-》云服務 里設置。
//define('DT_CLOUD_KEY', $CFG['cloud_key']);??
//參數:$mobile手機號,$message發送內容,$word 字數,$time 時間function send_sms($mobile, $message, $word = 0, $time = 0) {global $db, $DT, $DT_TIME, $DT_IP, $_username; //開啟短信,設置了用戶名密碼,手機號合法,內容給不低于5個字符。if(!$DT['sms'] || !DT_CLOUD_UID || !DT_CLOUD_KEY || !is_mobile($mobile) || strlen($message) < 5) return false; $word or $word = word_count($message); //若沒有指定字數,則通過函數word_count計算字數 ,這個函數涉及mb_strlen,strlen的區別。$sms_message = convert($message, DT_CHARSET, 'UTF-8'); $data = 'sms_uid='.DT_CLOUD_UID.'&sms_key='.md5(DT_CLOUD_KEY.'|'.$mobile.'|'.md5 ($sms_message)).'&sms_charset='.DT_CHARSET.'&sms_mobile='.$mobile.'&sms_message='.rawurlencode($sms_message).'&sms_time='.$time;$header = "POST /send.php HTTP/1.0\r\n";$header .= "Accept: */*\r\n";$header .= "Content-Type: application/x-www-form-urlencoded\r\n";$header .= "Content-Length: ".strlen($data)."\r\n\r\n";$fp = function_exists('fsockopen') ? fsockopen('sms.destoon.com', 8820) : stream_socket_client('sms.destoon.com:8820');$code = '';if($fp) {fputs($fp, $header.$data);while(!feof($fp)) {$code .= fgets($fp, 1024);}fclose($fp);if($code && strpos($code, 'destoon_sms_code=') !== false) {$code = explode('destoon_sms_code=', $code);$code = $code[1];} else {$code = 'Can Not Connect SMS Server';}} else {$code = 'Can Not Connect SMS Server';}//記錄發送記錄$db->query("INSERT INTO {$db->pre}sms (mobile,message,word,editor,sendtime,code) VALUES ('$mobile','$message','$word','$_username','$DT_TIME','$code')");return $code; } View Code//mb_strlen,strlen的區別 http://developer.51cto.com/art/201105/263103.htm?
function word_count($string) {if(function_exists('mb_strlen')) return mb_strlen($string, DT_CHARSET);$string = convert($string, DT_CHARSET, 'gbk');$length = strlen($string);$count = 0;for($i = 0; $i < $length; $i++) {$t = ord($string[$i]);if($t > 127) $i++;$count++;}return $count; } View Code?
需要注意的是,mb_strlen并不是PHP核心函數,使用前需要確保在php.ini中加載了php_mbstring.dll,即確保“extension=php_mbstring.dll”這一行存在并且沒有被注釋掉,否則會出現未定義函 數的問題。
?
修改系統默認短信端口
global.func.php?? send_sms函數改成
?
/*** 通過CURL發送HTTP請求* @param string $url //請求URL* @param array $postFields //請求參數 * @return mixed*/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;}/*** 發送短信** @param string $mobile 手機號碼* @param string $msg 短信內容* @param string $needstatus 是否需要狀態報告* @param string $product 產品id,可選* @param string $extno 擴展碼,可選*/function send_sms($mobile,$msg,$word = 0,$time = 0,$needstatus = 'false',$extno = '') { global $db, $DT, $DT_TIME, $DT_IP, $_username;if(!$DT['sms'] || !DT_CLOUD_UID || !DT_CLOUD_KEY || !is_mobile($mobile) || strlen($msg) <3) return false;$word or $word = word_count($message);//創藍接口參數$postArr = array ('account' => DT_CLOUD_UID,'pswd' => DT_CLOUD_KEY,'msg' => $msg,'mobile' => $mobile,'needstatus' => $needstatus,'extno' => $extno);$url="http://222.73.117.156/msg/HttpBatchSendSM";$result =curlPost($url, $postArr);if($result){$arr=explode(',',$result);$result=$arr[1]==0?1:$arr[1]; //這個接口成功返回0 返回大于1代表錯誤 }$db->query("INSERT INTO {$db->pre}sms (mobile,message,word,editor,sendtime,code) VALUES ('$mobile','$message','$word','$_username','$DT_TIME','$result')");return $result;} View Code?
轉載于:https://www.cnblogs.com/djiz/p/6414255.html
總結
以上是生活随笔為你收集整理的destoon 短信发送函数及短信接口修改的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Mac下svn搭建和使用方法
- 下一篇: 数据结构入门之链表(C语言实现)