-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo.js
471 lines (415 loc) · 13.6 KB
/
demo.js
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
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
'use strict';
var GeTui = require('./GT.push');
var Target = require('./getui/Target');
var APNTemplate = require('./getui/template/APNTemplate');
var BaseTemplate = require('./getui/template/BaseTemplate');
var APNPayload = require('./payload/APNPayload');
var DictionaryAlertMsg = require('./payload/DictionaryAlertMsg');
var SimpleAlertMsg = require('./payload/SimpleAlertMsg');
var NotyPopLoadTemplate = require('./getui/template/NotyPopLoadTemplate');
var LinkTemplate = require('./getui/template/LinkTemplate');
var NotificationTemplate = require('./getui/template/NotificationTemplate');
var PopupTransmissionTemplate = require('./getui/template/PopupTransmissionTemplate');
var TransmissionTemplate = require('./getui/template/TransmissionTemplate');
var SingleMessage = require('./getui/message/SingleMessage');
var AppMessage = require('./getui/message/AppMessage');
var ListMessage = require('./getui/message/ListMessage');
// http的域名
var HOST = 'http://sdk.open.api.igexin.com/apiex.htm';
//https的域名
//var HOST = 'https://api.getui.com/apiex.htm';
//Android用户测试
var APPID = '';
var APPKEY = '';
var MASTERSECRET = '';
var CID = '';
//IOS用户测试
//var DEVICETOKEN='';
var alias='demo';
var gt = new GeTui(HOST, APPKEY, MASTERSECRET);
//pushAPN();
pushAPNL();
//getUserStatus();
//pushMessageToSingle();
//pushMessageToSingleBatch();
//pushMessageToList();
//pushMessageToApp();
//stoptask();
//setClientTag();
//getUserTags()
//别名绑定操作
//aliasBind();
//queryCID();
//queryAlias();
//aliasBatch();
//aliasUnBindAll();
//aliasUnBind();
//结果查询操作
//getPushResult();
//queryAppPushDataByDate();
//queryAppUserDataByDate();
//推送任务停止
function stoptask() {
gt.stop('OSA-1125_FBLl4mxYjG9eZzVR18edd8', function (err, res) {
console.log(res);
});
}
function setClientTag() {
gt.setClientTag(APPID, CID, ['aa','哔哔','》?》','!@#¥%……&*()'], function (err, res) {
console.log(res);
})
}
function getUserTags() {
gt.getUserTags(APPID, CID, function (err, res) {
console.log(res);
})
}
function getUserStatus() {
gt.getClientIdStatus(APPID, CID, function (err, res) {
console.log(res);
});
}
function pushAPN() {
//APN简单推送
//var template = new APNTemplate();
//var payload = new APNPayload();
//var alertMsg = new SimpleAlertMsg();
//alertMsg.alertMsg="AlertMsg";
//payload.alertMsg = alertMsg;
//payload.badge=5;
//payload.contentAvailable =1;
//payload.category="ACTIONABLE";
//payload.sound="test1.wav";
//payload.customMsg.payload1="payload";
//template.setApnInfo(payload);
//APN高级推送
var template = new APNTemplate();
var payload = new APNPayload();
var alertMsg = new DictionaryAlertMsg();
alertMsg.body = "";
alertMsg.actionLocKey = "";
alertMsg.locKey = "";
alertMsg.locArgs = Array("");
alertMsg.launchImage = "";
//ios8.2以上版本支持
alertMsg.title = "";
alertMsg.titleLocKey = "";
alertMsg.titleLocArgs = Array("");
// payload.alertMsg=alertMsg;
payload.badge=5;
// payload.contentAvailable =1;
// payload.category="";
// payload.sound="";
// payload.customMsg.payload1="payload";
template.setApnInfo(payload);
var message = new SingleMessage();
message.setData(template);
gt.pushAPNMessageToSingle(APPID, DEVICETOKEN, message, function (err, res) {
console.log(res);
});
}
function pushAPNL() {
//APN简单推送
var template = new APNTemplate();
var payload = new APNPayload();
var alertMsg = new SimpleAlertMsg();
alertMsg.alertMsg="AlertMsg";
payload.alertMsg=alertMsg;
payload.badge=5;
payload.contentAvailable =1;
payload.category="ACTIONABLE";
payload.sound="test1.wav";
payload.customMsg.payload="payload";
//payload.customMsg.payload1="payload1";
template.setApnInfo(payload);
//APN高级推送
//var template = new APNTemplate();
//var payload = new APNPayload();
//var alertMsg = new DictionaryAlertMsg();
//alertMsg.body = "body";
//alertMsg.actionLocKey = "actionLocKey";
//alertMsg.locKey = "locKey";
//alertMsg.locArgs = Array("locArgs","locArgs2");
//alertMsg.launchImage = "launchImage";
////ios8.2以上版本支持
//alertMsg.title = "title";
//alertMsg.titleLocKey = "titleLocKey";
//alertMsg.titleLocArgs = Array("titleLocArgs","titleLocArgs2");
//
//payload.alertMsg=alertMsg;
//payload.badge=50;
//payload.contentAvailable =1;
//payload.category="ACTIONABLE";
//payload.sound="";
//payload.customMsg.payload="payload";
//payload.customMsg.payload1="payload1";
//template.setApnInfo(payload);
var message = new ListMessage();
message.setData(template);
gt.getAPNContentId(APPID, message, function(err, res) {
var contentId = res;
gt.pushAPNMessageToList(APPID, contentId, [DEVICETOKEN], function (err, res) {
console.log(res);
});
})
}
function pushMessageToSingle() {
var template = TransmissionTemplateDemo();
// var template = LinkTemplateDemo();
// var template = NotificationTemplateDemo();
// var template = NotyPopLoadTemplateDemo();
//个推信息体
var message = new SingleMessage({
isOffline: true, //是否离线
offlineExpireTime: 3600 * 12 * 1000, //离线时间
data: template, //设置推送消息类型
pushNetWorkType:0 //是否wifi ,0不限,1wifi
});
//接收方
var target = new Target({
appId: APPID,
clientId: CID
// alias:'_lalala_'
});
//target.setAppId(APPID).setClientId(CID);
gt.pushMessageToSingle(message, target, function(err, res){
console.log(res);
if(err != null && err.exception != null && err.exception instanceof RequestError){
var requestId = err.exception.requestId;
console.log(err.exception.requestId);
gt.pushMessageToSingle(message,target,requestId,function(err, res){
console.log(err);
console.log(res);
});
}
});
}
function pushMessageToSingleBatch() {
process.env.gexin_pushSingleBatch_needAsync=true;
var Batch=gt.getBatch();
var template = TransmissionTemplateDemo();
// var template = LinkTemplateDemo();
// var template = NotificationTemplateDemo();
// var template = NotyPopLoadTemplateDemo();
//个推信息体
var message = new SingleMessage({
isOffline: true, //是否离线
offlineExpireTime: 3600 * 12 * 1000, //离线时间
data: template //设置推送消息类型
});
//接收方
var target = new Target({
appId: APPID,
clientId: CID
// alias:'_lalala_'
});
Batch.add(message,target);
Batch.submit(function (err, res) {
if(err != null){
Batch.retry(function (err, res) {
console.log("demo batch retry", res);
});
}
console.log("demo batch submit", res);
});
}
function pushMessageToList() {
//process.env.gexin_pushList_needDetails = true;
//process.env.gexin_pushList_needAsync=true;
//process.env.=true;
// var taskGroupName = 'test';
var taskGroupName = "toList任务组名";
var template = TransmissionTemplateDemo();
//个推信息体
var message = new ListMessage({
isOffline: false,
offlineExpireTime: 3600 * 12 * 1000,
data: template
});
gt.getContentId(message, taskGroupName, function (err, res) {
var contentId = res;
//接收方1
var target1 = new Target({
appId: APPID,
clientId: CID
// alias:'_lalala_'
});
var targetList = [target1];
// gt.needDetails = true;
console.log("getContentId", res);
gt.pushMessageToList(contentId, targetList, function (err, res) {
console.log(res);
});
});
}
function pushMessageToApp() {
// var taskGroupName = 'test';
var taskGroupName = null;
var template = TransmissionTemplateDemo();
//个推信息体
//基于应用消息体
var message = new AppMessage({
isOffline: false,
offlineExpireTime: 3600 * 12 * 1000,
data: template,
appIdList: [APPID],
// phoneTypeList: ['IOS'],
// provinceList: ['浙江'],
//tagList: ['阿百川']
speed: 10000
});
gt.pushMessageToApp(message, taskGroupName, function (err, res) {
console.log(res);
});
}
//消息模版:
// 1.TransmissionTemplate:透传功能模板
// 2.LinkTemplate:通知打开链接功能模板
// 3.NotificationTemplate:通知透传功能模板
// 4.NotyPopLoadTemplate:通知弹框下载功能模板
function NotyPopLoadTemplateDemo() {
var template = new NotyPopLoadTemplate({
appId: APPID,
appKey: APPKEY,
notyTitle: '个推',
notyContent: '个推最新版点击下载',
notyIcon: 'http://wwww.igetui.com/logo.png', // 通知栏logo
isRing: true,
isVibrate: true,
isClearable: true,
popTitle: '弹框标题',
setPopContent: '弹框内容',
popImage: '',
popButton1: '下载', // 左键
popButton2: '取消', // 右键
loadIcon: 'http://www.photophoto.cn/m23/086/010/0860100017.jpg', // 弹框图片
loadUrl: 'http://dizhensubao.igexin.com/dl/com.ceic.apk',
loadTitle: '地震速报下载',
autoInstall: false,
actived: true
});
return template;
}
function LinkTemplateDemo() {
var template = new LinkTemplate({
appId: APPID,
appKey: APPKEY,
title: '个推',
text: '个推最新版点击下载',
logo: 'http://wwww.igetui.com/logo.png',
logoUrl: 'https://www.baidu.com/img/bdlogo.png',
isRing: true,
isVibrate: true,
isClearable: true,
url: 'http://www.igetui.com'
});
return template;
}
function NotificationTemplateDemo() {
var template = new NotificationTemplate({
appId: APPID,
appKey: APPKEY,
title: '个推',
text: '个推最新版点击下载',
logo: 'http://www.igetui.com/logo.png',
isRing: true,
isVibrate: true,
isClearable: true,
transmissionType: 1,
transmissionContent: '测试离线'
});
return template;
}
function TransmissionTemplateDemo() {
var template = new TransmissionTemplate({
appId: APPID,
appKey: APPKEY,
transmissionType: 1,
transmissionContent: '测试离线'
});
//APN简单推送
//var payload = new APNPayload();
////var alertMsg = new SimpleAlertMsg();
////alertMsg.alertMsg="";
////payload.alertMsg = alertMsg;
//payload.badge=5;
//payload.contentAvailable =1;
//payload.category="";
//payload.sound="";
////payload.customMsg.payload1="";
//template.setApnInfo(payload);
//APN高级推送
//var payload = new APNPayload();
//var 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("titleLocArgs");
//
//payload.alertMsg=alertMsg;
//payload.badge=5;
// payload.contentAvailable =1;
// payload.category="";
// payload.sound="";
// payload.customMsg.payload1="payload";
// template.setApnInfo(payload);
return template;
}
function aliasBind() {
gt.bindAlias(APPID, alias, CID, function(err, res) {
console.log(res);
});
}
function aliasBatch() {
// var target = new Target()
// .setClientId(CID)
// .setAlias('_lalala_');
var target2 = new Target({
alias: alias,
clientId: CID
});
var targetList = [target2];
gt.bindAlias(APPID, targetList, function(err, res) {
console.log(res);
});
}
function queryCID() {
gt.queryClientId(APPID, alias, function(err, res) {
console.log(res);
});
}
function queryAlias() {
gt.queryAlias(APPID, CID, function(err, res) {
console.log(res);
});
}
function aliasUnBind() {
gt.unBindAlias(APPID, alias, CID, function(err, res) {
console.log(res);
});
}
function aliasUnBindAll() {
gt.unBindAlias(APPID, alias, function(err, res) {
console.log(res);
});
}
function queryAppPushDataByDate() {
gt.queryAppPushDataByDate(APPID, "20150910", function(err, res) {
console.log(res);
});
}
function queryAppUserDataByDate() {
gt.queryAppUserDataByDate(APPID, "20150910", function(err, res) {
console.log(res);
});
}
function getPushResult() {
gt.getPushResult("OSA-1125_FBLl4mxYjG9eZzVR18edd8", function(err, res) {
console.log(res);
});
}