PHP簡訊發送服務 youe簡訊企業服務

來源:互聯網
上載者:User

標籤: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簡訊企業服務

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.