|
|
@@ -1,13 +1,5 @@
|
|
|
-#include <iostream>
|
|
|
-#include <iomanip>
|
|
|
-#include <sstream>
|
|
|
-#include <string>
|
|
|
-#include <stdio.h>
|
|
|
-#include <time.h>
|
|
|
-#include <openssl/sha.h>
|
|
|
-#include <openssl/hmac.h>
|
|
|
+#include "Message.h"
|
|
|
|
|
|
-using namespace std;
|
|
|
|
|
|
string get_data(int64_t ×tamp)
|
|
|
{
|
|
|
@@ -95,11 +87,11 @@ string HexEncode(const string &input)
|
|
|
return output;
|
|
|
}
|
|
|
|
|
|
-int main()
|
|
|
+bool SendMessage(int nTemplateId)
|
|
|
{
|
|
|
// 密钥参数,云API密匙查询: https://console.cloud.tencent.com/cam/capi
|
|
|
- string SECRET_ID = "AKIDz8krbsJ5yKBZQpn74WFkmLPx3*******";
|
|
|
- string SECRET_KEY = "Gu5t9xGARNpq86cd98joQYCN3*******";
|
|
|
+ string SECRET_ID = "AKID1vnmgR1PgmktyqU2NVQ8ex61iWHrJfrw";
|
|
|
+ string SECRET_KEY = "zvhGcljT6nPq470fBSaWFvT5ZvLfdTQJ";
|
|
|
|
|
|
string service = "sms";
|
|
|
string host = "sms.tencentcloudapi.com";
|
|
|
@@ -116,7 +108,7 @@ int main()
|
|
|
string canonicalHeaders = "content-type:application/json; charset=utf-8\nhost:" + host + "\n";
|
|
|
string signedHeaders = "content-type;host";
|
|
|
// 实际调用需要更新参数,这里仅作为演示签名验证通过的例子
|
|
|
- string payload = "{\"SmsSdkAppId\":\"1400006666\",\"TemplateParamSet\":[\"12345\"],\"PhoneNumberSet\":[\"+8618511122266\"],\"SessionContext\":\"test\",\"SignName\":\"腾讯云\",\"TemplateId\":\"1234\"}";
|
|
|
+ string payload = "{\"SmsSdkAppId\":\"1400895227\",\"TemplateParamSet\":[\"4\",\"ping !\"],\"PhoneNumberSet\":[\"+8615982211342\"],\"SessionContext\":\"PDU设备{1}网络状态异常:{2},请及时关注设备网络状态!\",\"SignName\":\"成都购旺科技\",\"TemplateId\":\"2108490\"}";
|
|
|
string hashedRequestPayload = sha256Hex(payload);
|
|
|
string canonicalRequest = httpRequestMethod + "\n" + canonicalUri + "\n" + canonicalQueryString + "\n"
|
|
|
+ canonicalHeaders + "\n" + signedHeaders + "\n" + hashedRequestPayload;
|
|
|
@@ -153,4 +145,14 @@ int main()
|
|
|
+ " -H \"X-TC-Region: " + region + "\""
|
|
|
+ " -d '" + payload + "'";
|
|
|
cout << curlcmd << endl;
|
|
|
- return 0;
|
|
|
+
|
|
|
+ //发送请求
|
|
|
+ int result = std::system(curlcmd.c_str());
|
|
|
+ if (result == 0) {
|
|
|
+ std::cout << "curl command succeeded." << std::endl;
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ std::cerr << "curl command failed with exit code: " << result << std::endl;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+}
|