java 極光推送

來源:互聯網
上載者:User

標籤:java   極光推送   

註:需要去官網下載   jpush-client-3.2.3.jar
/** * 極光推送工具類 * @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();}}

java 極光推送

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.