1

根据我尝试过的链接,这是我尝试过的代码

    public static void SendNotification2(String appid, String pinpointEndpointId){


    try {
        GetEndpointRequest getEndpointRequest = new GetEndpointRequest()
                   .withApplicationId(appid)
                   .withEndpointId(pinpointEndpointId);

        AmazonPinpoint pinpoint = AmazonPinpointClientBuilder.standard().withRegion(Regions.US_EAST_1).build();

        GetEndpointResult endpointResult = pinpoint.getEndpoint(getEndpointRequest);

        EndpointResponse endpointResponse = endpointResult.getEndpointResponse();

        Map<String, String> data = new HashMap<String, String>();

        data.put("message", "test");


        DirectMessageConfiguration directMessageConfiguration =
                new DirectMessageConfiguration().withGCMMessage(new GCMMessage().withData(data).withSilentPush(true));
        AddressConfiguration addressConfiguration = new AddressConfiguration().withChannelType(ChannelType.GCM);

        MessageRequest messageRequest = new MessageRequest().withMessageConfiguration(directMessageConfiguration)
            .addAddressesEntry(endpointResponse.getAddress(), addressConfiguration);

        SendMessagesRequest sendMessagesRequest = new SendMessagesRequest()
            .withApplicationId(appid)
            .withMessageRequest(messageRequest);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


}

代码成功执行,没有任何错误/异常,但我没有看到通知。但是,当我使用端点 ID 从 pinpoint 的“直接消息传递”部分发布消息时,我能够在移动设备中看到通知。

同样使用 Amazon CLI 传递通知消息:

aws --region="us-east-1" pinpoint send-messages --application-id 1fd19ca6fa944a79bdd91beddb4b4f7e --message-request "{\"Context\":{},\"MessageConfiguration\":{\"DefaultMessage\":{\"Body\":\"Test from default message\",\"Substitutions\":{}},\"DefaultPushNotificationMessage\":{},\"APNSMessage\":{},\"GCMMessage\":{\"Data\":{\"message\":\"test\"},\"SilentPush\":true},\"BaiduMessage\":{},\"ADMMessage\":{},\"SMSMessage\":{}},\"Addresses\":{\"cltaa5owuOU:APA91bFOBUB5YRi_Ac6teNmuu19aoFDAByOeoVbqLmY1Yp6cZEp_aueunDU1ZPB6H50GKBfuxu300z-El_sEjxo72crYKnklI-wboxXDk180JICrif0c7R-fR4xFOm5WsQOGUJZPFLG6\":{\"ChannelType\":\"GCM\"}},\"Endpoints\":{}}

任何帮助将不胜感激。谢谢

4

0 回答 0