|
@ -39,18 +39,17 @@ import com.ekexiu.operation.push.getui.NotificationMessage;
|
39
|
39
|
|
40
|
40
|
@Path("/push")
|
41
|
41
|
public class PushService {
|
42
|
|
private static final Logger log =LogFactory.getLog(PushService.class);
|
|
42
|
private static final Logger log = LogFactory.getLog(PushService.class);
|
43
|
43
|
|
44
|
44
|
private static Type RES_TYPE = new TypeReference<Map<String, Object>>() {
|
45
|
45
|
}.getType();
|
46
|
|
|
47
|
|
|
48
|
|
private static final MsgCondition android=new MsgCondition("phonetype",new String[]{"ANDROID"},1);
|
49
|
|
private static final MsgCondition ios=new MsgCondition("phonetype",new String[]{"IOS"},1);
|
50
|
|
|
51
|
|
private static final MsgCondition[] onlyAndroid = new MsgCondition[]{android};
|
52
|
|
|
53
|
|
private static final MsgCondition[] onlyIos = new MsgCondition[]{ios};
|
|
46
|
|
|
47
|
private static final MsgCondition android = new MsgCondition("phonetype", new String[] { "ANDROID" }, 1);
|
|
48
|
private static final MsgCondition ios = new MsgCondition("phonetype", new String[] { "IOS" }, 1);
|
|
49
|
|
|
50
|
private static final MsgCondition[] onlyAndroid = new MsgCondition[] { android };
|
|
51
|
|
|
52
|
private static final MsgCondition[] onlyIos = new MsgCondition[] { ios };
|
54
|
53
|
|
55
|
54
|
private static Map<String, String> CONTENT_TYPE = new HashMap<String, String>();
|
56
|
55
|
private static Map<String, String> TOKEN_MAP = new ConcurrentHashMap<String, String>();
|
|
@ -62,6 +61,8 @@ public class PushService {
|
62
|
61
|
private String appId = "TUdvbnxu1c97r6Fb6cUy57";
|
63
|
62
|
private int timeout = 0;
|
64
|
63
|
private boolean enable = false;
|
|
64
|
private String tokenUrl = "http://192.168.2.233/ajax/push/token";
|
|
65
|
private String lastLoadToken = null;
|
65
|
66
|
|
66
|
67
|
private String token = null;
|
67
|
68
|
private long lastBuildTime = 0;
|
|
@ -98,8 +99,6 @@ public class PushService {
|
98
|
99
|
this.timeout = timeout;
|
99
|
100
|
}
|
100
|
101
|
|
101
|
|
|
102
|
|
|
103
|
102
|
public boolean isEnable() {
|
104
|
103
|
return enable;
|
105
|
104
|
}
|
|
@ -125,22 +124,20 @@ public class PushService {
|
125
|
124
|
}
|
126
|
125
|
}
|
127
|
126
|
|
128
|
|
private void raiseGeTuiError(Object obj){
|
|
127
|
private void raiseGeTuiError(Object obj) {
|
129
|
128
|
String errMsg = null;
|
130
|
129
|
errMsg = ERR_MAP.get(obj);
|
131
|
130
|
if (errMsg == null)
|
132
|
131
|
errMsg = "其他错误";
|
133
|
132
|
throw new RuntimeException("调用用个推restApi,返回结果错误:" + obj + ":" + errMsg);
|
134
|
133
|
}
|
|
134
|
|
135
|
135
|
private void checkResult(Map<String, Object> ret) {
|
136
|
136
|
Object obj = ret.get("result");
|
137
|
|
if (!"ok".equals(obj)){
|
|
137
|
if (!"ok".equals(obj)) {
|
138
|
138
|
raiseGeTuiError(obj);
|
139
|
139
|
}
|
140
|
140
|
}
|
141
|
|
|
142
|
|
|
143
|
|
|
144
|
141
|
|
145
|
142
|
public String allocateRequesstId() {
|
146
|
143
|
UUID uuid = UUID.randomUUID();
|
|
@ -169,10 +166,60 @@ public class PushService {
|
169
|
166
|
}
|
170
|
167
|
|
171
|
168
|
public void refresh() {
|
172
|
|
if ((this.token != null) && ((System.currentTimeMillis() - this.lastBuildTime) < (24 * 60 * 60 * 1000 - 5000))) {
|
173
|
|
return;
|
|
169
|
if (this.enable) {
|
|
170
|
if ((this.token != null) && ((System.currentTimeMillis() - this.lastBuildTime) < (24 * 60 * 60 * 1000 - 5000))) {
|
|
171
|
return;
|
|
172
|
}
|
|
173
|
this.buildToken();
|
|
174
|
} else {
|
|
175
|
this.loadToken();
|
|
176
|
}
|
|
177
|
}
|
|
178
|
|
|
179
|
private void loadToken() {
|
|
180
|
if (this.tokenUrl != null) {
|
|
181
|
try {
|
|
182
|
HttpURLConnection connection = getConnection(this.tokenUrl);
|
|
183
|
connection.setRequestMethod("GET");
|
|
184
|
connection.setUseCaches(false);
|
|
185
|
int code = connection.getResponseCode();
|
|
186
|
if (code == 200) {
|
|
187
|
InputStream in = null;
|
|
188
|
byte[] resData = null;
|
|
189
|
try {
|
|
190
|
in = connection.getInputStream();
|
|
191
|
resData = IoUtil.readStream(in, false);
|
|
192
|
} finally {
|
|
193
|
if (null != in)
|
|
194
|
IoUtil.close(in);
|
|
195
|
}
|
|
196
|
Map<String, Object> map = JsonService.fromJson(new String(resData, ConstData.UTF8), RES_TYPE);
|
|
197
|
Object obj = map.get("data");
|
|
198
|
|
|
199
|
if (obj != null && obj instanceof String) {
|
|
200
|
if (obj.equals(this.lastLoadToken)) {
|
|
201
|
return;
|
|
202
|
}
|
|
203
|
String tokenResult = (String) obj;
|
|
204
|
int idx = tokenResult.indexOf("_");
|
|
205
|
if (idx > 0) {
|
|
206
|
this.updateToken(tokenResult.substring(0, idx), Integer.parseInt(tokenResult.substring(idx + 1)));
|
|
207
|
} else {
|
|
208
|
TOKEN_MAP.put("authtoken", tokenResult);
|
|
209
|
}
|
|
210
|
this.lastLoadToken = tokenResult;
|
|
211
|
}
|
|
212
|
}
|
|
213
|
} catch (Exception e) {
|
|
214
|
log.error("load token error", e);
|
|
215
|
}
|
174
|
216
|
}
|
175
|
|
if(enable) this.buildToken();
|
|
217
|
}
|
|
218
|
|
|
219
|
private void updateToken(String tk, int idx) {
|
|
220
|
int len = tk.length();
|
|
221
|
idx = len - idx;
|
|
222
|
TOKEN_MAP.put("authtoken", tk.substring(idx) + tk.substring(0, idx));
|
176
|
223
|
}
|
177
|
224
|
|
178
|
225
|
public Map<String, Object> post(String url, Map<String, String> header, byte[] data) throws IOException {
|
|
@ -240,83 +287,84 @@ public class PushService {
|
240
|
287
|
return false;
|
241
|
288
|
}
|
242
|
289
|
}
|
243
|
|
|
244
|
|
|
|
290
|
|
245
|
291
|
@Get
|
246
|
292
|
@Path("/token")
|
247
|
|
public String getToken(){
|
248
|
|
String ret = this.token;
|
249
|
|
if(ret!=null){
|
250
|
|
int len = ret.length();
|
251
|
|
Random random = new Random();
|
252
|
|
int idx = random.nextInt(len-1);
|
253
|
|
if(idx<1 || idx >=len){
|
254
|
|
return ret;
|
|
293
|
public String getToken() {
|
|
294
|
if (this.enable) {
|
|
295
|
String ret = this.token;
|
|
296
|
if (ret != null) {
|
|
297
|
int len = ret.length();
|
|
298
|
Random random = new Random();
|
|
299
|
int idx = random.nextInt(len - 1);
|
|
300
|
while (idx < 1 || idx >= len) {
|
|
301
|
idx = random.nextInt(len - 1);
|
|
302
|
}
|
|
303
|
return ret.substring(idx) + ret.substring(0, idx) + "_" + idx;
|
255
|
304
|
}
|
256
|
|
return ret.substring(idx)+ret.substring(0,idx)+"_"+idx;
|
257
|
305
|
}
|
258
|
306
|
return null;
|
259
|
307
|
}
|
260
|
|
|
|
308
|
|
261
|
309
|
@Path("/bindTags")
|
262
|
310
|
@Post
|
263
|
311
|
public boolean bindTags(String[] tags, String cid) {
|
264
|
312
|
String url = "https://restapi.getui.com/v1/" + this.appId + "/set_tags";
|
265
|
|
Map<String,Object> msg = new HashMap<String,Object>();
|
266
|
|
msg.put("cid",cid);
|
267
|
|
msg.put("tag_list",tags);
|
|
313
|
Map<String, Object> msg = new HashMap<String, Object>();
|
|
314
|
msg.put("cid", cid);
|
|
315
|
msg.put("tag_list", tags);
|
268
|
316
|
try {
|
269
|
317
|
Map<String, Object> ret = post(url, TOKEN_MAP, JsonService.toJson(msg).getBytes(ConstData.UTF8));
|
270
|
318
|
this.checkResult(ret);
|
271
|
319
|
return true;
|
272
|
320
|
} catch (IOException e) {
|
273
|
|
log.error("bind tags error:"+JsonService.toJson(msg), e);
|
|
321
|
log.error("bind tags error:" + JsonService.toJson(msg), e);
|
274
|
322
|
return false;
|
275
|
323
|
}
|
276
|
324
|
}
|
277
|
|
private Map<String,Object > createIosMessage(String title,String content,String payload){
|
278
|
|
Map<String,Object> ret = new HashMap<String,Object>();
|
279
|
|
Map<String,Object> message= new HashMap<String,Object>();
|
|
325
|
|
|
326
|
private Map<String, Object> createIosMessage(String title, String content, String payload) {
|
|
327
|
Map<String, Object> ret = new HashMap<String, Object>();
|
|
328
|
Map<String, Object> message = new HashMap<String, Object>();
|
280
|
329
|
ret.put("message", message);
|
281
|
|
message.put("appkey",this.appKey);
|
282
|
|
message.put("is_offline",true);
|
|
330
|
message.put("appkey", this.appKey);
|
|
331
|
message.put("is_offline", true);
|
283
|
332
|
message.put("msgtype", "transmission");
|
284
|
|
Map<String,Object> transmission = new HashMap<String,Object>();
|
|
333
|
Map<String, Object> transmission = new HashMap<String, Object>();
|
285
|
334
|
ret.put("transmission", transmission);
|
286
|
335
|
transmission.put("transmission_type", false);
|
287
|
336
|
transmission.put("transmission_content", payload);
|
288
|
|
Map<String,Object> pushInfo = new HashMap<String,Object>();
|
|
337
|
Map<String, Object> pushInfo = new HashMap<String, Object>();
|
289
|
338
|
ret.put("push_info", pushInfo);
|
290
|
|
Map<String,Object> aps = new HashMap<String,Object>();
|
291
|
|
pushInfo.put("aps",aps);
|
292
|
|
Map<String,Object> alert = new HashMap<String,Object>();
|
|
339
|
Map<String, Object> aps = new HashMap<String, Object>();
|
|
340
|
pushInfo.put("aps", aps);
|
|
341
|
Map<String, Object> alert = new HashMap<String, Object>();
|
293
|
342
|
aps.put("alert", alert);
|
294
|
343
|
alert.put("title", title);
|
295
|
|
alert.put("body",content);
|
296
|
|
aps.put("autoBadge","+1");
|
297
|
|
aps.put("content-available",1);
|
298
|
|
aps.put("sound","default");
|
299
|
|
pushInfo.put("payload",payload);
|
|
344
|
alert.put("body", content);
|
|
345
|
aps.put("autoBadge", "+1");
|
|
346
|
aps.put("content-available", 1);
|
|
347
|
aps.put("sound", "default");
|
|
348
|
pushInfo.put("payload", payload);
|
300
|
349
|
ret.put("condition", onlyIos);
|
301
|
|
return ret;
|
|
350
|
return ret;
|
302
|
351
|
}
|
303
|
352
|
|
304
|
|
|
305
|
|
private Map<String,Object > createAndriodMessage(String title,String content,String payload){
|
306
|
|
Map<String,Object> ret = new HashMap<String,Object>();
|
|
353
|
private Map<String, Object> createAndriodMessage(String title, String content, String payload) {
|
|
354
|
Map<String, Object> ret = new HashMap<String, Object>();
|
307
|
355
|
Message message = new Message();
|
308
|
356
|
ret.put("message", message);
|
309
|
357
|
message.setAppKey(this.appKey);
|
310
|
358
|
message.setMsgtype("notification");
|
311
|
359
|
message.setOffline(true);
|
312
|
|
message.setOfflineExpireTime(2*60*1000);
|
|
360
|
message.setOfflineExpireTime(2 * 60 * 1000);
|
313
|
361
|
message.setPushNetworkType(0);
|
314
|
362
|
NotificationMessage notification = new NotificationMessage();
|
315
|
363
|
ret.put("notification", notification);
|
316
|
|
notification.setTransmissionType(true);
|
317
|
|
notification.setTransmissionContent(payload);
|
318
|
|
MsgStyle style = new MsgStyle();
|
319
|
|
notification.setStyle(style);
|
|
364
|
notification.setTransmissionType(true);
|
|
365
|
notification.setTransmissionContent(payload);
|
|
366
|
MsgStyle style = new MsgStyle();
|
|
367
|
notification.setStyle(style);
|
320
|
368
|
style.setType(0);
|
321
|
369
|
style.setClearable(true);
|
322
|
370
|
style.setRing(true);
|
|
@ -324,136 +372,135 @@ public class PushService {
|
324
|
372
|
style.setTitle(title);
|
325
|
373
|
style.setVibrate(true);
|
326
|
374
|
ret.put("condition", onlyAndroid);
|
327
|
|
return ret;
|
|
375
|
return ret;
|
328
|
376
|
}
|
329
|
|
|
330
|
377
|
|
331
|
|
|
332
|
|
public void toApp(String title,String content,Object payload){
|
333
|
|
String url = "https://restapi.getui.com/v1/"+this.appId+"/push_app";
|
|
378
|
public void toApp(String title, String content, Object payload) {
|
|
379
|
String url = "https://restapi.getui.com/v1/" + this.appId + "/push_app";
|
334
|
380
|
String pl_str = JsonService.toJson(payload);
|
335
|
|
Map<String,Object> andriodMessage = this.createAndriodMessage(title, content, pl_str);
|
336
|
|
Map<String,Object> iosMessage = this.createIosMessage(title, content, pl_str);
|
337
|
|
andriodMessage.put("requestid",this.allocateRequesstId());
|
338
|
|
iosMessage.put("requestid",this.allocateRequesstId());
|
339
|
|
|
|
381
|
Map<String, Object> andriodMessage = this.createAndriodMessage(title, content, pl_str);
|
|
382
|
Map<String, Object> iosMessage = this.createIosMessage(title, content, pl_str);
|
|
383
|
andriodMessage.put("requestid", this.allocateRequesstId());
|
|
384
|
iosMessage.put("requestid", this.allocateRequesstId());
|
|
385
|
|
340
|
386
|
try {
|
341
|
|
Map<String,Object> ret = post(url, TOKEN_MAP,JsonService.toJson(andriodMessage).getBytes(ConstData.UTF8));
|
|
387
|
Map<String, Object> ret = post(url, TOKEN_MAP, JsonService.toJson(andriodMessage).getBytes(ConstData.UTF8));
|
342
|
388
|
this.checkResult(ret);
|
343
|
389
|
} catch (Exception e) {
|
344
|
|
log.error("send app message error",e);
|
|
390
|
log.error("send app message error", e);
|
345
|
391
|
}
|
346
|
392
|
try {
|
347
|
|
Map<String,Object> ret = post(url, TOKEN_MAP,JsonService.toJson(iosMessage).getBytes(ConstData.UTF8));
|
|
393
|
Map<String, Object> ret = post(url, TOKEN_MAP, JsonService.toJson(iosMessage).getBytes(ConstData.UTF8));
|
348
|
394
|
this.checkResult(ret);
|
349
|
395
|
} catch (Exception e) {
|
350
|
|
log.error("send app message error",e);
|
|
396
|
log.error("send app message error", e);
|
351
|
397
|
}
|
352
|
398
|
}
|
353
|
|
private MsgCondition createTagCondition(String[] tags){
|
|
399
|
|
|
400
|
private MsgCondition createTagCondition(String[] tags) {
|
354
|
401
|
return new MsgCondition("tag", tags, 0);
|
355
|
402
|
}
|
356
|
|
private void addTag(Map<String,Object> msg,MsgCondition tagCondition){
|
|
403
|
|
|
404
|
private void addTag(Map<String, Object> msg, MsgCondition tagCondition) {
|
357
|
405
|
MsgCondition[] mcs = (MsgCondition[]) msg.get("condition");
|
358
|
|
MsgCondition[] mcsn = new MsgCondition[mcs.length+1];
|
359
|
|
System.arraycopy(mcs,0,mcsn, 0,mcs.length);
|
|
406
|
MsgCondition[] mcsn = new MsgCondition[mcs.length + 1];
|
|
407
|
System.arraycopy(mcs, 0, mcsn, 0, mcs.length);
|
360
|
408
|
mcsn[mcs.length] = tagCondition;
|
361
|
409
|
msg.put("condition", mcsn);
|
362
|
|
|
|
410
|
|
363
|
411
|
}
|
364
|
|
|
365
|
|
public void pushWithTag(String title,String content,Object payload,String[] tags){
|
366
|
|
String url = "https://restapi.getui.com/v1/"+this.appId+"/push_app";
|
|
412
|
|
|
413
|
public void pushWithTag(String title, String content, Object payload, String[] tags) {
|
|
414
|
String url = "https://restapi.getui.com/v1/" + this.appId + "/push_app";
|
367
|
415
|
String pl_str = JsonService.toJson(payload);
|
368
|
|
Map<String,Object> andriodMessage = this.createAndriodMessage(title, content, pl_str);
|
369
|
|
Map<String,Object> iosMessage = this.createIosMessage(title, content, pl_str);
|
370
|
|
andriodMessage.put("requestid",this.allocateRequesstId());
|
371
|
|
iosMessage.put("requestid",this.allocateRequesstId());
|
372
|
|
|
|
416
|
Map<String, Object> andriodMessage = this.createAndriodMessage(title, content, pl_str);
|
|
417
|
Map<String, Object> iosMessage = this.createIosMessage(title, content, pl_str);
|
|
418
|
andriodMessage.put("requestid", this.allocateRequesstId());
|
|
419
|
iosMessage.put("requestid", this.allocateRequesstId());
|
|
420
|
|
373
|
421
|
MsgCondition tagC = this.createTagCondition(tags);
|
374
|
422
|
addTag(andriodMessage, tagC);
|
375
|
423
|
addTag(iosMessage, tagC);
|
376
|
424
|
|
377
|
425
|
try {
|
378
|
|
Map<String,Object> ret = post(url, TOKEN_MAP,JsonService.toJson(andriodMessage).getBytes(ConstData.UTF8));
|
|
426
|
Map<String, Object> ret = post(url, TOKEN_MAP, JsonService.toJson(andriodMessage).getBytes(ConstData.UTF8));
|
379
|
427
|
this.checkResult(ret);
|
380
|
428
|
} catch (Exception e) {
|
381
|
|
log.error("send app message error",e);
|
|
429
|
log.error("send app message error", e);
|
382
|
430
|
}
|
383
|
431
|
try {
|
384
|
|
Map<String,Object> ret = post(url, TOKEN_MAP,JsonService.toJson(iosMessage).getBytes(ConstData.UTF8));
|
|
432
|
Map<String, Object> ret = post(url, TOKEN_MAP, JsonService.toJson(iosMessage).getBytes(ConstData.UTF8));
|
385
|
433
|
this.checkResult(ret);
|
386
|
434
|
} catch (Exception e) {
|
387
|
|
log.error("send app message error",e);
|
|
435
|
log.error("send app message error", e);
|
388
|
436
|
}
|
389
|
437
|
}
|
390
|
438
|
|
391
|
|
public void pushWithCid(String title,String content,Object payload,String cid){
|
392
|
|
String url = "https://restapi.getui.com/v1/"+this.appId+"/push_single";
|
|
439
|
public void pushWithCid(String title, String content, Object payload, String cid) {
|
|
440
|
String url = "https://restapi.getui.com/v1/" + this.appId + "/push_single";
|
393
|
441
|
String pl_str = JsonService.toJson(payload);
|
394
|
|
Map<String,Object> androidMessage = this.createAndriodMessage(title, content, pl_str);
|
395
|
|
Map<String,Object> iosMessage = this.createIosMessage(title, content, pl_str);
|
396
|
|
androidMessage.put("requestid",this.allocateRequesstId());
|
397
|
|
androidMessage.put("cid",cid);
|
398
|
|
iosMessage.put("requestid",this.allocateRequesstId());
|
399
|
|
iosMessage.put("cid",cid);
|
400
|
|
|
|
442
|
Map<String, Object> androidMessage = this.createAndriodMessage(title, content, pl_str);
|
|
443
|
Map<String, Object> iosMessage = this.createIosMessage(title, content, pl_str);
|
|
444
|
androidMessage.put("requestid", this.allocateRequesstId());
|
|
445
|
androidMessage.put("cid", cid);
|
|
446
|
iosMessage.put("requestid", this.allocateRequesstId());
|
|
447
|
iosMessage.put("cid", cid);
|
|
448
|
|
401
|
449
|
try {
|
402
|
|
Map<String,Object> ret = post(url, TOKEN_MAP,JsonService.toJson(androidMessage).getBytes(ConstData.UTF8));
|
|
450
|
Map<String, Object> ret = post(url, TOKEN_MAP, JsonService.toJson(androidMessage).getBytes(ConstData.UTF8));
|
403
|
451
|
this.checkResult(ret);
|
404
|
452
|
} catch (Exception e) {
|
405
|
|
log.error("send app message error",e);
|
|
453
|
log.error("send app message error", e);
|
406
|
454
|
}
|
407
|
455
|
try {
|
408
|
|
Map<String,Object> ret = post(url, TOKEN_MAP,JsonService.toJson(iosMessage).getBytes(ConstData.UTF8));
|
|
456
|
Map<String, Object> ret = post(url, TOKEN_MAP, JsonService.toJson(iosMessage).getBytes(ConstData.UTF8));
|
409
|
457
|
this.checkResult(ret);
|
410
|
458
|
} catch (Exception e) {
|
411
|
|
log.error("send app message error",e);
|
412
|
|
}
|
|
459
|
log.error("send app message error", e);
|
|
460
|
}
|
413
|
461
|
}
|
414
|
|
public void pushWithAlias(String title,String content,Object payload,String alias){
|
415
|
|
String url = "https://restapi.getui.com/v1/"+this.appId+"/push_single";
|
|
462
|
|
|
463
|
public void pushWithAlias(String title, String content, Object payload, String alias) {
|
|
464
|
String url = "https://restapi.getui.com/v1/" + this.appId + "/push_single";
|
416
|
465
|
String pl_str = JsonService.toJson(payload);
|
417
|
|
Map<String,Object> androidMessage = this.createAndriodMessage(title, content, pl_str);
|
418
|
|
Map<String,Object> iosMessage = this.createIosMessage(title, content, pl_str);
|
419
|
|
androidMessage.put("requestid",this.allocateRequesstId());
|
420
|
|
androidMessage.put("alias","A_"+alias);
|
421
|
|
iosMessage.put("requestid",this.allocateRequesstId());
|
422
|
|
iosMessage.put("alias","I_"+alias);
|
423
|
|
|
424
|
|
boolean sended = false;
|
|
466
|
Map<String, Object> androidMessage = this.createAndriodMessage(title, content, pl_str);
|
|
467
|
Map<String, Object> iosMessage = this.createIosMessage(title, content, pl_str);
|
|
468
|
androidMessage.put("requestid", this.allocateRequesstId());
|
|
469
|
androidMessage.put("alias", "A_" + alias);
|
|
470
|
iosMessage.put("requestid", this.allocateRequesstId());
|
|
471
|
iosMessage.put("alias", "I_" + alias);
|
|
472
|
|
|
473
|
boolean sended = false;
|
425
|
474
|
Object result = null;
|
426
|
|
Map<String,Object> ret = null;
|
|
475
|
Map<String, Object> ret = null;
|
427
|
476
|
try {
|
428
|
|
ret = post(url, TOKEN_MAP,JsonService.toJson(androidMessage).getBytes(ConstData.UTF8));
|
|
477
|
ret = post(url, TOKEN_MAP, JsonService.toJson(androidMessage).getBytes(ConstData.UTF8));
|
429
|
478
|
} catch (Exception e) {
|
430
|
|
log.error("send app message error",e);
|
|
479
|
log.error("send app message error", e);
|
431
|
480
|
}
|
432
|
481
|
result = ret.get("result");
|
433
|
|
if("ok".equals(result)){
|
434
|
|
sended=true;
|
435
|
|
}else if(!"alias_notbind".equals(result)){
|
|
482
|
if ("ok".equals(result)) {
|
|
483
|
sended = true;
|
|
484
|
} else if (!"alias_notbind".equals(result)) {
|
436
|
485
|
raiseGeTuiError(result);
|
437
|
486
|
}
|
438
|
487
|
try {
|
439
|
|
ret = post(url, TOKEN_MAP,JsonService.toJson(iosMessage).getBytes(ConstData.UTF8));
|
|
488
|
ret = post(url, TOKEN_MAP, JsonService.toJson(iosMessage).getBytes(ConstData.UTF8));
|
440
|
489
|
} catch (Exception e) {
|
441
|
|
log.error("send app message error",e);
|
|
490
|
log.error("send app message error", e);
|
442
|
491
|
}
|
443
|
492
|
result = ret.get("result");
|
444
|
|
if("ok".equals(result)){
|
|
493
|
if ("ok".equals(result)) {
|
445
|
494
|
return;
|
446
|
|
}else if("alias_notbind".equals(result)){
|
|
495
|
} else if ("alias_notbind".equals(result)) {
|
447
|
496
|
raiseGeTuiError("alias_notbind");
|
448
|
|
}else{
|
449
|
|
if(!sended){
|
|
497
|
} else {
|
|
498
|
if (!sended) {
|
450
|
499
|
raiseGeTuiError(result);
|
451
|
500
|
}
|
452
|
501
|
}
|
453
|
502
|
}
|
454
|
|
|
455
|
|
|
456
|
|
|
|
503
|
|
457
|
504
|
public static HttpURLConnection getConnection(String urlString) throws IOException {
|
458
|
505
|
URL url = new URL(urlString);
|
459
|
506
|
HttpURLConnection conn = null;
|
|
@ -537,26 +584,25 @@ public class PushService {
|
537
|
584
|
|
538
|
585
|
public static void main(String[] args) throws Exception {
|
539
|
586
|
PushService s = new PushService();
|
540
|
|
// s.buildToken();
|
541
|
|
// s.checkToken();
|
542
|
|
|
543
|
|
|
544
|
|
|
545
|
|
|
546
|
|
String t="44f123977f387165a8c2b77f83ce30ccad8be50a922a21a96976700dad3a5f61";
|
|
587
|
// s.buildToken();
|
|
588
|
// s.checkToken();
|
|
589
|
|
|
590
|
String t = "44f123977f387165a8c2b77f83ce30ccad8be50a922a21a96976700dad3a5f61";
|
547
|
591
|
int idx = 51;
|
548
|
592
|
int len = t.length();
|
549
|
|
idx = len-idx;
|
|
593
|
idx = len - idx;
|
550
|
594
|
System.out.println();
|
551
|
595
|
|
552
|
|
TOKEN_MAP.put("authtoken", t.substring(idx)+t.substring(0,idx));
|
553
|
|
long l = System.currentTimeMillis();
|
554
|
|
//s.toApp("title_" + l, "content_" + l, "payload_" + l);
|
555
|
|
s.pushWithAlias("title_" + l, "content_" + l, "payload_" + l,"1A21F6D7BD4C549A1A2ABC415DE7701BD");
|
556
|
|
// s.applyBadge(10, "f293af1f1cc043185ee9d921b63c4807", "9982595B6AAAE1EFABD0B40E215A76507E74D12477573491AF023B89807A01AA");
|
557
|
|
System.out.println(l);
|
|
596
|
TOKEN_MAP.put("authtoken", t.substring(idx) + t.substring(0, idx));
|
|
597
|
long l = System.currentTimeMillis();
|
|
598
|
// s.toApp("title_" + l, "content_" + l, "payload_" + l);
|
|
599
|
s.pushWithAlias("title_" + l, "content_" + l, "payload_" + l, "1A21F6D7BD4C549A1A2ABC415DE7701BD");
|
|
600
|
// s.applyBadge(10, "f293af1f1cc043185ee9d921b63c4807",
|
|
601
|
// "9982595B6AAAE1EFABD0B40E215A76507E74D12477573491AF023B89807A01AA");
|
|
602
|
System.out.println(l);
|
558
|
603
|
|
559
|
|
// s.applyBadge(1, "f293af1f1cc043185ee9d921b63c4807", "D380AD6865B61F4D179DBB208EE3C7268A672AB9821385050596608A186F6023");
|
|
604
|
// s.applyBadge(1, "f293af1f1cc043185ee9d921b63c4807",
|
|
605
|
// "D380AD6865B61F4D179DBB208EE3C7268A672AB9821385050596608A186F6023");
|
560
|
606
|
// for(int i = 0 ;i < 100;++i){
|
561
|
607
|
// UUID uuid= UUID.randomUUID();
|
562
|
608
|
// System.out.println( "A"+Long.toString(
|