-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.php
396 lines (362 loc) · 14.3 KB
/
demo.php
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
<?php
/**
* Created by PhpStorm.
* User: sxxxx
* Date: 2017/3/16
* Time: 16:48
*/
namespace getui;
use getuisdk\IGeTui;
use getuisdk\IGtAppMessage;
use getuisdk\IGtAPNPayload;
use getuisdk\IGtBaseTemplate;
use getuisdk\IGtBatch;
use getuisdk\IGtNotificationTemplate;
use getuisdk\DictionaryAlertMsg;
use getuisdk\IGtSingleMessage;
use getuisdk\IGtTarget;
use getuisdk\IGtTransmissionTemplate;
use getuisdk\IGtNotyPopLoadTemplate;
use getuisdk\IGtLinkTemplate;
use getuisdk\IGtListMessage;
use getuisdk\AppConditions;
class Getui
{
protected $host = 'http://sdk.open.api.igexin.com/apiex.htm';
//https的域名
//protected $host = 'https://api.getui.com/apiex.htm';
protected $appkey = 'appkey';
protected $appid = 'appid';
protected $mastersecret = 'mastersecret';
protected $cid = '';
protected $devivetoken = '';
protected $alias = '';
/**
* 通知透传模板
* @param $content string 透传内容
* @param $title string 通知栏标题
* @param $text string 通知栏内容
* @param $logoUrl string 通知栏logo
* @return IGtNotificationTemplate
*/
public function IGtNotificationTemplateDemo($content,$title,$text,$logoUrl){
$template = new IGtNotificationTemplate();
$template->setAppId($this->appid);//应用appid
$template->setAppKey($this->appkey);//应用appkey
$template->setTransmissionType(2);//透传消息类型
$template->setTransmissionContent($content);
$template->setTitle($title);
$template->setText($text);
$template->setLogo($logoUrl);
$template->setIsRing(true);//是否响铃
$template->setIsVibrate(true);//是否震动
$template->setIsClearable(true);//通知栏是否可清除
//$template->set_duration(BEGINTIME,ENDTIME); //设置ANDROID客户端在此时间区间内展示消息
//iOS推送需要设置的pushInfo字段
// $apn = new IGtAPNPayload();
// $apn->alertMsg = "alertMsg";
// $apn->badge = 11;
// $apn->actionLocKey = "启动";
// // $apn->category = "ACTIONABLE";
// // $apn->contentAvailable = 1;
// $apn->locKey = "通知栏内容";
// $apn->title = "通知栏标题";
// $apn->titleLocArgs = array("titleLocArgs");
// $apn->titleLocKey = "通知栏标题";
// $apn->body = "body";
// $apn->customMsg = array("payload"=>"payload");
// $apn->launchImage = "launchImage";
// $apn->locArgs = array("locArgs");
//
// $apn->sound=("test1.wav");;
// $template->set_apnInfo($apn);
return $template;
}
/**
* 透传模板
* @param $content
* @return IGtTransmissionTemplate
*/
public function IGtTransmissionTemplateDemo($content){
$template = new IGtTransmissionTemplate();
$template->setAppId($this->appid);//应用appid
$template->setAppkey($this->appkey);//应用appkey
$template->setTransmissionType(1);//透传消息类型
$template->setTransmissionContent($content);//透传内容
//$template->set_duration(BEGINTIME,ENDTIME); //设置ANDROID客户端在此时间区间内展示消息
//APN简单推送
//$template = new IGtAPNTemplate();
//$apn = new IGtAPNPayload();
//$alertmsg=new SimpleAlertMsg();
//$alertmsg->alertMsg="";
//$apn->alertMsg=$alertmsg;
//$apn->badge=2;
//$apn->sound="";
//$apn->add_customMsg("payload","payload");
//$apn->contentAvailable=1;
//$apn->category="ACTIONABLE";
//$template->set_apnInfo($apn);
//$message = new IGtSingleMessage();
//APN高级推送
$apn = new IGtAPNPayload();
$alertmsg=new DictionaryAlertMsg();
$alertmsg->body="body";
$alertmsg->actionLocKey="ActionLockey";
$alertmsg->locKey="LocKey";
$alertmsg->locArgs=array("locargs");
$alertmsg->launchImage="launchimage";
//IOS8.2 支持
$alertmsg->title="Title";
$alertmsg->titleLocKey="TitleLocKey";
$alertmsg->titleLocArgs=array("TitleLocArg");
$apn->alertMsg=$alertmsg;
$apn->badge=7;
$apn->sound="";
$apn->addCustomMsg("payload","payload");
$apn->contentAvailable=1;
$apn->category="ACTIONABLE";
$template->setApnInfo($apn);
//PushApn老方式传参
//$template = new IGtAPNTemplate();
//$template->setPushInfo("", 10, "", "com.gexin.ios.silence", "", "", "", "");
return $template;
}
/**
* 通知弹框下载模板
* @return IGtNotyPopLoadTemplate
*/
public function IGtNotyPopLoadTemplateDemo(){
$template = new IGtNotyPopLoadTemplate();
$template ->setAppId($this->appid);//应用appid
$template ->setAppkey($this->appkey);//应用appkey
//通知栏
$template ->setNotyTitle("个推");//通知栏标题
$template ->setNotyContent("个推最新版点击下载");//通知栏内容
$template ->setNotyIcon("");//通知栏logo
$template ->setIsBelled(true);//是否响铃
$template ->setIsVibrationed(true);//是否震动
$template ->setIsCleared(true);//通知栏是否可清除
//弹框
$template ->setPopTitle("弹框标题");//弹框标题
$template ->setPopContent("弹框内容");//弹框内容
$template ->setPopImage("");//弹框图片
$template ->setPopButton1("下载");//左键
$template ->setPopButton2("取消");//右键
//下载
$template ->setLoadIcon("");//弹框图片
$template ->setLoadTitle("地震速报下载");
$template ->setLoadUrl("http://dizhensubao.igexin.com/dl/com.ceic.apk");
$template ->setLsAutoInstall(false);
$template ->setLsActived(true);
//$template->set_duration(BEGINTIME,ENDTIME); //设置ANDROID客户端在此时间区间内展示消息
return $template;
}
/**
* 通知链接模板
* @param $title string 通知栏标题
* @param $content string 通知栏内容
* @param $logo string 通知栏logo
* @param $url string 打开连接地址
* @return IGtLinkTemplate
*/
public function IGtLinkTemplateDemo($title,$content,$logo,$url){
$template = new IGtLinkTemplate();
$template ->setAppId($this->appid);//应用appid
$template ->setAppkey($this->appkey);//应用appkey
$template ->setTitle($title);
$template ->setText($content);
$template ->setLogo($logo);
$template ->setIsRing(true);//是否响铃
$template ->setIsVibrate(true);//是否震动
$template ->setIsClearable(true);//通知栏是否可清除
$template ->setUrl($url);
//$template->set_duration(BEGINTIME,ENDTIME); //设置ANDROID客户端在此时间区间内展示消息
//iOS推送需要设置的pushInfo字段
// $apn = new IGtAPNPayload();
// $apn->alertMsg = "alertMsg";
// $apn->badge = 11;
// $apn->actionLocKey = "启动";
// // $apn->category = "ACTIONABLE";
// // $apn->contentAvailable = 1;
// $apn->locKey = "通知栏内容";
// $apn->title = "通知栏标题";
// $apn->titleLocArgs = array("titleLocArgs");
// $apn->titleLocKey = "通知栏标题";
// $apn->body = "body";
// $apn->customMsg = array("payload"=>"payload");
// $apn->launchImage = "launchImage";
// $apn->locArgs = array("locArgs");
//
// $apn->sound=("test1.wav");;
// $template->set_apnInfo($apn);
return $template;
}
/**
* 单推接口案例
* @param $clientId cid
* @param $template 模板
* @return bool
*/
public function pushMessageToSingle($clientId,$template){
$igt = new IGeTui($this->host,$this->appkey,$this->mastersecret);
//个推信息体
$message = new IGtSingleMessage();
$message->setIsOffline(true);//是否离线
$message->setOfflineExpireTime(3600*12*1000);//离线时间
$message->setData($template);//设置推送消息类型
//$message->set_PushNetWorkType(0);//设置是否根据WIFI推送消息,1为wifi推送,0为不限制推送
//接收方
$target = new IGtTarget();
$target->setAppId($this->appid);
$target->setClientId($clientId);
//$target->set_alias(Alias);
try {
$rep = $igt->pushMessageToSingle($message, $target);
return $rep;
}catch(RequestException $e){
$requstId =$e->getRequestId();
$rep = $igt->pushMessageToSingle($message, $target,$requstId);
return $rep;
}
}
/**
* 多推接口案例 对指定列表用户推送消息
* @param $template
* @param $clientId
* @param $toList
* @return \getuisdk\Array
*/
public function pushMessageToList($template,$clientId,$toList)
{
putenv("gexin_pushList_needDetails=true");
putenv("gexin_pushList_needAsync=true");
$igt = new IGeTui($this->host,$this->appkey,$this->mastersecret);
//个推信息体
$message = new IGtListMessage();
$message->setIsOffline(true);//是否离线
$message->setOfflineExpireTime(3600 * 12 * 1000);//离线时间
$message->setData($template);//设置推送消息类型
//$message->setPushNetWorkType(1); //设置是否根据WIFI推送消息,1为wifi推送,0为不限制推送
//$contentId = $igt->getContentId($message);
$contentId = $igt->getContentId($message,$toList); //根据TaskId设置组名,支持下划线,中文,英文,数字
//接收方1
$target1 = new IGtTarget();
$target1->setAppId($this->appid);
$target1->setClientId($clientId);
//$target1->set_alias(Alias);
//接收方2
$target2 = new IGtTarget();
$target2->setAppId($this->appid);
$target2->setClientId($clientId);
$targetList[0] = $target1;
$targetList[1] = $target2;
$rep = $igt->pushMessageToList($contentId, $targetList);
return $rep;
}
/**
* 群推接口案例
* @param $template
* @return mixed|null
*/
public function pushMessageToApp($template){
$igt = new IGeTui($this->host,$this->appkey,$this->mastersecret);
//$template = IGtTransmissionTemplateDemo();
//$template = IGtLinkTemplateDemo();
//个推信息体
//基于应用消息体
$message = new IGtAppMessage();
$message->setIsOffline(true);
$message->setOfflineExpireTime(10 * 60 * 1000);//离线时间单位为毫秒,例,两个小时离线为3600*1000*2
$message->setData($template);
$appIdList=array($this->appid);
$phoneTypeList=array('ANDROID');
$provinceList=array('浙江');
$tagList=array('标签');
//用户属性
//$age = array("0000", "0010");
$cdt = new AppConditions();
// $cdt->addCondition(AppConditions::PHONE_TYPE, $phoneTypeList);
// $cdt->addCondition(AppConditions::REGION, $provinceList);
$cdt->addCondition2(AppConditions::TAG, $tagList);
//$cdt->addCondition("age", $age);
$message->setAppIdList($appIdList);
$message->set_conditions($cdt->getCondition());
$rep = $igt->pushMessageToApp($message,"任务组名");
return $rep;
}
/**
* 批量单推功能
* @param $template
* @param $clientId
* @return mixed
*/
public function pushMessageToSingleBatch($template,$clientId)
{
putenv("gexin_pushSingleBatch_needAsync=false");
$igt = new IGeTui($this->host,$this->appkey,$this->mastersecret);
$batch = new IGtBatch($this->appkey, $igt);
$batch->setApiUrl($this->host);
//$igt->connect();
//消息模版:
// 1.TransmissionTemplate:透传功能模板
// 2.LinkTemplate:通知打开链接功能模板
// 3.NotificationTemplate:通知透传功能模板
// 4.NotyPopLoadTemplate:通知弹框下载功能模板
//个推信息体
$message = new IGtSingleMessage();
$message->setIsOffline(true);//是否离线
$message->setOfflineExpireTime(12 * 1000 * 3600);//离线时间
$message->setData($template);//设置推送消息类型
//$message->setPushNetWorkType(1);//设置是否根据WIFI推送消息,1为wifi推送,0为不限制推送
$target = new IGtTarget();
$target->setAppId($this->appid);
$target->setClientId($clientId);
$batch->add($message, $target);
try {
$rep = $batch->submit();
return $rep;
}catch(Exception $e){
$rep=$batch->retry();
return $rep;
}
}
/**
* 通过服务端设置ClientId的标签
* @param $clientId
* @param array $tagList
* @return bool
*/
public function setTag($clientId,array $tagList){
$igt = new IGeTui($this->host,$this->appkey,$this->mastersecret);
$rep = $igt->setClientTag($this->appid,$clientId,$tagList);
return $rep;
}
/**
* 获取ClientId的标签
* @param $clientId
* @param array $tagList
* @return mixed|null
*/
public function getUserTags($clientId,array $tagList) {
$igt = new IGeTui($this->host,$this->appkey,$this->mastersecret);
$rep = $igt->getUserTags($this->appid,$clientId,$tagList);
return $rep;
}
/**
* 用户状态查询
* @param $clientId
* @return mixed|null
*/
public function getUserStatus($clientId) {
$igt = new IGeTui($this->host,$this->appkey,$this->mastersecret);
$rep = $igt->getClientIdStatus($this->appid,$clientId);
return $rep;
}
/**
* 推送任务停止
*/
public function stoptask(){
$igt = new IGeTui($this->host,$this->appkey,$this->mastersecret);
$igt->stop("OSA-1127_QYZyBzTPWz5ioFAixENzs3");
}
}