方維團購系統默認的短信平臺是翼鋒短信平臺 和 企信通短信平臺 ,如今要添加一個雲短信平臺;php
整合後的雲短信平臺的代碼以下:
html
<?php /*-------------------------------- //add by 方維繫統程序員 ,wangtongphp , QQ:1006440989 INSERT INTO `fanwe_sms` VALUES ('22', 'Yun', '雲短信網', '', 'http://http.yunsms.cn/tx/', '****', '****', '', '0'); --------------------------------*/ include_once("Sms.class.php"); class YunSms implements Sms { public $message = ""; public $smsInfo; public $statusStr = array( "100" => "發送成功", "101" => "驗證失敗", "102" => "短信不足", "103" => "操做失敗", "104" => "非法字符", "105" => "內容過多", "106" => "號碼過多", "107" => "頻率過快", "108" => "號碼內容空", "109" => "帳號凍結", "110" => "禁止頻繁單條發送", "111" => "系統暫定發送", "112" => "有錯誤號碼", "113" => "定時時間不對", "114" => "帳號被鎖,10分鐘後登陸", "115" => "鏈接失敗", "116" => "禁止接口發送", "117" => "系統升級", ); public function __construct($smsInfo = '') { if(!empty($smsInfo)) { set_time_limit(0); $this->smsInfo = $smsInfo; } } public function sendSMS($mobiles=array(),$content,$sendTime='') { $mobileLen = 50; $mobileList = array_chunk($mobiles,$mobileLen); $content = a_utf8ToGB($content); $contentLen = mb_strlen($content,"GBK"); $smsTotalCount = ceil($contentLen / 70) * count($mobiles); $successNum = 0; $code = ''; foreach($mobileList as $mobileItem) { $mobile = implode(",",$mobileItem); //$http = 'http://http.c123.com/tx/'; $http = $this->smsInfo['server_url']; $data = array ( 'uid'=>$this->smsInfo['user_name'], //用戶帳號 'pwd'=>strtolower(md5($this->smsInfo['password'])), //MD5位32密碼 //'pwd'=>$this->smsInfo['password'], //MD5位32密碼 'mobile'=>$mobile, //號碼 'content'=>urlencode($content), //內容 //'encode'=>'utf8' ); $code= trim($this->postSMS($http,$data)); //POST方式提交 $smsLog['send_content'] = a_gbToUtf8($content);; $smsLog['action_message'] = $this->statusStr[$code]; $sendCount = count($mobileItem); if($code == "100") { $smsLog['success_mobiles'] = $mobile; $smsLog['fail_mobiles'] = ""; $smsLog['success_count'] = $sendCount; $smsLog['fail_count'] = 0; $smsLog['expense_count'] = ceil($contentLen / 70) * $sendCount; $successNum += $sendCount; } else { $smsLog['success_mobiles'] = ""; $smsLog['fail_mobiles'] = $mobile; $smsLog['success_count'] = 0; $smsLog['fail_count'] = $sendCount; $smsLog['expense_count'] = 0; } $smsLog['send_time'] = a_gmtTime(); if(intval(a_fanweC('SMS_SEND_LOG')) == 1) { $sql = "insert into ".$GLOBALS['db_config']['DB_PREFIX']."sms_send_log (class_name,send_content,success_count,success_mobiles,fail_mobiles,expense_count,fail_count,action_message,send_time) values('C123','".$smsLog['send_content']."','".$smsLog['success_count']."','".$smsLog['success_mobiles']."','".$smsLog['fail_mobiles']."','".$smsLog['expense_count']."','".$smsLog['fail_count']."','".$smsLog['action_message']."','".$smsLog['send_time']."')"; $GLOBALS['db']->query($sql); } } if(($code == "100" && count($mobiles) == 1) || ($smsTotalCount == $successNum)) { $this->message ="成功發送短信【".$content."】,到手機".implode(",",$mobiles); return 1; } else { $this->message = $smsTotalCount."條短信中,有".($smsTotalCount - $successNum)."條未成功發送到手機".implode(",",$mobiles); return 0; } } function postSMS($url,$data='') { $row = parse_url($url); $host = $row['host']; $port = $row['port'] ? $row['port']:80; $file = $row['path']; while (list($k,$v) = each($data)) { $post .= rawurlencode($k)."=".rawurlencode($v)."&"; //轉URL標準碼 } $post = substr( $post , 0 , -1 ); $len = strlen($post); $fp = @fsockopen( $host ,$port, $errno, $errstr, 10); if (!$fp) { return "$errstr ($errno)\n"; } else { $receive = ''; $out = "POST $file HTTP/1.1\r\n"; $out .= "Host: $host\r\n"; $out .= "Content-type: application/x-www-form-urlencoded\r\n"; $out .= "Connection: Close\r\n"; $out .= "Content-Length: $len\r\n\r\n"; $out .= $post; fwrite($fp, $out); while (!feof($fp)) { $receive .= fgets($fp, 128); } fclose($fp); $receive = explode("\r\n\r\n",$receive); unset($receive[0]); return implode("",$receive); } } } ?>
版權出自:http://www.cnblogs.com/wangtongphp/p/3287216.html ;博主QQ:1006440989程序員