|
- <?php
- namespace backend\common\push;
- //jpush.php �������ͷ��� �õ�curl��������
- class jpush
- {
- private $_masterSecret = '9f0dfe4da5893fb6065b1d08';
- private $_appkeys = '0fdf462e3c9d6ddaa525a4fd';
-
- /**
- * ���캯��
- * @param string $username
- * @param string $password
- * @param string $appkeys
- */
- function __construct($masterSecret = '', $appkeys = '')
- {
- $this->_masterSecret = $masterSecret;
- $this->_appkeys = $appkeys;
- }
-
- /**
- * ģ��post����url����
- * @param string $url
- * @param string $param
- */
- function request_post($url = '', $param = '')
- {
- 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
- 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;
- }
-
- /**
- * ����
- * @param int $sendno ���ͱ�š��ɿ������Լ�ά������ʶһ�η�������
- * @param int $receiver_type ���������͡�1��ָ���� IMEI����ʱ����ָ�� appKeys��2��ָ���� tag��3��ָ���� alias��4�� ��ָ�� appkey �������û�������Ϣ��
- * @param string $receiver_value ���ͷ�Χֵ���� receiver_type���Ӧ�� 1��IMEIֻ֧��һ�� 2��tag ֧�ֶ����ʹ�� "," ����� 3��alias ֧�ֶ����ʹ�� "," ����� 4������Ҫ��
- * @param int $msg_type ������Ϣ�����ͣ�1��֪ͨ 2���Զ�����Ϣ
- * @param string $msg_content ������Ϣ�����ݡ� �� msg_type ���Ӧ��ֵ
- * @param string $platform Ŀ���û��ն��ֻ��ƽ̨���ͣ��磺 android, ios �����ʹ�ö��ŷָ�
- */
- function send($sendno = 0, $receiver_type = 1, $receiver_value = '', $msg_type = 1, $msg_content = '', $platform = 'android')
- {
- $url = 'http://api.jpush.cn:8800/sendmsg/v2/sendmsg';
- $param = '';
- $param .= '&sendno=' . $sendno;
- $appkeys = $this->_appkeys;
- $param .= '&app_key=' . $appkeys;
- $param .= '&receiver_type=' . $receiver_type;
- $param .= '&receiver_value=' . $receiver_value;
- $masterSecret = $this->_masterSecret;
- $verification_code = md5($sendno . $receiver_type . $receiver_value . $masterSecret);
- $param .= '&verification_code=' . $verification_code;
- $param .= '&msg_type=' . $msg_type;
- $param .= '&msg_content=' . $msg_content;
- $param .= '&platform=' . $platform;
- $res = $this->request_post($url, $param);
-
-
- if ($res === false) {
- return false;
- }
- $res_arr = json_decode($res, true);
- return $res_arr;
- }
-
- }
-
- ?>
|