zoukankan      html  css  js  c++  java
  • java 极光推送

    /**
     * 极光推送工具类
     * @author why
     *
     */
    @SuppressWarnings("all")
    public class JPushAllUtil {
    	private final static String appKey = "";
    	private final static String masterSecret = "";
    	/**
    	 * 测试方法
    	 */
    	public static void main(String[] args) {
    		//发送通知
    		jSend_notification("0a139889879","您有一条新的物流消息_123");
    		
    	}
    	/**
    	 * 发送通知
    	 * @param registrationId 设备标识
    	 * @param alert 推送内容
    	 */
    	public static void jSend_notification(String registrationId, String alert){
    		JPushClient jpushClient = new JPushClient(masterSecret, appKey, 3);
    		PushPayload payload = send_N(registrationId, alert);
    		try {
                PushResult result = jpushClient.sendPush(payload);
                System.out.println(result);
                
            } catch (APIConnectionException e) {
                System.out.println(e);
            } catch (APIRequestException e) {
            	System.out.println(e);
            	System.out.println("Error response from JPush server. Should review and fix it. "+ e);
            	System.out.println("HTTP Status: " + e.getStatus());
            	System.out.println("Error Code: " + e.getErrorCode());
            	System.out.println("Error Message: " + e.getErrorMessage());
            	System.out.println("Msg ID: " + e.getMsgId());
            }
    	}
    	
    	public static PushPayload send_N(String registrationId, String alert){
    		return PushPayload.newBuilder()
        			.setPlatform(Platform.android_ios())//必填    推送平台设置
        			.setAudience(Audience.registrationId(registrationId))
        			.setNotification(Notification.alert(alert))
        			/**
        			 * 如果目标平台为 iOS 平台 需要在 options 
        			 * 中通过 apns_production 字段来制定推送环境。
        			 * True 表示推送生产环境,False 表示要推送开发环境; 如
        			 * 果不指定则为推送生产环境
        			 */
        			.setOptions(Options.newBuilder()
        					.setApnsProduction(false)
        					.build())
        			.build();
    		}
    }
  • 相关阅读:
    (二)常问升级小点
    (一)常问基础小点
    Linux之expr命令详解
    Mac--Visual Studio Code 常用快捷键
    git撤销commit操作回到add状态
    ExampleMatcher ,在查询非int 或boolean 字段时要使用 withIgnorePaths() 忽略 int 和boolean 字段,要不然查询不到值
    navicat 用url 连接mongo
    javase 打印杨辉三角
    关系型数据库遵循ACID规则
    Redis介绍
  • 原文地址:https://www.cnblogs.com/JOEH60/p/5781012.html
Copyright © 2011-2022 走看看