|
@@ -6,6 +6,16 @@
|
|
|
* Date: 2016/4/15
|
|
|
* Time: 16:27
|
|
|
*/
|
|
|
+
|
|
|
+// 发送类型,安卓还是ios
|
|
|
+class platform_type extends SplEnum
|
|
|
+{
|
|
|
+ const __default = self::unicast;
|
|
|
+ const android = 1;
|
|
|
+ const ios = 2;
|
|
|
+}
|
|
|
+
|
|
|
+// 消息类型
|
|
|
class msg_type extends SplEnum
|
|
|
{
|
|
|
const __default = self::unicast;
|
|
@@ -19,6 +29,19 @@ class msg_type extends SplEnum
|
|
|
const file_id = "file_id";
|
|
|
}
|
|
|
|
|
|
+class status_code extends SplEnum
|
|
|
+{
|
|
|
+ const __default = self::OK;
|
|
|
+ const OK = 200;
|
|
|
+ const CREATED = 201;
|
|
|
+ const ACCEPTED = 202;
|
|
|
+ const BAD_REQUEST = 400;
|
|
|
+ const UNAUTHORIZED = 401;
|
|
|
+ const FORBIDDEN = 403;
|
|
|
+ const NOT_FOUND = 404;
|
|
|
+ const INTERNAL_SERVICE_ERROR = 500;
|
|
|
+}
|
|
|
+
|
|
|
class display_type extends SplEnum
|
|
|
{
|
|
|
const __default = self::notification;
|
|
@@ -26,7 +49,11 @@ class display_type extends SplEnum
|
|
|
const message = "message";
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+/**
|
|
|
+ * Class upush
|
|
|
+ *
|
|
|
+ * 友盟推送内容
|
|
|
+ */
|
|
|
class upush
|
|
|
{
|
|
|
const PUSH_URL = "http://msg.umeng.com/api/send";
|
|
@@ -34,11 +61,31 @@ class upush
|
|
|
const APP_MASTER_SECRET = "r6w2a8z9x8zonh7qmk8ds2fvypu02wpj";
|
|
|
const APPKEY = "5631efd4e0f55a8770000027";
|
|
|
|
|
|
+ private $platform;
|
|
|
+
|
|
|
+ private $type;
|
|
|
+ private $alias_type;
|
|
|
+ private $alias;
|
|
|
+ private $ticker;
|
|
|
+ private $title;
|
|
|
+ private $text;
|
|
|
+
|
|
|
public function __construct()
|
|
|
{
|
|
|
+ $platform = platform_type::android;
|
|
|
+ $type = msg_type::unicast;
|
|
|
+ $ticker = "ticker";
|
|
|
+ $title = "title";
|
|
|
+ $text = "text";
|
|
|
}
|
|
|
|
|
|
- // post 请求发送
|
|
|
+ /**
|
|
|
+ * post发送数据
|
|
|
+ *
|
|
|
+ * @param $url
|
|
|
+ * @param $data_string
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
public function http_post_data($url, $data_string)
|
|
|
{
|
|
|
$ch = curl_init();
|
|
@@ -57,6 +104,20 @@ class upush
|
|
|
return array($return_code, $return_content);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 生成签名
|
|
|
+ *
|
|
|
+ * @param $http_method
|
|
|
+ * @param $url
|
|
|
+ * @param $post_body
|
|
|
+ * @param $app_master_secret
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ private function make_sign($http_method, $url, $post_body, $app_master_secret)
|
|
|
+ {
|
|
|
+ return strtolower(md5($http_method . $url . json_encode($post_body) . $app_master_secret));
|
|
|
+ }
|
|
|
+
|
|
|
// android 打包
|
|
|
private function android_pack()
|
|
|
{
|
|
@@ -114,24 +175,27 @@ class upush
|
|
|
// ios 打包
|
|
|
private function ios_pack()
|
|
|
{
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- private function make_sign(){
|
|
|
-
|
|
|
- return strtolower(md5(self::METHOD.self::PUSH_URL.json_encode(self::android_pack()).self::APP_MASTER_SECRET));
|
|
|
- }
|
|
|
+// private function make_sign(){
|
|
|
+//
|
|
|
+// return strtolower(md5(self::METHOD.self::PUSH_URL.json_encode(self::android_pack()).self::APP_MASTER_SECRET));
|
|
|
+// return strtolower(md5($http_method . $url . json_encode($post_body) . $app_master_secret));
|
|
|
+// }
|
|
|
|
|
|
// android 推送
|
|
|
- public function android_push()
|
|
|
- {
|
|
|
-// $sign = strtolower(md5(self::METHOD.self::PUSH_URL.self::android_pack().self::APP_MASTER_SECRET,false));
|
|
|
- return $this->http_post_data(self::PUSH_URL.'?sign='.$this->make_sign(), json_encode(self::android_pack()));
|
|
|
- }
|
|
|
+// public function android_push()
|
|
|
+// {
|
|
|
+//// $sign = strtolower(md5(self::METHOD.self::PUSH_URL.self::android_pack().self::APP_MASTER_SECRET,false));
|
|
|
+// return $this->http_post_data(self::PUSH_URL.'?sign='.$this->make_sign(), json_encode(self::android_pack()));
|
|
|
+// }
|
|
|
|
|
|
// ios 推送
|
|
|
- public function ios_push()
|
|
|
+ public function android_push()
|
|
|
{
|
|
|
+ $pack_body = self::android_pack();
|
|
|
+ $url = self::PUSH_URL . '?sign=' . self::make_sign("POST", self::PUSH_URL, $pack_body, self::APP_MASTER_SECRET);
|
|
|
+ return $this->http_post_data($url, json_encode($pack_body));
|
|
|
|
|
|
}
|
|
|
|