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();
	    }
}

你可能感兴趣的:(JPUSH后台极光推送)