|
|
@ -1,16 +1,22 @@ |
|
|
|
package com.zscat.mallplus.unipush; |
|
|
|
|
|
|
|
import cn.hutool.json.JSONUtil; |
|
|
|
import com.getui.push.v2.sdk.ApiHelper; |
|
|
|
import com.getui.push.v2.sdk.GtApiConfiguration; |
|
|
|
import com.getui.push.v2.sdk.api.PushApi; |
|
|
|
import com.getui.push.v2.sdk.common.ApiResult; |
|
|
|
import com.getui.push.v2.sdk.dto.req.Audience; |
|
|
|
import com.getui.push.v2.sdk.dto.req.AudienceDTO; |
|
|
|
import com.getui.push.v2.sdk.dto.req.message.PushDTO; |
|
|
|
import com.getui.push.v2.sdk.dto.req.message.PushMessage; |
|
|
|
import com.getui.push.v2.sdk.dto.req.message.android.GTNotification; |
|
|
|
import com.getui.push.v2.sdk.dto.res.TaskIdDTO; |
|
|
|
import com.zscat.mallplus.ums.entity.SysMessage; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
@Component |
|
|
@ -130,9 +136,152 @@ public class UniPushService { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public void testlist() { |
|
|
|
String taskid = createMessageTaskaa(); |
|
|
|
AudienceDTO pdto = new AudienceDTO(); |
|
|
|
|
|
|
|
Audience audience = new Audience(); |
|
|
|
audience.addCid("89e286aee78d38faf748a690e603b1a3"); |
|
|
|
audience.addCid("e4a96929cc5f40c886cb517853356bc2"); |
|
|
|
|
|
|
|
pdto.setAudience(audience); |
|
|
|
pdto.setTaskid(taskid); |
|
|
|
|
|
|
|
ApiResult<Map<String, Map<String, String>>> mapApiResult = singlePushApi().pushListByCid(pdto); |
|
|
|
|
|
|
|
System.out.println(mapApiResult); |
|
|
|
} |
|
|
|
|
|
|
|
public String createMessageTaskaa() { |
|
|
|
PushDTO<Audience> pdto = new PushDTO<>(); |
|
|
|
pdto.setGroupName("群发消息"); |
|
|
|
|
|
|
|
|
|
|
|
PushMessage pushMessage = new PushMessage(); |
|
|
|
|
|
|
|
GTNotification notification = new GTNotification(); |
|
|
|
notification.setTitle("测试Titleaa"); |
|
|
|
notification.setBody("测试BodyXaa"); |
|
|
|
|
|
|
|
SysMessage msg = new SysMessage(); |
|
|
|
msg.setId(11); |
|
|
|
msg.setUserId(1); |
|
|
|
msg.setCode("云链助手"); |
|
|
|
msg.setParams("欢迎"); |
|
|
|
msg.setContent("欢迎注册汇融云链~"); |
|
|
|
msg.setCtime(System.currentTimeMillis()); |
|
|
|
|
|
|
|
// String payload = "{\"title\":\"lzh\",\"body\":\"liubody\",\"name\":\"hao\",\"userid\":101,\"msgtitle\":\"haha\"}";
|
|
|
|
String payload = JSONUtil.toJsonStr(msg); |
|
|
|
notification.setPayload(payload); |
|
|
|
notification.setClickType("payload"); |
|
|
|
|
|
|
|
pushMessage.setNotification(notification); |
|
|
|
|
|
|
|
pdto.setPushMessage(pushMessage); |
|
|
|
|
|
|
|
ApiResult<TaskIdDTO> msgg = this.singlePushApi().createMsg(pdto); |
|
|
|
System.out.println(msgg); |
|
|
|
return msgg.getData().getTaskId(); |
|
|
|
} |
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
new UniPushService().test(); |
|
|
|
List<String> clist = new ArrayList<>(); |
|
|
|
clist.add("079fb42d1f4f824a3defd471a432d0fe"); |
|
|
|
clist.add("89e286aee78d38faf748a690e603b1a3"); |
|
|
|
|
|
|
|
SysMessage msg = new SysMessage(); |
|
|
|
msg.setId(11); |
|
|
|
msg.setUserId(1); |
|
|
|
msg.setCode("交易物流"); |
|
|
|
msg.setParams("ABC"); |
|
|
|
msg.setContent("欢迎注册汇融云链~"); |
|
|
|
msg.setCtime(System.currentTimeMillis()); |
|
|
|
new UniPushService().sendPush(msg, clist); |
|
|
|
// new UniPushService().testlist();
|
|
|
|
} |
|
|
|
|
|
|
|
private static String imgUrltx = "http://mall.yyundong.com/tx.png"; |
|
|
|
private static String imgUrltz = "http://mall.yyundong.com/tz.png"; |
|
|
|
private static String imgUrlwl = "http://mall.yyundong.com/wl.png"; |
|
|
|
|
|
|
|
public void sendPush(SysMessage mess, List<String> cids) { |
|
|
|
String code = mess.getCode(); |
|
|
|
if ("系统消息".equals(code)) { |
|
|
|
sendTzMsg(mess); |
|
|
|
} else { |
|
|
|
sendUserMsg(mess, cids); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private void sendUserMsg(SysMessage mess, List<String> cids) { |
|
|
|
|
|
|
|
if (cids == null || cids.isEmpty()) |
|
|
|
return; |
|
|
|
|
|
|
|
String taskid = createMessageTask(mess); |
|
|
|
AudienceDTO pdto = new AudienceDTO(); |
|
|
|
|
|
|
|
Audience audience = new Audience(); |
|
|
|
cids.forEach(cid -> audience.addCid(cid)); |
|
|
|
|
|
|
|
pdto.setAudience(audience); |
|
|
|
pdto.setTaskid(taskid); |
|
|
|
|
|
|
|
ApiResult<Map<String, Map<String, String>>> mapApiResult = singlePushApi().pushListByCid(pdto); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private void sendTzMsg(SysMessage mess) { |
|
|
|
|
|
|
|
PushDTO<String> pd = new PushDTO<>(); |
|
|
|
pd.setRequestId("all" + System.currentTimeMillis()); |
|
|
|
pd.setGroupName("system_notice"); |
|
|
|
pd.setAudience("all"); |
|
|
|
|
|
|
|
pd.setPushMessage(createPushMessage(mess)); |
|
|
|
|
|
|
|
ApiResult<TaskIdDTO> taskIdDTOApiResult = singlePushApi().pushAll(pd); |
|
|
|
// System.out.println(taskIdDTOApiResult);
|
|
|
|
} |
|
|
|
|
|
|
|
private PushMessage createPushMessage(SysMessage mess) { |
|
|
|
|
|
|
|
String code = mess.getCode(); |
|
|
|
PushMessage pushMessage = new PushMessage(); |
|
|
|
|
|
|
|
GTNotification notification = new GTNotification(); |
|
|
|
// notification.setTitle(code);
|
|
|
|
// notification.setBody(mess.getParams());
|
|
|
|
notification.setTitle(mess.getParams()); |
|
|
|
notification.setBody(mess.getContent()); |
|
|
|
if ("交易物流".equals(code)) { |
|
|
|
notification.setLogoUrl(imgUrlwl); |
|
|
|
} else if ("云链助手".equals(code)) { |
|
|
|
notification.setLogoUrl(imgUrltx); |
|
|
|
} else { |
|
|
|
notification.setLogoUrl(imgUrltz); |
|
|
|
} |
|
|
|
String payload = JSONUtil.toJsonStr(mess); |
|
|
|
notification.setPayload(payload); |
|
|
|
notification.setClickType("payload"); |
|
|
|
// notification.setClickType("payload_custom");
|
|
|
|
|
|
|
|
pushMessage.setNotification(notification); |
|
|
|
|
|
|
|
return pushMessage; |
|
|
|
} |
|
|
|
|
|
|
|
private String createMessageTask(SysMessage mess) { |
|
|
|
PushDTO<Audience> pdto = new PushDTO<>(); |
|
|
|
pdto.setGroupName("tolist"); |
|
|
|
|
|
|
|
pdto.setPushMessage(createPushMessage(mess)); |
|
|
|
|
|
|
|
ApiResult<TaskIdDTO> result = this.singlePushApi().createMsg(pdto); |
|
|
|
// System.out.println(msgg);
|
|
|
|
return result.getData().getTaskId(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|