用PHP實現飛信api介面發飛信簡訊

來源:互聯網
上載者:User

用PHP實現飛信api介面發飛信簡訊

不過這個不能和飛信用戶端同時登入,二者只能登一個,只要代碼在dw裡開啟,用戶端就掉了呵呵~~~

 

<?php  

/* 

 * Created on 2010-4-18 

 * MiaoPengFei 

 * To change the template for this generated file go to 

 * Window - Preferences - PHPeclipse - PHP - Code Templates 

 */  

    $data["username"] = ;//這裡填自己的手機號  

   $data["password"] = "";//這裡填飛信的密碼  

   $data["sendto"] = ;//這裡填收信人的號碼  

   $data["message"] = "沒事,這是我自己編的php代碼,發的簡訊哈哈!";//這裡填飛信簡訊內容  

 

    $curl = new Curl_Class();  

    $result = @$curl->post("http://sms.api.bz/fetion.php", $data);  

    echo $result; //返回資訊預設為UTF-8編碼的漢字,如果你的頁面編碼為gb2312,請使用下行語句輸出返回資訊。  

     //echo iconv("UTF-8", "GBK", $result);  

  

     //curl類  

     class Curl_Class  

     {  

    function Curl_Class()  

    {  

     return true;  

     }  

  

     function execute($method, $url, $fields = '', $userAgent = '', $httpHeaders = '', $username = '', $password = '')  

     {  

    $ch = Curl_Class::create();  

     if (false === $ch)  

     {  

     return false;  

     }  

  

     if (is_string($url) && strlen($url))  

     {  

     $ret = curl_setopt($ch, CURLOPT_URL, $url);  

    }  

    else  

     {  

    return false;  

     }  

     //是否顯示頭部資訊  

     curl_setopt($ch, CURLOPT_HEADER, false);  

   //  

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  

  

    if ($username != '')  

    {  

     curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);  

     }  

  

     $method = strtolower($method);  

     if ('post' == $method)  

    {  

     curl_setopt($ch, CURLOPT_POST, true);  

     if (is_array($fields))  

     {  

     $sets = array();  

     foreach ($fields AS $key => $val)  

     {  

     $sets[] = $key . '=' . urlencode($val);  

     }  

     $fields = implode('&',$sets);  

     }  

     curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);  

     }  

     else if ('put' == $method)  

     {  

     curl_setopt($ch, CURLOPT_PUT, true);  

     }  

  

     //curl_setopt($ch, CURLOPT_PROGRESS, true);  

     //curl_setopt($ch, CURLOPT_VERBOSE, true);  

     //curl_setopt($ch, CURLOPT_MUTE, false);  

     curl_setopt($ch, CURLOPT_TIMEOUT, 10);//設定curl逾時秒數  

  

     if (strlen($userAgent))  

     {  

     curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);  

     }  

  

     if (is_array($httpHeaders))  

     {  

     curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeaders);  

     }  

  

     $ret = curl_exec($ch);  

  

     if (curl_errno($ch))  

     {  

     curl_close($ch);  

     return array(curl_error($ch), curl_errno($ch));  

     }  

     else  

     {  

     curl_close($ch);  

     if (!is_string($ret) || !strlen($ret))  

     {  

     return false;  

     }  

     return $ret;  

    }  

     }  

  

     function post($url, $fields, $userAgent = '', $httpHeaders = '', $username = '', $password = '')  

     {  

     $ret = Curl_Class::execute('POST', $url, $fields, $userAgent, $httpHeaders, $username, $password);  

     if (false === $ret)  

     {  

     return false;  

     }  

  

     if (is_array($ret))  

     {  

     return false;  

     }  

     return $ret;  

     }  

     function get($url, $userAgent = '', $httpHeaders = '', $username = '', $password = '')  

    {  

    $ret = Curl_Class::execute('GET', $url, '', $userAgent, $httpHeaders, $username, $password);  

     if (false === $ret)  

     {  

     return false;  

    }  

  

     if (is_array($ret))  

    {  

     return false;  

    }  

    return $ret;  

     }  

  

    function create()  

     {  

     $ch = null;  

     if (!function_exists('curl_init'))  

     {  

     return false;  

     }  

     $ch = curl_init();  

     if (!is_resource($ch))  

     {  

     return false;  

     }  

    return $ch;  

     }  

  

   }  

?>  

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.