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

在windows下用dysmsapi发送短信 出错 #155

Open
runninglinuxkernel opened this issue Nov 27, 2024 · 0 comments
Open

在windows下用dysmsapi发送短信 出错 #155

runninglinuxkernel opened this issue Nov 27, 2024 · 0 comments

Comments

@runninglinuxkernel
Copy link

runninglinuxkernel commented Nov 27, 2024

我用最新的版本:aliyun-openapi-cpp-sdk-1.36.2021
编译模块:dysmsapi

在MSYS2编译成 dll动态库,在windows QT中运行:

InitializeSdk done

Invalid parameter passed to C runtime function.
Invalid parameter passed to C runtime function.
SmsSend_ali: error code: InvalidTimeStamp.Format
SmsSend_ali: error: Specified time stamp or date value is not well formatted.
SmsSend_ali: detail:
SmsSend_ali: paylod:
request id: B43B5BFE-5673-5AF9-A0D7-C160D6AD2AD6

出现这个错误,请问一下这是什么原因?

下面是发送短信的代码片段,(这代码片段在ubuntu上可以发短信的):

void SmsSend_ali(std::string phone, std::string code)
{
    AlibabaCloud::InitializeSdk();

    LOG("InitializeSdk done\n");

    AlibabaCloud::ClientConfiguration configuration( "cn-hangzhou" );

    // 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("LTAxxxxx", "FrGxxxxxxx");

    /* 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");
    request.setQueryParameter("PhoneNumbers", phone);
    request.setQueryParameter("SignName", "dddd");
    request.setQueryParameter("TemplateCode", "SMS_47xxxxx");

    std::string templateParam = "{\"code\":\"" + code + "\"}";
    request.setQueryParameter("TemplateParam", templateParam);
    //request.setQueryParameter("TemplateParam", "{\"code\":\"4321\"}");

    auto response = client.commonResponse(request);
    if (response.isSuccess()) {
        LOG("SmsSend_ali request success.\n");
        LOG("SmsSend_ali: result:" << response.result().payload().c_str());
    } else {
        LOG("SmsSend_ali: error code:" << response.error().errorCode().c_str());
        LOG("SmsSend_ali: error:" << response.error().errorMessage().c_str());
        LOG("SmsSend_ali: detail:" <<response.error().detail().c_str());
        LOG("SmsSend_ali: paylod:" << response.result().payload().c_str());
        LOG("request id:" << response.error().requestId().c_str());
    }

    AlibabaCloud::ShutdownSdk();
}
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

1 participant