標籤:print mobile customer fputs mat short convert 發送 nec
/** * 通用簡訊平台HTTP介面POST方式傳送簡訊執行個體 * 返回字串 * 一般情況下調用此方法 */ function postSendMessage($msgContents,$phoneListStr){ //echo $phoneListStr.‘<br/>‘; $ShortMSGUid=‘123456‘;//簡訊服務 使用者名稱 $ShortMSGPwd=‘123456‘;//簡訊服務 密碼 $ShortMSGSignature=‘【簽名樣本】‘;//簡訊服務 簽名 //$CustomerServicePhoneList=array(‘185********‘,‘185********‘); //$phoneListStr = implode(‘;‘,$CustomerServicePhoneList); $url="http://www.smsadmin.cn/smsmarketing/wwwroot/api/post_send/"; //通用簡訊平台介面地址 $uid=$ShortMSGUid; //您在通用簡訊平台上註冊的使用者ID //$uid=mb_convert_encoding($uid,‘GB2312‘,‘UTF-8‘); //內容為UTF-8時轉碼成GB2312 $ShortMSGSignature = mb_convert_encoding($ShortMSGSignature,‘GB2312‘,‘UTF-8‘);//有漢字的時候要加上 $msgContents = mb_convert_encoding($msgContents,‘GB2312‘,‘UTF-8‘); $pwd=$ShortMSGPwd; //使用者密碼 $msg=$msgContents.$ShortMSGSignature;//【通用簡訊平台】"; //要發送的簡訊內容,必須要加簽名,簽名格式:【簽名內容】 //$msg=mb_convert_encoding($msg,‘GB2312‘,‘UTF-8‘); //內容為UTF-8時轉碼成GB2312 $mobile=$phoneListStr; //接收簡訊的手機號碼,多個手機號碼用英文下的分號(;)間隔,最多不能超過1000個手機號碼。 $params = array( "uid"=>$uid, "pwd"=>$pwd, "mobile"=>$mobile, "msg"=>$msg, "dtime"=>"", //為空白,表示立即傳送簡訊;寫入時間即為定時傳送簡訊時間,時間格式:0000-00-00 00:00:00 "linkid"=>"" //為空白,表示沒有流水號;寫入流水號,擷取狀態報表和簡訊回覆時返迴流水號,流水號格式要求:最大長度不能超過32位,數字、字母、數字字母組合的字串 ); $results = $this->posttohosts($url,$params); /* 提交成功傳回值格式: 0發送成功! */ } /** * 通過POST方式提交 */ function posttohosts($url, $data){ $url = parse_url($url); if (!$url) return "couldn‘t parse url"; if (!isset($url[‘port‘])) { $url[‘port‘] = ""; } if (!isset($url[‘query‘])) { $url[‘query‘] = ""; } $encoded = ""; while (list($k,$v) = each($data)){ $encoded .= ($encoded ? "&" : ""); $encoded .= rawurlencode($k)."=".rawurlencode($v); } //echo $encoded; $fp = fsockopen($url[‘host‘], $url[‘port‘] ? $url[‘port‘] : 80); if (!$fp) return "Failed to open socket to $url[host]"; fputs($fp, sprintf("POST %s%s%s HTTP/1.0\n", $url[‘path‘], $url[‘query‘] ? "?" : "", $url[‘query‘])); fputs($fp, "Host: $url[host]\n"); fputs($fp, "Content-type: application/x-www-form-urlencoded\n"); fputs($fp, "Content-length: " . strlen($encoded) . "\n"); fputs($fp, "Connection: close\n\n"); fputs($fp, "$encoded\n"); $line = fgets($fp,1024); if (!preg_match("{^HTTP/1\.. 200}", $line)) return; $results = ""; $inheader = 1; while(!feof($fp)){ $line = fgets($fp,1024); if ($inheader && ($line == "\n" || $line == "\r\n")){ $inheader = 0; }elseif (!$inheader){ $results .= $line; } } fclose($fp); return $results; }
PHP簡訊發送服務 youe簡訊企業服務