|
|
@@ -0,0 +1,100 @@ |
|
|
|
package com.hp.user.service.utils; |
|
|
|
|
|
|
|
import com.gexin.rp.sdk.base.IPushResult; |
|
|
|
import com.gexin.rp.sdk.base.impl.ListMessage; |
|
|
|
import com.gexin.rp.sdk.base.impl.Target; |
|
|
|
import com.gexin.rp.sdk.http.IGtPush; |
|
|
|
import com.gexin.rp.sdk.template.NotificationTemplate; |
|
|
|
import com.gexin.rp.sdk.template.style.Style0; |
|
|
|
import com.hp.user.client.entity.DataResult; |
|
|
|
import com.hp.user.client.entity.Msg; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
public class PushMsgUtil { |
|
|
|
private static String appId = "lKmadzfZhH6ba89AyPR0q1"; |
|
|
|
private static String appKey = "464hjTzesi5wonBzifDEsA"; |
|
|
|
private static String masterSecret = "FASmZ3GxYj5jIlif9XdWT"; |
|
|
|
// 如果需要使用HTTPS,直接修改url即可 |
|
|
|
//private static String url = "https://api.getui.com/apiex.htm"; |
|
|
|
static String host = "http://api.getui.com/apiex.htm"; |
|
|
|
|
|
|
|
public DataResult<Map> pushMassage(Msg msg) { |
|
|
|
DataResult<Map> result = new DataResult<>(); |
|
|
|
try{ |
|
|
|
// 配置返回每个用户返回用户状态,可选 |
|
|
|
System.setProperty("gexin_pushList_needDetails", "true"); |
|
|
|
// 配置返回每个别名及其对应cid的用户状态,可选 |
|
|
|
// System.setProperty("gexin_pushList_needAliasDetails", "true"); |
|
|
|
IGtPush push = new IGtPush(host, appKey, masterSecret); |
|
|
|
// 通知透传模板 |
|
|
|
NotificationTemplate template = getNotificationTemplate(msg); |
|
|
|
ListMessage message = new ListMessage(); |
|
|
|
// 设置消息离线,并设置离线时间 |
|
|
|
message.setOffline(true); |
|
|
|
// 离线有效时间,单位为毫秒 |
|
|
|
message.setOfflineExpireTime(24 * 3600 * 1000); |
|
|
|
message.setData(template); |
|
|
|
// 可选,1为wifi,0为不限制网络环境。根据手机处于的网络情况,决定是否下发 |
|
|
|
message.setPushNetWorkType(0); |
|
|
|
// 厂商通道下发策略 |
|
|
|
message.setStrategyJson("{\"default\":4,\"ios\":4,\"st\":4}"); |
|
|
|
// 配置推送目标 |
|
|
|
List<Target> targets = new ArrayList<>(); |
|
|
|
Target target = null; |
|
|
|
if(msg.getClientIds()==null) { |
|
|
|
result.setCode("-1"); |
|
|
|
result.setMessage("clientIds不能为空"); |
|
|
|
return result; |
|
|
|
} |
|
|
|
for (String temp : msg.getClientIds()) { |
|
|
|
target = new Target(); |
|
|
|
target.setAppId(appId); |
|
|
|
target.setClientId(temp); |
|
|
|
targets.add(target); |
|
|
|
} |
|
|
|
// taskId用于在推送时去查找对应的message |
|
|
|
String taskId = push.getContentId(message); |
|
|
|
IPushResult ret = push.pushMessageToList(taskId, targets); |
|
|
|
result.setCode("0"); |
|
|
|
result.setData(ret.getResponse()); |
|
|
|
return result; |
|
|
|
}catch (Exception e){ |
|
|
|
result.setCode("-1"); |
|
|
|
result.setMessage("服务器异常"); |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private static NotificationTemplate getNotificationTemplate(Msg msg) { |
|
|
|
NotificationTemplate template = new NotificationTemplate(); |
|
|
|
// 设置APPID与APPKEY |
|
|
|
template.setAppId(appId); |
|
|
|
template.setAppkey(appKey); |
|
|
|
|
|
|
|
Style0 style = new Style0(); |
|
|
|
// 设置通知栏标题与内容 |
|
|
|
style.setTitle(msg.getTitle()); |
|
|
|
style.setText(msg.getText()); |
|
|
|
// 配置通知栏图标 |
|
|
|
style.setLogo(msg.getLogo()); |
|
|
|
// 配置通知栏网络图标 |
|
|
|
style.setLogoUrl(""); |
|
|
|
// 设置通知是否响铃,震动,或者可清除 |
|
|
|
style.setRing(true); |
|
|
|
style.setVibrate(true); |
|
|
|
style.setClearable(true); |
|
|
|
// style.setChannel("通知渠道id"); |
|
|
|
// style.setChannelName("通知渠道名称"); |
|
|
|
// style.setChannelLevel(3); //设置通知渠道重要性 |
|
|
|
template.setStyle(style); |
|
|
|
|
|
|
|
template.setTransmissionType(2); // 透传消息接受方式设置,1:立即启动APP,2:客户端收到消息后需要自行处理 |
|
|
|
template.setTransmissionContent(msg.getContent()); |
|
|
|
|
|
|
|
//template.setAPNInfo(getAPNPayload()); //详见【推送模板说明】iOS通知样式设置 |
|
|
|
return template; |
|
|
|
} |
|
|
|
} |