后台报错 推送接口不通

error
标签: #<Tag:0x00007f83d4c703a8>

(Captain Lu) #1

{“error”:{“code”:1000,“message”:“Server internal error”}}

Process finished with exit code 0


#2

请问现在是否还存在问题?
提供你调用的 API 地址、Appkey、报错时间点。


(Captain Lu) #3

有问题{“error”:{“code”:1000,“message”:“Server internal error”}}


(Captain Lu) #4

是接口返回的 不是json 异常


(Captain Lu) #5
private static final String uri = "https://api.jpush.cn/v3/push";

@Override
public void sendPush(String msg) {
    send(msg);
}

static HttpPost post = null;

private static void send(String msg) {
    HttpClient client = new DefaultHttpClient();
    post = new HttpPost(uri);
    post.setHeader("Content-type", "application/json; charset=utf-8");
    //   post.setHeader("Connection", "Close");
    String master = "Basic  " + getMaster();
    post.setHeader("Authorization", master);
    JSONObject jsonObject = getBody(msg);
    // 构建消息实体
    StringEntity entity = new StringEntity("{\n" +
            "    \"platform\": \"all\",\n" +
            "    \"audience\": {\n" +
            "        \"tag\": [\n" +
            "            \"深圳\",\n" +
            "            \"北京\"\n" +
            "        ]\n" +
            "    },\n" +
            "    \"notification\": {\n" +
            "        \"android\": {\n" +
            "            \"alert\": \"Hi, JPush!\",\n" +
            "            \"title\": \"Send to Android\",\n" +
            "            \"builder_id\": 1,\n" +
            "            \"large_icon\": \"http://www.jiguang.cn/largeIcon.jpg\",\n" +
            "            \"intent\": {\n" +
            "                \"url\": \"intent:#Intent;component=com.jiguang.push/com.example.jpushdemo.SettingActivity;end\",\n" +
            "            },\n" +
            "            \"extras\": {\n" +
            "                \"newsid\": 321\n" +
            "            }\n" +
            "        },\n" +
            "        \"ios\": {\n" +
            "            \"alert\": \"Hi, JPush!\",\n" +
            "            \"sound\": \"default\",\n" +
            "            \"badge\": \"+1\",\n" +
            "            \"thread-id\": \"default\"\n" +
            "            \"extras\": {\n" +
            "                \"newsid\": 321\n" +
            "            }\n" +
            "        }\n" +
            "    },\n" +
            "    \"message\": {\n" +
            "        \"msg_content\": \"Hi,JPush\",\n" +
            "        \"content_type\": \"text\",\n" +
            "        \"title\": \"msg\",\n" +
            "        \"extras\": {\n" +
            "            \"key\": \"value\"\n" +
            "        }\n" +
            "    },\n" +
            "    \"sms_message\":{\n" +
            "       \"temp_id\":1250,\n" +
            "       \"temp_para\":{\n" +
            "            \"code\":\"123456\"\n" +
            "       },\n" +
            "        \"delay_time\":3600,\n" +
            "        \"active_filter\":false\n" +
            "    },\n" +
            "    \"options\": {\n" +
            "        \"time_to_live\": 60,\n" +
            "        \"apns_production\": false,\n" +
            "        \"apns_collapse_id\":\"jiguang_test_201706011100\"\n" +
            "    }\n" +
            "}\n", Charset.forName("UTF-8"));
    entity.setContentEncoding("UTF-8");
    // 发送Json格式的数据请求
    entity.setContentType("application/json");
    post.setEntity(entity);

    try {
        //执行请求操作,并拿到结果(同步阻塞)
        HttpResponse response = client.execute(post);
        int statusCode = response.getStatusLine().getStatusCode();
        System.out.println(statusCode == 200 ? "OK" : "ERROR");
        //获取结果实体
        HttpEntity entityR = response.getEntity();
        if (entityR != null) {
            //按指定编码转换结果实体为String
            String s = EntityUtils.toString(entityR, "utf-8");
            System.out.println(s);
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("error");
    }
}

private static JSONObject getBody(String msg) {
    JSONObject object = new JSONObject();
    object.put("platform", "all");
    object.put("audience", "\"tag\": [\n" +
            "            \"深圳\",\n" +
            "            \"北京\"\n" +
            "        ]");
    object.put("message", " {\n" +
            "        \"msg_content\": \"Hi,JPush\",\n" +
            "        \"content_type\": \"text\",\n" +
            "        \"title\": \"msg\",\n" +
            "        \"extras\": {\n" +
            "            \"key\": \"value\"\n" +
            "        }");
    object.put("notification", " {\n" +
            "        \"android\": {\n" +
            "            \"alert\": \"Hi, JPush!\",\n" +
            "            \"title\": \"Send to Android\",\n" +
            "            \"builder_id\": 1,\n" +
            "            \"large_icon\": \"http://www.jiguang.cn/largeIcon.jpg\",\n" +
            "            \"intent\": {\n" +
            "                \"url\": \"intent:#Intent;component=com.jiguang.push/com.example.jpushdemo.SettingActivity;end\",\n" +
            "            },\n" +
            "            \"extras\": {\n" +
            "                \"newsid\": 321\n" +
            "            }\n" +
            "        },\n" +
            "        \"ios\": {\n" +
            "            \"alert\": \"Hi, JPush!\",\n" +
            "            \"sound\": \"default\",\n" +
            "            \"badge\": \"+1\",\n" +
            "            \"thread-id\": \"default\"\n" +
            "            \"extras\": {\n" +
            "                \"newsid\": 321\n" +
            "            }\n" +
            "        }\n" +
            "    }");

    return object;
}

private static String getMaster() {
    String str = APP_KEY + ":" + MASTER_SECRET;
    String result = "";
    try {
        byte[] bytes = str.getBytes("UTF-8");
        result = encode(bytes);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return result;
}

public static String encode(byte[] bstr) {
    return new sun.misc.BASE64Encoder().encode(bstr);
}

public static void main(String[] args) {
    send("123");
}

}


(Captain Lu) #6
    private static final String APP_KEY = "3b8dfe997d1f8d3bf68bd80a";

#7

你直接 curl 推送试一下结果。
我这测试正常。另外,你 ping 一下 api.jpush.cn


(Captain Lu) #8

Last login: Mon May 13 08:45:05 on ttys000

lujuanyudeMacBook-Pro:~ lujunyu$ ping http://api.jpush.cn

ping: cannot resolve http://api.jpush.cn: Unknown host

lujuanyudeMacBook-Pro:~ lujunyu$ ping 不通 我试试部署到服务器


#9

那看下你绑定的 host

这里面的命令可以用来排查,可能是你的网络限制问题,也可能是你配置了相关host 文件有问题


(Captain Lu) #10

我试试服务器呗 反正要部署