JPush極光推送Java伺服器端API

來源:互聯網
上載者:User
// 對android和ios裝置發送JPushClient jpush = new JPushClient(masterSecret, appKey); // 對android和ios裝置發送,同時指定離線訊息儲存時間JPushClient jpush = new JPushClient(masterSecret, appKey, timeToLive); // 指定某種裝置發送JPushClient jpush = new JPushClient(masterSecret, appKey, DeviceEnum.Android); // 指定某種裝置發送,並且指定離線訊息儲存時間JPushClient jpush = new JPushClient(masterSecret, appKey, timeToLive, DeviceEnum.IOS);
參數名稱 參數類型 選項 內容說明
masterSecret
String 必須 Portal上註冊應用時產生的 masterSecret
appKey String 必須 Portal上註冊應用時產生的 appKey
timeToLive long 可選

儲存離線訊息的時間長度。秒為單位。最多支援10天(864000秒)。
0 表示該訊息不儲存離線。即:使用者線上馬上發出,當前不線上使用者將不會收到此訊息。
此參數不設定則表示預設,預設為儲存1天的離線訊息(86400秒)。

DeviceEnum Enum 可選 指定的裝置。
可選值:DeviceEnum.Android, DeviceEnum.IOS。
不填或者null值為同時支援 Android 與 iOS。
發送訊息

JPushClient公用方法

 

方法名稱 參數列表(必須) 方法說明
setEnableSSL boolean enableSSL (true為使用ssl, 預設為不使用ssl) 是否啟動ssl安全連線

sendNotificationWithImei

int sendNo(發送編號),
String imei (IMEI字串) ,
String msgTitle (訊息標題/通知標題) ,
String msgContent (訊息內容/通知內容) 
發送帶IMEI的通知
sendNotificationWithImei int sendNo , 
String imei ,
String msgTitle ,
String msgContent ,
int builderId (自訂通知欄樣式Id) ,
Map<String, Object>extra (附屬資訊)
自訂通知欄(沒有則填寫0)
以及傳遞附屬資訊 

sendCustomMessageWithImei

int sendNo , 
String imei ,
String msgTitle ,
String msgContent 
發送帶IMEI的訊息
sendCustomMessageWithImei int sendNo , 
String imei ,
String msgTitle ,
String msgContent, 
String msgContentType (訊息內容類型,原樣返回),
Map<String, Object> extra 
使用者自訂訊息類型,
以及傳遞附屬資訊 

sendNotificationWithTag

int sendNo , 
String tag (Tag字串) ,
String msgTitle ,
String msgContent
發送帶Tag的通知
sendNotificationWithTag int sendNo , 
String tag ,
String msgTitle ,
String msgContent , 
int builderId ,
Map<String, Object>extra
自訂通知欄(沒有則填寫0)
以及傳遞附屬資訊 

sendCustomMessageWithTag

int sendNo , 
String tag ,
String msgTitle ,
String msgContent
發送帶Tag的訊息
sendCustomMessageWithTag
int sendNo , 
String tag ,
String msgTitle ,
String msgContent ,
String msgContentType ,
Map<String, Object> extra 
使用者自訂訊息類型,
以及傳遞附屬資訊 

sendNotificationWithAlias

int sendNo , 
String alias (Alias字串) ,
String msgTitle , 
String msgContent
發送帶Alias的通知
sendNotificationWithAlias int sendNo , 
String alias (Alias字串) ,
String msgTitle , 
String msgContent ,
int builderId ,
Map<String, Object>extra
自訂通知欄(沒有則填寫0)
以及傳遞附屬資訊 

sendCustomMessageWithAlias

int sendNo , 
String alias ,
String msgTitle , 
String msgContent
發送帶Alias的訊息
sendCustomMessageWithAlias int sendNo , 
String alias ,
String msgTitle , 
String msgContent , 
String msgContentType ,
Map<String, Object> extra 
使用者自訂訊息類型,
以及傳遞附屬資訊 

sendNotificationWithAppKey

int sendNo , 
String msgTitle , 
String msgContent
發送通知給AppKey的所有使用者
sendNotificationWithAppKey int sendNo , 
String msgTitle , 
String msgContent ,
int builderId ,
Map<String, Object>extra
自訂通知欄(沒有則填寫0)
以及傳遞附屬資訊 

sendCustomMessageWithAppKey

int sendNo , 
String msgTitle , 
String msgContent
發送帶AppKey的訊息
sendCustomMessageWithAppKey int sendNo , 
String msgTitle , 
String msgContent ,
String msgContentType ,
Map<String, Object> extra  
使用者自訂訊息類型,
以及傳遞附屬資訊 

 

程式碼範例 程式碼範例-發送帶IMEI的通知
JPushClient jpush = new JPushClient(masterSecret, appKey);//jpush.setEnableSSL(true);int sendNo = 1;String imei = "";String msgTitle = "";String msgContent = ""; MessageResult msgResult = jpush.sendNotificationWithImei(sendNo, imei, msgTitle, msgContent);if (null != msgResult) {    if (msgResult.getErrcode() == ErrorCodeEnum.NOERROR.value()) {        System.out.println("發送成功, sendNo=" + msgResult.getSendno());    } else {        System.out.println("發送失敗, 錯誤碼=" + msgResult.getErrcode() + ", 錯誤訊息=" + msgResult.getErrmsg());    }} else {    System.out.println("無法擷取資料");}
程式碼範例-IOS設定通知鈴聲和badge
JPushClient jpush = new JPushClient(masterSecret, appKey); Map<String, Object> extra = new HashMap<String, Object>();IOSExtra iosExtra = new IOSExtra(1, "Windows_Logon_Sound.wav");//badge and soundextra.put("ios", iosExtra); MessageResult msgResult = jpush.sendNotificationWithAppKey(sendNo, msgTitle, msgContent, 0, extra);
MessageResult 類
公用方法 方法用途

getSendno

 訊息發送成功後,按用戶端傳輸的sendNo原樣返回

getErrcode

 錯誤碼,代碼定義參考ErrorCodeEnum
getErrmsg  返回錯誤訊息的描述
ErrorCode 類 錯誤碼-ErrorCodeEnum
package cn.jpush.api; public enum ErrorCodeEnum {         //沒有錯誤,發送成功    NOERROR(0),     //系統內部錯誤    SystemError(10),     //不支援GET請求    NotSupportGetMethod(1001),     //缺少必須參數    MissingRequiredParameters(1002),     //參數值不合法    InvalidParameter(1003),     //驗證失敗    ValidateFailed(1004),     //訊息體太大    DataTooBig(1005),     //IMEI不合法    InvalidIMEI(1007),     //appkey不合法    InvalidAppKey(1008),     //msg_content不合法    InvalidMsgContent(1010),     //沒有滿足條件的推送目標    InvalidPush(1011),     //IOS不支援自訂訊息    CustomMessgaeNotSupportIOS(1012);     private final int value;    private ErrorCodeEnum(final int value) {        this.value = value;    }     public int value() {        return this.value;    }}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.