天天看點

atitit.極光消息推送伺服器端開發實作推送  jpush v3. 總結o7p

atitit.極光消息推送伺服器端開發實作推送  jpush v3. 總結o7p

1. 推送所設計到底功能1

1.1. 内容壓縮1

1.2. 多引擎1

2. reg  ,設定appkey and pwdkey1

3. 下載下傳server  sdk   v31

4. push推送樣例1

5. Code3

1. 推送所設計到底功能

1.1. 内容壓縮

1.2. 多引擎

2. reg  ,設定appkey and pwdkey

3. 下載下傳server  sdk   v3

https://github.com/jpush/jpush-api-java-client

4. push推送樣例

以下片斷來自項目代碼裡的檔案:cn.jpush.api.examples.PushExample

       JPushClient jpushClient = new JPushClient(masterSecret, appKey, 3);

        // For push, all you need do is to build PushPayload object.

        PushPayload payload = buildPushObject_all_all_alert();

        try {

            PushResult result = jpushClient.sendPush(payload);

            LOG.info("Got result - " + result);

        } catch (APIConnectionException e) {

            // Connection error, should retry later

            LOG.error("Connection error, should retry later", e);

        } catch (APIRequestException e) {

            // Should review the error, and fix the request

            LOG.error("Should review the error, and fix the request", e);

            LOG.info("HTTP Status: " + e.getStatus());

            LOG.info("Error Code: " + e.getErrorCode());

            LOG.info("Error Message: " + e.getErrorMessage());

        }

進行推送的關鍵在于建構一個 PushPayload 對象。以下示例一般的建構對象的用法。

5. Code

Pushx。Java

private static void single_test(final double i) throws APIConnectionException,

APIRequestException {

core.execMeth_Ays(new Runnable() {

@Override

public void run() {

String r = "";

try {

r = new pushX().push(".", 1099);

} catch (APIConnectionException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (Exception e) {

}

System.out.println(String.valueOf(i) + "::" + r);

}, " threadName");

public String push(final String txt, final Object... target)

throws APIConnectionException, APIRequestException {

// attilax 老哇的爪子 X5042 o7m // k_56_44 o80 老哇的爪子 Attilax

core.log("---- o8q14 add act n seruinfo before  txt:" + txt);

core.log("----add act n seruinfo before len:"

+ String.valueOf(txt.length()));

final String s = jpushCompressor.kmprs(txt);

core.log("----add act n seruinfo aft len:" + String.valueOf(s.length()));

logger.info(txt + "\r\ntarget:" + StringUtils.join(target, ",") + " ");

// new com.attilax.tryX<String>() {

// @Override public String $$(Object t) throws Exception {

// attilax 老哇的爪子 2_q_9 o86

setInvokeTimes();

PushExample.SendPush_msgFmt(s, core.toStrArr(target));

} finally {

// this.respMsg=r;

this.sendMsg = PushExample.sendMsg_thrdloc.get();

// catch (APIConnectionException e) {

// respMsg="APIConnectionException";

// }

// catch (APIRequestException e) {

// respMsg=

// return null;

// }.$("");

new com.attilax.tryX<String>() {

public String $$(Object t) throws Exception {

// PushExample.SendPush(s, core.toStrArr(target));

return null;

}.$("");

String r = PushExample.rzt.get();

return r;