Created
July 24, 2023 07:49
-
-
Save M0nteCarl0/12cecfe6b9051e27cabbd618b55cabca to your computer and use it in GitHub Desktop.
Wins push notification client
This file contains 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 <cpprest/http_client.h> | |
#include <cpprest/json.h> | |
using namespace web; | |
using namespace web::http; | |
using namespace web::http::client; | |
int main() | |
{ | |
// Define the WNS endpoint URL | |
utility::string_t wnsEndpoint = U("https://your-wns-endpoint-url"); | |
// Define the package security identifier (SID) and secret key | |
utility::string_t packageSid = U("your-package-sid"); | |
utility::string_t secretKey = U("your-secret-key"); | |
// Create the HTTP client | |
http_client client(wnsEndpoint); | |
// Create the request message | |
http_request request(methods::POST); | |
request.headers().add(U("Content-Type"), U("application/octet-stream")); | |
request.headers().add(U("X-WNS-Type"), U("wns/raw")); | |
// Set the authorization header | |
utility::string_t authorizationHeader = U("Bearer "); | |
authorizationHeader.append(packageSid); | |
authorizationHeader.append(U("=")); | |
authorizationHeader.append(secretKey); | |
request.headers().add(U("Authorization"), authorizationHeader); | |
// Set the notification payload | |
utility::string_t notificationPayload = U("{\"data\":\"Hello, Windows!\"}"); | |
request.set_body(notificationPayload); | |
// Send the request | |
client.request(request).then([](http_response response) { | |
if (response.status_code() == status_codes::OK) { | |
std::cout << "Push notification sent successfully." << std::endl; | |
} else { | |
std::cout << "Error sending push notification. Status code: " << response.status_code() << std::endl; | |
} | |
}).wait(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment