java集成魅族推送sdk

测试代码块

/**
 * 魅族推送测试类
 * 
 */
public class Meizu {

	public static final int APP_ID = 123;

	public static final String APP_KEY = "APP_KEY";

	public static final String APP_SECRET = "APP_SECRET";

	// 需要推送用户的注册di
	public static final String REGIS_ID = "REGIS_ID";

	public static void main(String[] args) {
		doMeizuPush();
	}

	/**
	 * 组装消息
	 * 
	 * @param appId
	 * @param title
	 *            标题
	 * @param content
	 *            内容
	 * @return
	 */
	public static VarnishedMessage buildMessage(Long appId, String title, String content) {
		return new VarnishedMessage.Builder().appId(appId).title(title).content(content).build();
	}

	public static void doMeizuPush() {
		// 推送对象
		final IFlymePush push = new IFlymePush(APP_SECRET);
		// 目标用户
		List<String> pushIds = new ArrayList<String>();
		pushIds.add(REGIS_ID);
		// 1 调用推送服务
		ResultPack<PushResult> result;
		try {
			result = push.pushMessage(buildMessage(Long.valueOf(APP_ID), "title", "content"), pushIds, 3);
			if (result.isSucceed()) {
				// 2 调用推送服务成功 (其中map为设备的具体推送结果,一般业务针对超速的code类型做处理)
				PushResult pushResult = result.value();
				// 推送消息ID,用于推送流程明细排查
				String msgId = pushResult.getMsgId();
				// 推送结果,全部推送成功,则map为empty
				Map<String, List<String>> targetResultMap = pushResult.getRespTarget();
				if (targetResultMap != null && !targetResultMap.isEmpty()) {
					System.out.println("Meizu Push fail, token: " + targetResultMap);
				}
				System.out.println(String.format(
						"Meizu Push Over -> regisId: {}, data: {}, code: {}, messageId:{}, message: {}.", REGIS_ID,
						result.toString(), result.code(), msgId, result.comment()));
			} else {
				// 调用推送接口服务异常 eg: appId、appKey非法、推送消息非法.....
				// result.code(); //服务异常码
				// result.comment();//服务异常描述
				System.out.println(String.format("meizu pushMessage error code:%scomment:%s", result.code(), result.comment()));
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值