0
我試圖從我的應用程序服務器發送推送通知(PN)到Android設備使用發佈終端在Amazon SNS控制檯與此消息和消息結構作爲json它工作正常。Amazon SNS GCM/FCM消息負載
{
"GCM": "{ \"notification\": { \"text\": \"test message\" } }"
}
但是,當我嘗試在Java中實現相同的設備不會收到通知。在控制檯上
PublishRequest publishRequest = new PublishRequest();
publishRequest.setTargetArn("arn:aws:sns:ap-south-1:818862955266:endpoint/GCM/TestApp/a1ec8114-58c9-371b-bb76-d8d16e674e52");
String message = "{\"GCM\": \"{ \"notification\": { \"text\": \"test message\" } }\"}";
ObjectMapper mapper = new ObjectMapper();
PushRequest pushRequest = new PushRequest();
pushRequest.setDef("Test");
GCM gcm = new GCM();
Notification notification = new Notification();
notification.setText("hello");
gcm.setNotification(notification);
pushRequest.setGcm(gcm);
String jsonInString = mapper.writeValueAsString(pushRequest);
publishRequest.setMessage(jsonInString);
publishRequest.setMessageStructure("json");
System.out.println("Publist request:"+publishRequest.toString());
PublishResult publishResult = amazonSNSTemplate.getAmazonSNSClient().publish(publishRequest);
System.out.println(publishResult.toString());
System.out.println(publishResult.getSdkResponseMetadata().toString());
public class PushRequest {
@JsonProperty("default")
private String def;
@JsonProperty("GCM")
private GCM gcm;
public String getDef() {
return def;
}
public void setDef(String def) {
this.def = def;
}
public GCM getGcm() {
return gcm;
}
public void setGcm(GCM gcm) {
this.gcm = gcm;
}
}
public class GCM {
private Notification notification;
@JsonProperty("notification")
public Notification getNotification() {
return notification;
}
public void setNotification(Notification notification) {
this.notification = notification;
}
}
public class Notification {
private String text;
@JsonProperty("text")
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
響應
Publist請求:{TargetArn: ARN:AWS:SNS:AP-南-1:818862955266:端點/ GCM/TestApp/a1ec8114-58c9-371b- bb76-d8d16e674e52,消息: {「default」:「Test」,「GCM」:{「notification」:{「text」:「hello」}}},MessageStructure: json,MessageAttributes:{}} {MessageId: 7dfb613c-06d0-5fe6-8766-3068c9438614} {AWS_REQUEST_ID = 3d0e13f4-b2be-5c95-ad43-42a07d2d5567}
可能是什麼問題?
此外,我遵循SO回答here建議的模式。