当前位置: 移动技术网 > IT编程>开发语言>.net > 使用Amazon AWS SNS 发送 SMS 消息 .net

使用Amazon AWS SNS 发送 SMS 消息 .net

2018年09月10日  | 移动技术网IT编程  | 我要评论

吴岳明,宝路捷车管家,长篇成人小说

1.浏览aws 开发人员指南

2.安装 aws sms net api : awssdk.simplenotificationservice

3.调用 amazonsimplenotificationserviceclient 发送sms

string defaultsenderid="appname";
string message = "[appname] enter this verification code 000000 in your app now.";//消息
string phonenumber = "+8618372712159";     //手机号
string defaultsmstype = "promotional";     //promotional – 不重要的消息|transactional – 为客户事务处理提供支持的重要消息
sms_entity mode = new sms_entity() { contents = message, mobilenumber = phonenumber };
try
{
    amazonsimplenotificationserviceclient snsclient = new amazonsimplenotificationserviceclient(awsaccesskeyid, awssecretaccesskey, regionendpoint.apsoutheast1);
    publishrequest publishreq = new publishrequest();
    publishreq.message = message;
    publishreq.phonenumber = phonenumber;
    publishreq.messageattributes = new dictionary<string, messageattributevalue>();
    publishreq.messageattributes.add("aws.sns.sms.senderid", new messageattributevalue() { datatype = "string", stringvalue = defaultsenderid });
    publishreq.messageattributes.add("aws.sns.sms.smstype", new messageattributevalue() { datatype = "string", stringvalue = defaultsmstype });
    publishresponse response = snsclient.publish(publishreq);
    mode.response = jsonconvert.serializeobject(response);
    mode.sendstatus = response.httpstatuscode.tostring();
    if (response.httpstatuscode == system.net.httpstatuscode.ok)
        mode.result = true;
    else
        mode.result = false;
}
catch (exception ex)
{
    mode.sendstatus = "error:" + ex.message;
    mode.result = false;
}

注意:awsaccesskeyid,awssecretaccesskey,regionendpoint,需要登陆aws的控制台查看

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网