先去个推官网下载个推服务端SDK
个推sdk
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105public function pushUserInfo($cid,$title,$msg) { // 这是基本参数配置 // uniapp push也可使用 $api = new GTClient("https://restapi.getui.com", "你的appkey", "你的appid", "你的masterSecret"); //设置推送参数 $push = new GTPushRequest(); //需要使用随机 ,不可重复 $push->setRequestId(md5(time() . mt_rand(1, 9999999))); $message = new GTPushMessage(); $notify = new GtNotification(); $notify->setTitle($title); $notify->setBody($msg); //消息通知的类型 $notify->setClickType('startapp'); $message->setNotification($notify); $push = $this->IGtNotificationTemplateDemo($title, $msg); $push->setPushMessage($message); //$userInfo里面只有一个cid是由前端生成的 $push->setCid($cid); //处理返回结果 $result = $api->pushApi()->pushToSingleByCid($push); } public function IGtNotificationTemplateDemo($title, $msg) { $push = new GTPushRequest(); $push->setRequestId($this->micro_time()); //设置setting $set = new GTSettings(); $set->setTtl(3600000); $strategy = new GTStrategy(); // 此处分为4个类型 // 1: 表示该消息在用户在线时推送个推通道,用户离线时推送厂商通道; 我使用的是1 // 2: 表示该消息只通过厂商通道策略下发,不考虑用户是否在线; // 3: 表示该消息只通过个推通道下发,不考虑用户是否在线; // 4: 表示该消息优先从厂商通道下发,若消息内容在厂商通道代发失败后会从个推通道下发。 $strategy->setDefault(GTStrategy::STRATEGY_GT_FIRST); $set->setStrategy($strategy); $push->setSettings($set); //厂商推送消息参数 $pushChannel = new GTPushChannel(); //ios $ios = new GTIos(); $ios->setType("notify"); $ios->setAutoBadge("1"); $ios->setPayload("ios_payload"); $ios->setApnsCollapseId("apnsCollapseId"); //aps设置 $aps = new GTAps(); $alert = new GTAlert(); $alert->setTitle($title); $alert->setBody($msg); $aps->setAlert($alert); $ios->setAps($aps); $multimedia = new GTMultimedia(); $multimedia->setUrl("url"); $multimedia->setType(1); $multimedia->setOnlyWifi(false); $multimedia2 = new GTMultimedia(); $multimedia2->setUrl("url2"); $multimedia2->setType(2); $multimedia2->setOnlyWifi(true); $ios->setMultimedia(array($multimedia)); $ios->addMultimedia($multimedia2); $pushChannel->setIos($ios); //安卓 $android = new GTAndroid(); $ups = new GTUps(); $thirdNotification = new GTThirdNotification(); $thirdNotification->setTitle($title); $thirdNotification->setBody($msg); // 和上面的方法中setClickType()的类型对应,一定要按照类型去写参数。下面有图,详细参考文档 // 消息通知的类型对应分别有 // CLICK_TYPE_INTENT = "intent"; // CLICK_TYPE_URL = "url"; // CLICK_TYPE_PAYLOAD = "payload"; // CLICK_TYPE_STAERAPP = "startapp"; // CLICK_TYPE_NONE = "none"; $thirdNotification->setClickType(GTThirdNotification::CLICK_TYPE_STAERAPP); $ups->setNotification($thirdNotification); $android->setUps($ups); $pushChannel->setAndroid($android); $push->setPushChannel($pushChannel); return $push; } public function micro_time() { list($usec, $sec) = explode(" ", microtime()); $time = ($sec . substr($usec, 2, 3)); return $time; }
详情可以去个推官网查看文档
个推官网
个推RestAPI V2 文档
最后
以上就是安详唇彩最近收集整理的关于PHP对接个推的全部内容,更多相关PHP对接个推内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复