PHP完全自学手册(珍藏版) 中文pdf扫描版下载
- <?php
 - class APICloud {
 - var $AppID = 'A6912326640236';
 - var $AppKey = '32B34156-5FDC-51CA-A970-41AD2067544A';
 - var $AppPath = 'https://p.apicloud.com/api/push/message/';
 - var $timeOut = 30;
 - function APICloud()
 - {
 - $this->headerInfo = array(
 - 'X-APICloud-AppId:'.$this->AppID,
 - 'X-APICloud-AppKey:'.$this->getSHAKey()
 - );
 - }
 - //毫秒
 - function getMilliSecond()
 - {
 - list($s1, $s2) = explode(' ', microtime());
 - return (float)sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000);
 - }
 - function getSHAKey()
 - {
 - $time = $this->getMilliSecond();
 - return sha1($this->AppID.'UZ'.$this->AppKey.'UZ'.$time).'.'.$time;
 - }
 - function push($data)
 - {
 - $ch = curl_init();
 - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
 - curl_setopt ($ch, CURLOPT_URL, $this->AppPath);
 - curl_setopt ($ch, CURLOPT_HTTPHEADER, $this->headerInfo);
 - curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
 - curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );
 - $result = curl_exec($ch);
 - curl_close($ch);
 - return $result;
 - }
 - }
 - //测试
 - $test = new APICloud();
 - $data = array (
 - 'title' => '测试标题',
 - 'content' => '测试内容',
 - 'type' => 1,
 - 'timer' => '',
 - 'platform' => 2,
 - 'groupName' => '',
 - );
 - print_r(json_decode($test->push($data)));
 
转载请注明:谷谷点程序 » apicloud php消息推送的方法