aliyun / aliyun/aliyun-openapi-cpp-sdk

在windows下用dysmsapi发送短信 出错

Open
#155 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
104
Forks
75
PR merge metrics
No merged PRs in 30d

Description

我用最新的版本: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();
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the SmsSend_ali entry point and reproduce the SendSms request on Windows under MSYS2/Qt, then compare its timestamp handling with the Ubuntu run. Trace the request construction and runtime diagnostics around commonResponse. Done means identifying the Windows-specific cause and confirming a successful request or a documented workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.