android接收情况:
????????在线:可以收到通知
? ? ? ? 离线:在app离线后,消息有效时间内,在此打开app可收到推送消息
? ? ? ? 离线,不在消息有效期内,走第三方厂商推送
? ? ? ? 缺点:无
ios接收情况
? ? ? ??在线:不能收到通知
? ? ? ? 离线:可以走apns,苹果自己的推送服务,可以收到消息
? ? ? ? 缺点:app在线收不到消息
package co.yixiang;
import com.alibaba.fastjson.JSONObject;
import com.gexin.rp.sdk.base.IPushResult;
import com.gexin.rp.sdk.base.impl.AppMessage;
import com.gexin.rp.sdk.base.notify.Notify;
import com.gexin.rp.sdk.base.payload.APNPayload;
import com.gexin.rp.sdk.dto.GtReq;
import com.gexin.rp.sdk.http.IGtPush;
import com.gexin.rp.sdk.template.StartActivityTemplate;
import com.gexin.rp.sdk.template.style.Style0;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class UniPushTest06 {
// STEP1:获取应用基本信息
private static String appId = "";
private static String appKey = "";
private static String masterSecret = "";
private static String url = "http://sdk.open.api.igexin.com/apiex.htm";
public static void main(String[] args) throws IOException {
String title="我是标题";
String content="我是内容";
Integer type=0;
Integer contentId=258;
Map map=new HashMap();
map.put("type",type);
map.put("contentId",contentId);
map.put("title",title);
map.put("content",content);
JSONObject jsonObj=new JSONObject(map);
String s = jsonObj.toString();
IGtPush push = new IGtPush(url, appKey, masterSecret);
Style0 style = new Style0();
// STEP2:设置推送标题、推送内容
style.setTitle(title);
style.setText(content);
// 注释采用默认图标
// style.setLogo("push.png"); // 设置推送图标
// STEP3:设置响铃、震动等推送效果
style.setRing(true); // 设置响铃
style.setVibrate(true); // 设置震动
// STEP4:选择通知模板
StartActivityTemplate template = new StartActivityTemplate ();
template.setAppId(appId);
template.setAppkey(appKey);
template.setStyle(style);
String intent = "intent:#Intent;action=android.intent.action.oppopush;launchFlags=0x14000000;component=uni.UNI91FE773/io.dcloud.PandoraEntry;S.UP-OL-SU=true;S.title="+title+";S.content="+content+";S.payload="+s+";end";
template.setIntent(intent);
//template.setAPNInfo();
Notify notify = new Notify();
notify.setTitle("厂商推送title");
notify.setContent("厂商推送内容");
notify.setIntent("intent:#Intent;action=android.intent.action.oppopush;launchFlags=0x14000000;component=uni.UNI91FE773/io.dcloud.PandoraEntry;S.UP-OL-SU=true;S.title="+title+";S.content="+content+";S.payload="+s+";end");
notify.setType(GtReq.NotifyInfo.Type._intent);
template.set3rdNotifyInfo(notify);//设置第三方通知
APNPayload apnpayload = new APNPayload();
apnpayload.setSound("");
//apnpayload.setAlertMsg(new APNPayload.SimpleAlertMsg("hello"));
apnpayload.setAlertMsg(getDictionaryAlertMsg());
//传送的附加信息,用于解析
apnpayload.addCustomMsg("info","测试参数");
apnpayload.addCustomMsg("info1","测试参数2");
template.setAPNInfo(apnpayload);
// STEP5:定义"AppMessage"类型消息对象,设置推送消息有效期等推送参数
List<String> appIds = new ArrayList<String>();
appIds.add(appId);
AppMessage message = new AppMessage();
message.setData(template);
message.setAppIdList(appIds);
message.setOffline(true);
message.setOfflineExpireTime(1000 * 600); // 时间单位为毫秒
// STEP6:执行推送
IPushResult ret = push.pushMessageToApp(message);
System.out.println(ret.getResponse().toString());
}
/**
* 苹果消息文字设置
* @return
*/
private static APNPayload.DictionaryAlertMsg getDictionaryAlertMsg(){
APNPayload.DictionaryAlertMsg alertMsg = new APNPayload.DictionaryAlertMsg();
alertMsg.setTitle("标题是我123456");
alertMsg.setBody("我以前是body,现在改变了吗?");
alertMsg.setActionLocKey("ActionLockey");
//显示关闭和查看两个按钮的消息;
alertMsg.setLocKey("LocKey");
alertMsg.addLocArg("loc-args");
alertMsg.setLaunchImage("launch-image");
// iOS8.2以上版本支持
alertMsg.setTitleLocKey("TitleLocKey");
alertMsg.addTitleLocArg("TitleLocArg");
return alertMsg;
}
}
plus.push.addEventListener("click", function(msg) {
console.log("click:"+JSON.stringify(msg));
console.log(msg.payload);
let pinf = plus.push.getClientInfo();
console.log("pinf:"+JSON.stringify(pinf));
}, false);
|