Amazon C++ SDK SMS/MMS

说明

Amazon支持SMS/MMS功能,根据官方提供的API接口是需要SDK来支持的。如下是SDK API相关介绍:

发布到移动电话 - Amazon Simple Notification Service

获取SDK

git clone https://github.com/aws/aws-sdk-cpp.git

设置region、keyId及accessKey

setenv("AWS_DEFAULT_REGION", region, 1);
setenv("AWS_ACCESS_KEY_ID", keyId, 1);
setenv("AWS_SECRET_ACCESS_KEY", accessKey, 1);

SDK调用

static int amazonSendMsg(const char *to, const char *body)
{
    int retval = -1;
    Aws::SDKOptions options;
    options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Trace;

#if defined(__arm__) || defined(__aarch64__)
    openlog("smstool", LOG_ODELAY, LOG_USER); //启用syslog功能
#endif

    /*! 使用Lambada配置SDK log级别 */
    options.loggingOptions.logger_create_fn = []() {
        return Aws::MakeShared<LogObject>("Client", Aws::Utils::Logging::LogLevel::Trace);
    };

    Aws::InitAPI(options);
#if defined(__arm__) || defined(__aarch64__)
    Aws::Client::ClientConfiguration clientConfig;
    clientConfig.caFile = CA_FILE; //导入证书
    Aws::SNS::SNSClient sns(clientConfig);
#else
    Aws::SNS::SNSClient sns;
#endif
    Aws::String message = body;
    Aws::String phone_number = to;

    Aws::SNS::Model::PublishRequest psms_req;
    psms_req.SetMessage(message);
    psms_req.SetPhoneNumber(phone_number);

    auto psms_out = sns.Publish(psms_req);
    if (psms_out.IsSuccess()) {
        retval = 0;
        logOut("Message published successfully %s", psms_out.GetResult().GetMessageId());
    } else {
        logOut("Error while publishing message %s", psms_out.GetError().GetMessage());
    }
    Aws::ShutdownAPI(options);

#if defined(__arm__) || defined(__aarch64__)
    closelog();
#endif

    return retval;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值