class jpush { private $_mastersecret = ''; private $_appkeys = ''; function __construct($mastersecret = '',$appkeys = '') { $this->_mastersecret = $mastersecret; $this->_appkeys = $appkeys; } function request_post($url = '', $param = '',$header='') { if (empty($url) || empty($param)) { return false; } $posturl = $url; $curlpost = $param; $ch = curl_init();//初始化curl curl_setopt($ch, curlopt_url,$posturl);//抓取指定网页 curl_setopt($ch, curlopt_header, 0);//设置header $header && curl_setopt($ch, curlopt_httpheader, $header); curl_setopt($ch, curlopt_returntransfer, 1);//要求结果为字符串且输出到屏幕上 curl_setopt($ch, curlopt_post, 1);//post提交方式 curl_setopt($ch, curlopt_postfields, $curlpost); $data = curl_exec($ch);//运行curl curl_close($ch); return $data; } function send($platform = 'android,ios',$audience = 'all',$message = '', $notification = '', $options = '') { $url = 'https://api.jpush.cn/v3/push'; $base64_auth_string=base64_encode($this->_appkeys.':'.$this->_mastersecret); $header = array( 'content-type: application/json', 'authorization: basic '.$base64_auth_string ); $param = ''; $param .= '&platform='.$platform; $param .= '&audience='.$audience; $param .= '&message='.$message; $param .= '¬ification='.$notification; $param .= '&options='.$options; $res = $this->request_post($url, $param, $header); return $res; } }