Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在VS2022中运行阿里云短信V1.0的c++版本示例报错: #156

Open
tianjianing opened this issue Jan 9, 2025 · 9 comments
Open

Comments

@tianjianing
Copy link

#include
#include
#include <alibabacloud/core/AlibabaCloud.h>
#include <alibabacloud/core/CommonRequest.h>
#include <alibabacloud/core/CommonClient.h>
#include <alibabacloud/core/CommonResponse.h>

using namespace std;
using namespace AlibabaCloud;

int main( int argc, char** argv )
{
AlibabaCloud::InitializeSdk();
AlibabaCloud::ClientConfiguration configuration( "cn-qingdao" );
// specify timeout when create client.
configuration.setConnectTimeout(1500);
configuration.setReadTimeout(4000);
// Please ensure that the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set.
AlibabaCloud::Credentials credential( getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET") );
/* use STS Token
credential.setSessionToken( getenv("ALIBABA_CLOUD_SECURITY_TOKEN") );
*/
AlibabaCloud::CommonClient client( credential, configuration );
AlibabaCloud::CommonRequest request(AlibabaCloud::CommonRequest::RequestPattern::RpcPattern);
request.setHttpMethod(AlibabaCloud::HttpRequest::Method::Post);
request.setDomain("dysmsapi.aliyuncs.com");
request.setVersion("2017-05-25");
request.setQueryParameter("Action", "SendSms");

auto response = client.commonResponse(request);
if (response.isSuccess()) {
    printf("request success.\n");
    printf("result: %s\n", response.result().payload().c_str());
} else {
    printf("error: %s\n", response.error().errorMessage().c_str());
    printf("request id: %s\n", response.error().requestId().c_str());
}

AlibabaCloud::ShutdownSdk();
return 0;

}

报错如下:

错误 C4996 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. test-2-alibaba D:\Visual Studio\Projects\test-2-alibaba D:\Visual Studio\Projects\test-2-alibaba\test-2-alibaba.cpp 19

@yndu13
Copy link
Contributor

yndu13 commented Jan 10, 2025

感谢反馈,我们处理下

@TsinghuaDream
Copy link
Contributor

这个应该是VS编译器的报错,是要在windows上开发 Windows 平台 (UWP) 应用吗?若是如此应该用不了环境变量的方案https://learn.microsoft.com/zh-cn/cpp/cppcx/crt-functions-not-supported-in-universal-windows-platform-apps?view=msvc-170
即把getenv删除,然后使用变量传递AK的两个值应该就好,出于安全我们不建议将AK明文写在代码中。

@tianjianing
Copy link
Author

tianjianing commented Jan 10, 2025 via email

@tianjianing
Copy link
Author

tianjianing commented Jan 10, 2025 via email

@TsinghuaDream
Copy link
Contributor

是没编译core文件夹吗

@tianjianing
Copy link
Author

tianjianing commented Jan 10, 2025 via email

@TsinghuaDream
Copy link
Contributor

编译完整信息发下吧 看是哪行触发的编译报错

@tianjianing
Copy link
Author

tianjianing commented Jan 10, 2025 via email

@tianjianing
Copy link
Author

tianjianing commented Jan 10, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants