用户工具

站点工具


差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

en:toaster:sample-code-of-web-interface-of-pns [2015/03/19 15:11]
cobub created
en:toaster:sample-code-of-web-interface-of-pns [2017/07/14 11:18]
行 1: 行 1:
-====== Sample Code of Web Interface of PNS ====== 
  
- 
-You can find the sample codes here invoking the web interface of PNS here. 
- 
-**Cobub @ github** 
- 
-You can find more code at [[https://​github.com/​cobub/​|github of Cobub]]. 
- 
-**PHP Samples** 
-<​code>​ 
- 
-if(isset($_POST["​serverurl"​]) && isset($_POST["​data"​]) ​ 
-&& isset($_POST["​appid"​]) && isset($_POST["​channel"​]) && isset($_POST["​expired"​])) 
-{ 
- $serverUrl = $_POST["​serverurl"​];​ //Get Server URL, configured in the Cobub Toaster configure file 
- $data = $_POST["​data"​];​ //Push content 
- $appid = $_POST["​appid"​];​ // APP ID 
- $channel = $_POST["​channel"​];​ // Which channel to push 
- $expired = $_POST["​expired"​];​ // expire timestamp of the notification 
-  
- $post = '​expired='​.$expired.'&​channel='​.$channel."&​appid="​.$appid."&​data="​.$data;​ 
- 
-       //​Construct the curl paramenters 
- $curl = curl_init ( $serverUrl ); 
- curl_setopt ( $curl, CURLOPT_HEADER,​ 0 ); 
- $header = array (); 
- $header [] = '​Connection:​ keep-alive';​ 
- $header [] = '​User-Agent:​ ozilla/5.0 (X11; Linux i686) AppleWebKit/​535.1 (KHTML, like Gecko) Chrome/​14.0.835.186 Safari/​535.1';​ 
- $header [] = '​Accept:​text/​html,​application/​xhtml+xml,​application/​xml;​q=0.9,​*/​*;​q=0.8';​ 
- $header [] = '​Accept-Language:​ zh-CN,​zh;​q=0.8';​ 
- $header [] = '​Accept-Charset:​ GBK,​utf-8;​q=0.7,​*;​q=0.3';​ 
- $header [] = '​Cache-Control:​max-age=0';​ 
- $header [] = '​Cookie:​t_skey=p5gdu1nrke856futitemkld661;​ t__CkCkey_=29f7d98';​ 
- $header [] = '​Content-Type:​application/​x-www-form-urlencoded';​ 
- curl_setopt($curl,​ CURLOPT_HTTPHEADER,​ array('​Expect:'​));​ 
- curl_setopt ( $curl, CURLOPT_HTTPHEADER,​ $header ); 
- curl_setopt ( $curl, CURLOPT_POST,​ 1); 
- curl_setopt($curl,​ CURLOPT_RETURNTRANSFER,​ 1); 
- curl_setopt ( $curl, CURLOPT_POSTFIELDS,​ $post ); 
-  
-    $result = curl_exec ( $curl ); //execute the curl method 
- curl_close ( $curl ); 
-} 
-</​code>​ 
en/toaster/sample-code-of-web-interface-of-pns.txt · 最后更改: 2017/07/14 11:18 (外部编辑)