dfl
请教各位:java服务端 使用透传消息模板 推送消息,应用离线时,可以收到, 应用在线时收不到 这是什么问题?
public void PushtoSingle(PushInfo pushInfo){
IGtPush push = new IGtPush(config.getApiurl(),config.getAppKey(),config.getMasterSecret());
TransmissionTemplate template = getTransmissionTemplate(pushInfo);
SingleMessage message = new SingleMessage();
message.setOffline(true);
// 离线有效时间,单位为毫秒,可选
message.setOfflineExpireTime(24 * 3600 * 1000);
message.setData(template);
// 可选,1为wifi,0为不限制网络环境。根据手机处于的网络情况,决定是否下发
message.setPushNetWorkType(0);
Target target = new Target();
target.setAppId(config.getAppId());
target.setClientId(pushInfo.getClientId());
//target.setAlias(Alias);
IPushResult ret = null;
try {
ret = push.pushMessageToSingle(message, target);
} catch (RequestException e) {
e.printStackTrace();
ret = push.pushMessageToSingle(message, target, e.getRequestId());
}
if (ret != null) {
System.out.println(ret.getResponse().toString());
} else {
System.out.println("服务器响应异常");
}
}
public TransmissionTemplate getTransmissionTemplate(PushInfo pushInfo){
String payLoad="{\"title\":\""+pushInfo.getNotifyTitle()+"\",\"content\":\""+pushInfo.getNotityText()+"\",\"payload\":\"test\"}";
String intent="intent:#Intent;launchFlags=0x14000000;action=android.intent.action.oppopush;package=";
intent+= config.getPackageName();
intent+=";component=";
intent+= config.getPackageName();
intent+="/io.dcloud.PandoraEntry;";
intent+="S.UP-OL-SU=true;S.title=";
intent+=pushInfo.getNotifyTitle();
intent+=";S.content=";
intent+=pushInfo.getNotityText();
intent+=";S.payload=test;end";
TransmissionTemplate template = new TransmissionTemplate();
template.setAppId(config.getAppId());
template.setAppkey(config.getAppKey());
template.setTransmissionContent(pushInfo.getNotityText());
template.setTransmissionType(2);
Notify notify = new Notify();
notify.setTitle(pushInfo.getNotifyTitle());
notify.setContent(pushInfo.getNotityText());
notify.setIntent(intent);
notify.setType(GtReq.NotifyInfo.Type._intent);
notify.setPayload(payLoad);
// notify.setUrl("https://dev.getui.com/");
//notify.setType(Type._url);
template.set3rdNotifyInfo(notify);//设置第三方通知
return template;
}
2019-07-15 19:17
519 个评论
要回复文章请先登录或注册
老哥教教我
1***@qq.com
dfl
dfl
4***@qq.com
dfl
老哥教教我
bishuihanshan
1***@qq.com
DCloud_App_Array (作者)