admin管理员组文章数量:1558092
关于个推 vivo 接收不到离线消息问题
在2020年6月1日 vivo对消息推送管控进行调整,
对推送消息分为两种 0:运营消息 1:系统消息
在java 使用个推sdk的情况下 vivo对默认选择的推送消息类型为运营消息, 导致一个用户每天只能发送5条离线消息,5条过后将收不到消息,查看vivo开发平台发现消息已被管控。如下图:
以下是处理方式
主要设置 源码组件 第32行 以及第104行
源码 如下
maven依赖
<!--个推 消息推送 unipuh-->
<dependency>
<groupId>com.gexin.platform</groupId>
<artifactId>gexin-rp-sdk-http</artifactId>
<version>4.1.1.4</version>
</dependency>
组件
@Component
public class AppPush {
private static final Logger log = LoggerFactory.getLogger(AppPush.class);
// STEP1:获取应用基本信息
@Value("${push.rider.appId}")
private String riderAppId;
@Value("${push.rider.appKey}")
private String riderAppKey;
@Value("${push.rider.masterSecret}")
@Value("${push.url}")
private String url;
@Value("${push.rider.packet}")
private String riderPacket;
// 对单个骑手用户推送消息
public IPushResult pushMsgToSingleByApp(String cid, Map<String, String> msg) {
// 代表在个推注册的一个 app,调用该类实例的方法来执行对个推的请求
IGtPush push = new IGtPush(riderAppKey, riderMasterSecret);
// 创建信息模板
TransmissionTemplate template = AppPush.getTransmissionTemplateWith3rdNotifyInfoAndAPNPayload(msg.get("title"),
msg.get("titleText"), "0", msg,riderAppId,riderAppKey,riderPacket);
//定义消息推送方式为,单推
SingleMessage message = new SingleMessage();
// 设置推送消息的内容
message.setData(template);
message.setOffline(true);// 设置消息离线,并设置离线时间
message.setOfflineExpireTime(180 * 1000); // 离线有效时间,单位为毫秒,可选
Map<String,Integer> map=new LinkedMap<>(7);
map.put("default",1);
// map.put("hw",1);
// map.put("xm",4);
map.put("vv",2); //优先厂推
// map.put("mz",4);
// map.put("op",4);
message.setStrategyJson(JSONObject.toJSONString(map));
// message.setPushNetWorkType(0);
// 设置推送目标
Target target = new Target();
target.setAppId(riderAppId);
// 设置cid
target.setClientId(cid);
log.info("个推cid返回:"+cid);
// 获得推送结果
IPushResult result = push.pushMessageToSingle(message, target);
log.info("个推提交返回打印:"+JSONUtils.toJSONString(result.getResponse()));
/*
* 1. 失败:{result=sign_error}
* 2. 成功:{result=ok, taskId=OSS-0212_1b7578259b74972b2bba556bb12a9f9a, status=successed_online}
* 3. 异常
*/
return result;
}
/**
* 获取同时有Android第三方推送及IOS推送功能的很透传消息
*
* @param title 标题
* @param body 正文
* @param badge IOS的角标数
* @param customParam 自定义属性
* @return
*/
public static TransmissionTemplate getTransmissionTemplateWith3rdNotifyInfoAndAPNPayload(String title, String body, String badge,
Map<String, String> customParam,String appId,String appKey,String packet) {
TransmissionTemplate template = new TransmissionTemplate();
// 设置APPID与APPKEY
template.setAppId(appId);
template.setAppkey(appKey);
// 透传消息设置,1为强制启动应用,客户端接收到消息后就会立即启动应用;2为等待应用启动
template.setTransmissionType(2);
template.setTransmissionContent(JSON.toJSONString(customParam)); // 透传内容
// 第三方厂商推送
template.set3rdNotifyInfo(get3rdNotifyInfo(title, body, customParam,packet));
// 针对IOS,设置APNs
template.setAPNInfo(getAPNPayload(title, body, badge, customParam)); // ios消息推送
return template;
}
/**
* 第三方厂商通知
*
* @param title 标题
* @param content 正文
* @param payload 附带属性
* @return
*/
private static Notify get3rdNotifyInfo(String title, String content, Map<String, String> payload,String packet ) {
Notify notify = new Notify();
notify.setTitle(title);
notify.setContent(content);
notify.setType(GtReq.NotifyInfo.Type._intent);
//intent:#Intent;action=android.intent.action.oppopush;launchFlags=0x14000000;component=com.bajiaostar.uuRunBiker;S.UP-OL-SU=true;S.title=123;S.content=123;S.payload=ceshi;end
// /io.dcloud.PandoraEntry
String intent= "intent:#Intent;launchFlags=0x14000000;action=android.intent.action.oppopush;component="+packet+";S.UP-OL-SU=true;S.title="+title+";S.content="+content+";S.payload=ceshi;end";
notify.setIntent(intent);
notify.setPayload(JSON.toJSONString(payload));
//注意:这里是设置vivo推送消息类型
notify.addVVExtKV("classification",1);
return notify;
}
/**
* IOS的APNs消息
*
* @param title
* @param body
* @param badge
* @param customMsg
* @return
*/
private static APNPayload getAPNPayload(String title, String body, String badge, Map<String, String> customMsg) {
APNPayload payload = new APNPayload();
//在已有数字基础上加1显示,设置为-1时,在已有数字上减1显示,设置为数字时,显示指定数字
payload.setAutoBadge(badge);
payload.setContentAvailable(0);
//ios 12.0 以上可以使用 Dictionary 类型的 sound
payload.setSound("default");
// payload.setCategory("$由客户端定义");
if (customMsg != null) {
for (Map.Entry<String, String> enty : customMsg.entrySet()) {
payload.addCustomMsg(enty.getKey(), enty.getValue());
}
}
// payload.addCustomMsg("由客户自定义消息key", "由客户自定义消息value");
//简单模式APNPayload.SimpleMsg
// payload.setAlertMsg(new APNPayload.SimpleAlertMsg("hello"));
payload.setAlertMsg(getDictionaryAlertMsg(title, body)); //字典模式使用APNPayload.DictionaryAlertMsg
//设置语音播报类型,int类型,0.不可用 1.播放body 2.播放自定义文本
// payload.setVoicePlayType(2);
//设置语音播报内容,String类型,非必须参数,用户自定义播放内容,仅在voicePlayMessage=2时生效
//注:当"定义类型"=2, "定义内容"为空时则忽略不播放
// payload.setVoicePlayMessage("定义内容");
// 添加多媒体资源
// payload.addMultiMedia(new MultiMedia()
// .setResType(MultiMedia.MediaType.pic)
// .setResUrl("资源文件地址")
// .setOnlyWifi(true));
return payload;
}
/**
* IOS通知提示样式
*
* @param title
* @param body
* @return
*/
private static APNPayload.DictionaryAlertMsg getDictionaryAlertMsg(String title, String body) {
APNPayload.DictionaryAlertMsg alertMsg = new APNPayload.DictionaryAlertMsg();
alertMsg.setBody(body);
// alertMsg.setActionLocKey("显示关闭和查看两个按钮的消息");
// alertMsg.setLocKey("loc-key1");
// alertMsg.addLocArg("loc-ary1");
// alertMsg.setLaunchImage("调用已经在应用程序中绑定的图形文件名");
// iOS8.2以上版本支持
alertMsg.setTitle(title);
// alertMsg.setTitleLocKey("自定义通知标题");
// alertMsg.addTitleLocArg("自定义通知标题组");
return alertMsg;
}
}
以此作为记录学习
版权声明:本文标题:关于个推 vivo 接收不到离线消息问题 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1727362204a1110742.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论