|
@ -57,7 +57,6 @@ public class PushService {
|
57
|
57
|
private static Map<String, String> ERR_MAP = new HashMap<String, String>();
|
58
|
58
|
|
59
|
59
|
final static char[] digits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
|
60
|
|
// UiIGJTfKNR8oXb8apYdGh3
|
61
|
60
|
private String secret = "U96j677DHoA1Pv5X0mxMU9";
|
62
|
61
|
private String appKey = "48nq7d7yHu8dgbzVHuisp6";
|
63
|
62
|
private String appId = "TUdvbnxu1c97r6Fb6cUy57";
|
|
@ -126,24 +125,22 @@ public class PushService {
|
126
|
125
|
}
|
127
|
126
|
}
|
128
|
127
|
|
129
|
|
private void checkResult(Map<String, Object> ret) {
|
130
|
|
Object obj = ret.get("result");
|
131
|
|
if ("ok".equals(obj))
|
132
|
|
return;
|
|
128
|
private void raiseGeTuiError(Object obj){
|
133
|
129
|
String errMsg = null;
|
134
|
130
|
errMsg = ERR_MAP.get(obj);
|
135
|
131
|
if (errMsg == null)
|
136
|
132
|
errMsg = "其他错误";
|
137
|
|
log.error("调用用个推restApi,返回结果错误:" + obj + ":" + errMsg);
|
138
|
133
|
throw new RuntimeException("调用用个推restApi,返回结果错误:" + obj + ":" + errMsg);
|
139
|
134
|
}
|
|
135
|
private void checkResult(Map<String, Object> ret) {
|
|
136
|
Object obj = ret.get("result");
|
|
137
|
if (!"ok".equals(obj)){
|
|
138
|
raiseGeTuiError(obj);
|
|
139
|
}
|
|
140
|
}
|
|
141
|
|
|
142
|
|
140
|
143
|
|
141
|
|
// private void checkToken() {
|
142
|
|
// if (this.token == null) {
|
143
|
|
// log.error("token is null");
|
144
|
|
// throw new RuntimeException("token is null");
|
145
|
|
// }
|
146
|
|
// }
|
147
|
144
|
|
148
|
145
|
public String allocateRequesstId() {
|
149
|
146
|
UUID uuid = UUID.randomUUID();
|
|
@ -277,22 +274,6 @@ public class PushService {
|
277
|
274
|
return false;
|
278
|
275
|
}
|
279
|
276
|
}
|
280
|
|
@Path("/applyBadge")
|
281
|
|
@Get
|
282
|
|
public void applyBadge(int badge,String cid,String devtoken){
|
283
|
|
String url = "https://restapi.getui.com/v1/" + this.appId + "/set_badge";
|
284
|
|
StringBuilder sb = new StringBuilder();
|
285
|
|
sb.append("{\"badge\":").append(badge).append(",\"cid_list\":[\"").append(cid).append("\"],\"devicetoken_list\":[\"").append(devtoken).append("\"]}");
|
286
|
|
System.out.println(sb.toString());
|
287
|
|
try {
|
288
|
|
Map<String, Object> ret = post(url, TOKEN_MAP, sb.toString().getBytes(ConstData.UTF8));
|
289
|
|
this.checkResult(ret);
|
290
|
|
} catch (IOException e) {
|
291
|
|
log.error("apply badge error[cid:" + cid + ",devtoken:" + devtoken + "]", e);
|
292
|
|
}
|
293
|
|
|
294
|
|
}
|
295
|
|
|
296
|
277
|
private Map<String,Object > createIosMessage(String title,String content,String payload){
|
297
|
278
|
Map<String,Object> ret = new HashMap<String,Object>();
|
298
|
279
|
Map<String,Object> message= new HashMap<String,Object>();
|
|
@ -356,8 +337,6 @@ public class PushService {
|
356
|
337
|
andriodMessage.put("requestid",this.allocateRequesstId());
|
357
|
338
|
iosMessage.put("requestid",this.allocateRequesstId());
|
358
|
339
|
|
359
|
|
// System.out.println(JsonService.toJson(andriodMessage));
|
360
|
|
// System.out.println(JsonService.toJson(iosMessage));
|
361
|
340
|
try {
|
362
|
341
|
Map<String,Object> ret = post(url, TOKEN_MAP,JsonService.toJson(andriodMessage).getBytes(ConstData.UTF8));
|
363
|
342
|
this.checkResult(ret);
|
|
@ -419,8 +398,6 @@ public class PushService {
|
419
|
398
|
iosMessage.put("requestid",this.allocateRequesstId());
|
420
|
399
|
iosMessage.put("cid",cid);
|
421
|
400
|
|
422
|
|
// System.out.println(JsonService.toJson(androidMessage));
|
423
|
|
// System.out.println(JsonService.toJson(iosMessage));
|
424
|
401
|
try {
|
425
|
402
|
Map<String,Object> ret = post(url, TOKEN_MAP,JsonService.toJson(androidMessage).getBytes(ConstData.UTF8));
|
426
|
403
|
this.checkResult(ret);
|
|
@ -444,20 +421,35 @@ public class PushService {
|
444
|
421
|
iosMessage.put("requestid",this.allocateRequesstId());
|
445
|
422
|
iosMessage.put("alias","I_"+alias);
|
446
|
423
|
|
447
|
|
// System.out.println(JsonService.toJson(androidMessage));
|
448
|
|
// System.out.println(JsonService.toJson(iosMessage));
|
|
424
|
boolean sended = false;
|
|
425
|
Object result = null;
|
|
426
|
Map<String,Object> ret = null;
|
449
|
427
|
try {
|
450
|
|
Map<String,Object> ret = post(url, TOKEN_MAP,JsonService.toJson(androidMessage).getBytes(ConstData.UTF8));
|
451
|
|
this.checkResult(ret);
|
|
428
|
ret = post(url, TOKEN_MAP,JsonService.toJson(androidMessage).getBytes(ConstData.UTF8));
|
452
|
429
|
} catch (Exception e) {
|
453
|
430
|
log.error("send app message error",e);
|
454
|
431
|
}
|
|
432
|
result = ret.get("result");
|
|
433
|
if("ok".equals(result)){
|
|
434
|
sended=true;
|
|
435
|
}else if(!"alias_notbind".equals(result)){
|
|
436
|
raiseGeTuiError(result);
|
|
437
|
}
|
455
|
438
|
try {
|
456
|
|
Map<String,Object> ret = post(url, TOKEN_MAP,JsonService.toJson(iosMessage).getBytes(ConstData.UTF8));
|
457
|
|
this.checkResult(ret);
|
|
439
|
ret = post(url, TOKEN_MAP,JsonService.toJson(iosMessage).getBytes(ConstData.UTF8));
|
458
|
440
|
} catch (Exception e) {
|
459
|
441
|
log.error("send app message error",e);
|
460
|
|
}
|
|
442
|
}
|
|
443
|
result = ret.get("result");
|
|
444
|
if("ok".equals(result)){
|
|
445
|
return;
|
|
446
|
}else if("alias_notbind".equals(result)){
|
|
447
|
raiseGeTuiError("alias_notbind");
|
|
448
|
}else{
|
|
449
|
if(!sended){
|
|
450
|
raiseGeTuiError(result);
|
|
451
|
}
|
|
452
|
}
|
461
|
453
|
}
|
462
|
454
|
|
463
|
455
|
|
|
@ -547,10 +539,21 @@ public class PushService {
|
547
|
539
|
PushService s = new PushService();
|
548
|
540
|
// s.buildToken();
|
549
|
541
|
// s.checkToken();
|
550
|
|
TOKEN_MAP.put("authtoken", "c3bbeb7aac006871f228d48e5da846933bfd2109e1d20fac3c8c0a3f3ccebd7d");
|
|
542
|
|
|
543
|
|
|
544
|
|
|
545
|
|
|
546
|
String t="44f123977f387165a8c2b77f83ce30ccad8be50a922a21a96976700dad3a5f61";
|
|
547
|
int idx = 51;
|
|
548
|
int len = t.length();
|
|
549
|
idx = len-idx;
|
|
550
|
System.out.println();
|
|
551
|
|
|
552
|
TOKEN_MAP.put("authtoken", t.substring(idx)+t.substring(0,idx));
|
551
|
553
|
long l = System.currentTimeMillis();
|
552
|
554
|
//s.toApp("title_" + l, "content_" + l, "payload_" + l);
|
553
|
|
s.pushWithAlias("title_" + l, "content_" + l, "payload_" + l,"A21F6D7BD4C549A1A2ABC415DE7701BD");
|
|
555
|
s.pushWithAlias("title_" + l, "content_" + l, "payload_" + l,"1A21F6D7BD4C549A1A2ABC415DE7701BD");
|
|
556
|
// s.applyBadge(10, "f293af1f1cc043185ee9d921b63c4807", "9982595B6AAAE1EFABD0B40E215A76507E74D12477573491AF023B89807A01AA");
|
554
|
557
|
System.out.println(l);
|
555
|
558
|
|
556
|
559
|
// s.applyBadge(1, "f293af1f1cc043185ee9d921b63c4807", "D380AD6865B61F4D179DBB208EE3C7268A672AB9821385050596608A186F6023");
|