JPUSH后台极光推送

Jpush后台极光推送,后台代码如下:
import org.apache.log4j.Logger;
import com.hrtel.app.controller.WorkerController;
import cn.jpush.api.JPushClient;
import cn.jpush.api.common.APIConnectionException;
import cn.jpush.api.common.APIRequestException;
import cn.jpush.api.push.PushResult;
import cn.jpush.api.push.model.Message;
import cn.jpush.api.push.model.Platform;
import cn.jpush.api.push.model.PushPayload;
import cn.jpush.api.push.model.audience.Audience;

/** s
* Jpush后台极光推送
*/
public class Test {
	private static final Logger logger = Logger.getLogger(WorkerController.class);
	public static void main(String[] args){
		
		// JPushClient jpushClient = new JPushClient(masterSecret, appKey, 3);
		JPushClient jpushClient = new JPushClient("839fb97f9ea2a77a15a5e0c9", "394b75478d1b91413a685de6", 3);

        // For push, all you need do is to build PushPayload object.
        PushPayload payload = buildPushObject_android_and_ios();

        try {
            PushResult result = jpushClient.sendPush(payload);
            logger.info("Got result - " + result);

        } catch (APIConnectionException e) {
            // Connection error, should retry later
        	logger.error("Connection error, should retry later", e);

        } catch (APIRequestException e) {
            // Should review the error, and fix the request
        	logger.error("Should review the error, and fix the request", e);
        	logger.info("HTTP Status: " + e.getStatus());
        	logger.info("Error Code: " + e.getErrorCode());
        	logger.info("Error Message: " + e.getErrorMessage());
        }
	}
	
	/**
	 * 返回通知,创建PushPayload
	 * @return
	 */
	 public static PushPayload buildPushObject_all_all_alert() {
		 	String msg = "海贼王";
	        return PushPayload.messageAll(msg);
	    }
	
	/**
	 * 返回自定义消息,创建PushPayload
	 * @return
	 */
	 public static PushPayload buildPushObject_android_and_ios() {
		 String msg = "{\"title\":\"移动套餐\",\"msg\":\"中国移动套餐\"}";
	        return PushPayload.newBuilder()
	                .setPlatform(Platform.android_ios())
	                .setAudience(Audience.all())
	                .setMessage(Message.newBuilder()
	                		.setMsgContent(msg)
	                		.build())
	                .build();
	    }
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值