个推遇到没有消息推送

个推遇到Java后台返回成功移动端不推送消息

官方文档

http://docs.getui.com/ 使用时可参考

Java集成

单推,群推代码示例
package com.getui.platform.demo.push;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.gexin.rp.sdk.base.IPushResult;
import com.gexin.rp.sdk.base.impl.AppMessage;
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.exceptions.RequestException;
import com.gexin.rp.sdk.http.IGtPush;
import com.gexin.rp.sdk.template.TransmissionTemplate;

public class PushMessage{

	// 1:获取应用基本信息
    private static String appId = "cb4psTmvup6jdeRz5FOuiA";
    private static String appKey = "armpJUdqPr6BvG8aJCZo89";
    private static String masterSecret = "Lo4u2eQo3L70gsNipaUaW2";
    private static String url = "http://sdk.open.api.igexin.com/apiex.htm";
    private static String cid = "def823c2ce8bf54e8b14b302984d4fe9";
    
	/**
	 * 
	* @Function: getAppPushAll
	* @Description: 单推
	* @version: v1.0.0
	* @author: qiuyujiao
	* @date: 2019年11月7日
	 */
    public static void getPushtoSingle(){
    	IGtPush push = new IGtPush(url, appKey, masterSecret);
		TransmissionTemplate template = getTemplate();
		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(appId);
		target.setClientId(cid);
		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("服务器响应异常");
		}
		System.out.println(ret.getResponse().toString());
	}

    /**
     * 
    * @Function: getTemplate
    * @Description: 通知模板
    * @version: v1.0.0
    * @author: qiuyujiao
    * @date: 2019年11月7日 
     */
	public static TransmissionTemplate getTemplate() {
		TransmissionTemplate template = new TransmissionTemplate();
		template.setTransmissionContent("aa");//透传的内容,开发者自行处理
		template.setAppId(appId);
		template.setAppkey(appKey);
		// 透传消息设置,1为强制启动应用,客户端接收到消息后就会立即启动应用;2为等待应用启动
		template.setTransmissionType(2);
		APNPayload payload = new APNPayload();
		// 字典模式使用APNPayload.DictionaryAlertMsg
		payload.setAlertMsg(getDictionaryAlertMsg());
		template.setAPNInfo(payload);
		return template;
	}

	/**
	 * 
	* @Function: getDictionaryAlertMsg
	* @Description: 【通知样式】iOS通知样式设置
	* ios一定要用改方法调试,平板上才会显示推送的消息
	* @version: v1.0.0
	* @author: qiuyujiao
	* @date: 2019年11月7日
	 */
	private static APNPayload.DictionaryAlertMsg getDictionaryAlertMsg() {
		APNPayload.DictionaryAlertMsg alertMsg = new APNPayload.DictionaryAlertMsg();
		alertMsg.setBody("推送测试内容11");
		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;
	}

	/**
	 * 
	* @Function: getAppPushAll
	* @Description: 群推
	* @version: v1.0.0
	* @author: qiuyujiao
	* @date: 2019年11月7日
	 */
	public static void getAppPushAll(){
		IGtPush push = new IGtPush(url, appKey, masterSecret);
		TransmissionTemplate template = getTemplate();
        AppMessage message = new AppMessage();
        message.setData(template);
        message.setOffline(true);
        // 离线有效时间,单位为毫秒
        message.setOfflineExpireTime(24 * 1000 * 3600);
        List<String> appIdList = new ArrayList<String>();
        appIdList.add(appId);
        message.setAppIdList(appIdList);
        message.setOffline(true);
        // 离线有效时间,单位为毫秒
        message.setOfflineExpireTime(24 * 1000 * 3600);
        IPushResult ret = push.pushMessageToApp(message);
        System.out.println(ret.getResponse().toString());
	}
	public static void main(String[] args) throws IOException {
		getPushtoSingle();
		getAppPushAll();
	}
	
}

平板收到消息通知

在这里插入图片描述

需要注意的地方

1.如果是和ios调试,需要调用【透传模板】自定义消息 TransmissionTemplate 才能在苹果平板上看到推送
2.如果是和ios调试,一定需要template.setAPNInfo(payload);

此文章仅供参考,欢迎大家一起讨论

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值