java集成求解

fab0d79b26df43ce41d3
2018-12-06 02:13 995 0

下载集成的demo运行时可以运行的,可是去官网注册了appkey以及Master Secret ,代码中修改了下就运行不起来,

public static PushPayload buildPushObject_android_and_ios() {
        Map<String, String> extras = new HashMap<String, String>();
        extras.put("test", "https://community.jiguang.cn/push");
//        extras.put("test", "https://bjapi.push.jiguang.cn/v3/push");
        return PushPayload.newBuilder()
                .setPlatform(Platform.all())
                .setAudience(Audience.all())
                .setNotification(Notification.newBuilder()
                        .setAlert("yangyang")
                        .addPlatformNotification(AndroidNotification.newBuilder()
                                .setTitle("lin")
                                .addExtras(extras).build())
                        .addPlatformNotification(IosNotification.newBuilder()
                                .incrBadge(1)
                                .addExtra("ios", "mengmeng").build())
                        .build())
                .build();
    }

    public static PushPayload buildPushObject_all_alias_alert() {
        return PushPayload.newBuilder()
                .setPlatform(Platform.all())
                .setAudience(Audience.alias("alias1"))
                .setNotification(Notification.alert("hahah"))
                .build();
    }

    public static void main(String[] args) {
        ClientConfig clientConfig = ClientConfig.getInstance();
//        clientConfig.setPushHostName("https://bjapi.push.jiguang.cn");
//        clientConfig.setScheduleHostName("https://bjapi.push.jiguang.cn");
//        clientConfig.put(ClientConfig.SCHEDULE_PATH, "v3/push/schedules");
        String authCode = ServiceHelper.getBasicAuthorization(APP_KEY, MASTER_SECRET);
        ApacheHttpClient httpClient = new ApacheHttpClient(authCode, null, clientConfig);

        JPushClient jpushClient = new JPushClient(MASTER_SECRET, APP_KEY, null, clientConfig);
        jpushClient.getPushClient().setHttpClient(httpClient);

        Map<String, String> extras = new HashMap<String, String>();
        extras.put("test", "https://community.jiguang.cn/push");
        // For push, all you need do is to build PushPayload object.
        PushPayload payload = buildPushObject_android_and_ios();

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

这是代码,运行后一直报错

```
18/12/06 10:12:46 DEBUG http.wire: http-outgoing-0 >> "{"platform":"all","audience":"all","notification":{"alert":"yangyang","ios":{"alert":"yangyang","extras":{"ios":"mengmeng"},"badge":"+1","sound":""},"android":{"alert":"yangyang","extras":{"test":"https://community.jiguang.cn/push"},"title":"lin"}},"options":{"sendno":1033437369,"apns_production":false}}"
18/12/06 10:12:46 DEBUG http.wire: http-outgoing-0 << "HTTP/1.1 400 Bad Request[\r][\n]"
18/12/06 10:12:46 DEBUG http.wire: http-outgoing-0 << "Server: nginx[\r][\n]"
18/12/06 10:12:46 DEBUG http.wire: http-outgoing-0 << "Date: Thu, 06 Dec 2018 02:12:46 GMT[\r][\n]"
18/12/06 10:12:46 DEBUG http.wire: http-outgoing-0 << "Content-Type: application/json[\r][\n]"
18/12/06 10:12:46 DEBUG http.wire: http-outgoing-0 << "Content-Length: 91[\r][\n]"
18/12/06 10:12:46 DEBUG http.wire: http-outgoing-0 << "Connection: keep-alive[\r][\n]"
18/12/06 10:12:46 DEBUG http.wire: http-outgoing-0 << "X-Rate-Limit-Limit: 600[\r][\n]"
18/12/06 10:12:46 DEBUG http.wire: http-outgoing-0 << "X-Rate-Limit-Remaining: 599[\r][\n]"
18/12/06 10:12:46 DEBUG http.wire: http-outgoing-0 << "X-Rate-Limit-Reset: 60[\r][\n]"
18/12/06 10:12:46 DEBUG http.wire: http-outgoing-0 << "X-Jpush-Msgid: 4000623665[\r][\n]"
18/12/06 10:12:46 DEBUG http.wire: http-outgoing-0 << "X-Jpush-Timestamp: 1544062366405[\r][\n]"
18/12/06 10:12:46 DEBUG http.wire: http-outgoing-0 << "[\r][\n]"
18/12/06 10:12:46 DEBUG http.wire: http-outgoing-0 << "{"msg_id":"4000623665","error":{"code":1011,"message":"cannot find user by this audience"}}"
18/12/06 10:12:46 DEBUG http.headers: http-outgoing-0 << HTTP/1.1 400 Bad Request
18/12/06 10:12:46 DEBUG http.headers: http-outgoing-0 << Server: nginx
18/12/06 10:12:46 DEBUG http.headers: http-outgoing-0 << Date: Thu, 06 Dec 2018 02:12:46 GMT
18/12/06 10:12:46 DEBUG http.headers: http-outgoing-0 << Content-Type: application/json
18/12/06 10:12:46 DEBUG http.headers: http-outgoing-0 << Content-Length: 91
18/12/06 10:12:46 DEBUG http.headers: http-outgoing-0 << Connection: keep-alive
18/12/06 10:12:46 DEBUG http.headers: http-outgoing-0 << X-Rate-Limit-Limit: 600
18/12/06 10:12:46 DEBUG http.headers: http-outgoing-0 << X-Rate-Limit-Remaining: 599
18/12/06 10:12:46 DEBUG http.headers: http-outgoing-0 << X-Rate-Limit-Reset: 60
18/12/06 10:12:46 DEBUG http.headers: http-outgoing-0 << X-Jpush-Msgid: 4000623665
18/12/06 10:12:46 DEBUG http.headers: http-outgoing-0 << X-Jpush-Timestamp: 1544062366405
18/12/06 10:12:46 DEBUG execchain.MainClientExec: Connection can be kept alive indefinitely
18/12/06 10:12:46 DEBUG connection.ApacheHttpClient: Response
18/12/06 10:12:46 DEBUG conn.PoolingHttpClientConnectionManager: Connection [id: 0][route: {s}->https://bjapi.push.jiguang.cn:443] can be kept alive indefinitely
18/12/06 10:12:46 DEBUG conn.PoolingHttpClientConnectionManager: Connection released: [id: 0][route: {s}->https://bjapi.push.jiguang.cn:443][total kept alive: 1; route allocated: 1 of 40; total allocated: 1 of 200]
18/12/06 10:12:46 DEBUG resp.ResponseWrapper: JPush API Rate Limiting params - quota:600, remaining:599, reset:60
18/12/06 10:12:46 DEBUG connection.ApacheHttpClient: {"msg_id":"4000623665","error":{"code":1011,"message":"cannot find user by this audience"}}
18/12/06 10:12:46 WARN connection.ApacheHttpClient: Got error response - responseCode:400, responseContent:{"msg_id":"4000623665","error":{"code":1011,"message":"cannot find user by this audience"}}
18/12/06 10:12:46 ERROR connection.ApacheHttpClient: Your request params is invalid. Please check them according to error message.
18/12/06 10:12:46 ERROR jpush.Jpush: Should review the error, and fix the request
{}
at cn.jiguang.common.connection.ApacheHttpClient.processResponse(ApacheHttpClient.java:469)
at cn.jiguang.common.connection.ApacheHttpClient.sendPost(ApacheHttpClient.java:317)
at cn.jpush.api.push.PushClient.sendPush(PushClient.java:160)
at cn.jpush.api.JPushClient.sendPush(JPushClient.java:194)
at com.yml.jpush.Jpush.main(Jpush.java:83)
18/12/06 10:12:46 INFO jpush.Jpush: HTTP Status: 400
18/12/06 10:12:46 INFO jpush.Jpush: Error Code: 1011
18/12/06 10:12:46 INFO jpush.Jpush: Error Message: cannot find user by this audience

1个回答

热门排序