package com.shtoone.app.util;
import java.util.HashMap;
import java.util.Map;
import com.gexin.rp.sdk.base.IPushResult;
import com.gexin.rp.sdk.base.impl.SingleMessage;
import com.gexin.rp.sdk.base.impl.Target;
import com.gexin.rp.sdk.base.payload.APNPayload;
import com.gexin.rp.sdk.http.IGtPush;
import com.gexin.rp.sdk.template.TransmissionTemplate;
import com.itextpdf.io.IOException;
public class a {
private static String appId = "";
private static String appKey = "";
private static String masterSecret = "";
private static String url = "http://sdk.open.api.igexin.com/apiex.htm";
private static String clientId="";//
public static void main(String[] args) throws IOException {
IGtPush push = new IGtPush(url, appKey, masterSecret);
TransmissionTemplate template =getTemplate();
// 定义"AppMessage"类型消息对象,设置消息内容模板、发送的目标App列表、是否支持离线发送、以及离线消息有效期(单位毫秒)
SingleMessage message = new SingleMessage();
message.setData(template);
// 设置消息离线,并设置离线时间
message.setOffline(true);
// 离线有效时间,单位为毫秒,可选
message.setOfflineExpireTime(24 * 1000 * 3600);
Target target = new Target();
//Target target2 = new Target();
target.setAppId(appId);
target.setClientId(clientId);
IPushResult ret = push.pushMessageToSingle(message, target);
System.out.println(ret.getResponse().toString());
}
public static TransmissionTemplate getTemplate() {
TransmissionTemplate template = new TransmissionTemplate();
template.setAppId(appId);
template.setAppkey(appKey);
template.setTransmissionContent("透传内容1111111111");
template.setTransmissionType(2);
APNPayload payload = new APNPayload();
//在已有数字基础上加1显示,设置为-1时,在已有数字上减1显示,设置为数字时,显示指定数字
payload.setAutoBadge("+1");
payload.setContentAvailable(1);
//ios 12.0 以上可以使用 Dictionary 类型的 sound
payload.setSound("default");
payload.setCategory("$由客户端定义");
Map<String,String> map = new HashMap<String,String>();
map.put("type", "0");
map.put("text", "这是一条审核消息");
payload.addCustomMsg("payload", map);
//字典模式使用APNPayload.DictionaryAlertMsg
payload.setAlertMsg(getDictionaryAlertMsg());
//设置语音播报类型,int类型,0.不可用
payload.setVoicePlayType(0);
template.setAPNInfo(payload);
return template;
}
private static APNPayload.DictionaryAlertMsg getDictionaryAlertMsg(){
APNPayload.DictionaryAlertMsg alertMsg = new APNPayload.DictionaryAlertMsg();
alertMsg.setBody("您有一个验收单");
alertMsg.setActionLocKey("ActionLockey");
alertMsg.setLocKey("LocKey");
alertMsg.addLocArg("loc-args");
alertMsg.setLaunchImage("launch-image");
// iOS8.2以上版本支持
alertMsg.setTitle("标题");
alertMsg.setTitleLocKey("TitleLocKey");
alertMsg.addTitleLocArg("TitleLocArg");
return alertMsg;
}
}
个推的文档看了半天也还是有点懵,我自己试了试,发现把测试里面的推送demo变成模板里的TransmissionTemplate template =getTemplate(); 就可以发出透传消息了; 接着我又把message的改成toSingle了,完成了单个推送;
具体的用法我还是不太清楚,这个只能用到发出信息,但是消息类型,怎么组织的,我还是要再继续学习;