Created
October 31, 2017 09:30
-
-
Save alexandruc/679a3b631dc38e064a1c9973e24c4cc5 to your computer and use it in GitHub Desktop.
SNS send push notification
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <aws/core/Aws.h> | |
#include <aws/sns/SNSClient.h> | |
#include <aws/core/auth/AWSCredentialsProvider.h> | |
#include <aws/sns/model/PublishRequest.h> | |
#include <aws/sns/model/MessageAttributeValue.h> | |
int main(int argc, char *argv[]) | |
{ | |
Aws::SDKOptions options; | |
Aws::InitAPI(options); | |
Aws::Client::ClientConfiguration config; | |
config.region = "us-west-2"; | |
Aws::Auth::AWSCredentials credentials("xx", "yy"); | |
Aws::SNS::SNSClient client(credentials , config); | |
Aws::SNS::Model::PublishRequest pubReq; | |
Aws::SNS::Model::PublishOutcome pubOutcome; | |
pubReq.SetTargetArn("arn:aws:sns:us-west-2:069740189621:endpoint/WNS/Windows_VeraMobile_DEV/ccb48a46-c071-3b90-adbb-e98e2609eb91"); | |
pubReq.SetMessageStructure("json"); | |
pubReq.SetMessage("{ \"default\": \"default message\", \"WNS\" : \"{ \\\"message\\\": \\\"my message\\\",\\\"deviceid\\\":\\\"1\\\",\\\"devicecategory\\\":2 }\"}"); | |
Aws::Map<Aws::String, Aws::SNS::Model::MessageAttributeValue> msgAttribs; | |
Aws::SNS::Model::MessageAttributeValue msgAttribute; | |
msgAttribute.SetDataType("String"); | |
msgAttribute.SetStringValue("wns/raw"); | |
msgAttribs["AWS.SNS.MOBILE.WNS.Type"] = msgAttribute; | |
pubReq.SetMessageAttributes(msgAttribs); | |
std::cout << "payload: " << pubReq.SerializePayload() << std::endl; | |
pubOutcome = client.Publish(pubReq); | |
if(! pubOutcome.IsSuccess() ){ | |
std::cout << "outcome: " << pubOutcome.GetError().GetMessage() << std::endl; | |
} | |
Aws::ShutdownAPI(options); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment