我尝试将带有RestClient的请求发送到https://push.ionic.io/api/v1/push。我按照http://docs.ionic.io/docs/push-api-examples说的所有说明。我使用www.base64encode.org将我的私钥更改为base64,但最后返回的是:
{
"result": "error",
"message": "Unable to Authenticate"
}
这里是json a send:
{
"tokens":"fRB8B55UKS8:APA91bHjfNL7TJuAFzJKEQHSb4717__Ezz-nNvhSTgBdzuBhLz70P95S7lXDb46jfA6pZE-OWOdL-RCBBX0tnDCB7NZR0Og4YXcX5kvWlURwDfYfsH361ImJsdPap42JUr-wnkNqj0St",
"notification":{
"alert":"Hello World!",
"ios":{
"badge":1,
"sound":"ping.aiff",
"expiry": 1423238641,
"priority": 10,
"contentAvailable": 1,
"payload":{
"key1":"value",
"key2":"value"
}
},
"android":{
"collapseKey":"foo",
"delayWhileIdle":true,
"timeToLive":300,
"payload":{
"key1":"value",
"key2":"value"
}
}
}
}
编辑:
public static void push(String notification){
String str = "{\"tokens\": [\"fRB8B55UKS8:APA91bHjfNL7TJuAFzJKEQHSb4717__Ezz-nNvhSTgBdzuBhLz70P95S7lXDb46jfA6pZE-OWOdL-RCBBX0tnDCB7NZR0Og4YXcX5kvWlURwDfYfsH361ImJsdPap42JUr-wnkNqj0St\"],\"production\": true, \"notification\":{ \"alert\":\"azr\", \"title\": \"TOTO\", \"android\": {\"payload\": {}}, \"ios\": {\"payload\": {}}}}";
Promise<String> promise = WS.url(PUSH_URL)
.setContentType("application/json")
.setHeader("X-Ionic-Application-Id", APP_ID)
.setHeader("Authorization", "Basic " + new String(SECRET_ENCODED))
.post(str)
.map(
new Function<WS.Response, String>() {
public String apply(WS.Response response) {
String result = response.getBody();
return result;
}
});
String boo;
long timeout = 2000l;
boo = promise.get(timeout);
}
我正在使用play框架来做http请求
答案 0 :(得分:0)
要解决我添加的问题(:),APP_ID也必须是小写,如:dr2h3525