自学_个推的小栗子_透传给ios

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了,完成了单个推送;

     具体的用法我还是不太清楚,这个只能用到发出信息,但是消息类型,怎么组织的,我还是要再继续学习;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值