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 pushIds = new ArrayList();
		pushIds.add(REGIS_ID);
		// 1 调用推送服务
		ResultPack 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> 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();
		}
	}
}

 

你可能感兴趣的:(java)