简体   繁体   English

混淆使用aws发送短信[更新:短信交付太晚了]

[英]Confused sending sms using aws [Updated: sms is delivered soo late]

I'm writing a program that sends SMS using the AWS SNS service. 我正在编写一个使用AWS SNS服务发送SMS的程序。 I am new to this topic. 我是这个话题的新手。 So I've tried one of the codes available online. 所以我尝试了在线提供的一个代码。

and the code is as below. 代码如下。

var AWS = require('aws-sdk');

AWS.config.region = 'your aws region';
AWS.config.update({
    accessKeyId: "your access id",
    secretAccessKey: "your secret access key",
});

var sns = new AWS.SNS();
var params = {
    Message: "your message",
    MessageStructure: 'string',
    PhoneNumber: 'phone_number_without_+',
    Subject: 'your subject'
};

sns.publish(params, function (err, data) {
    if (err) console.log(err, err.stack); // an error occurred
    else console.log(data);           // successful response
});

Here I've filled the entire data from my AWS console like Region , accessKey and secretAccessKey , my mobile number , Subject and message . 在这里,我已经从我的AWS控制台填充了整个数据,例如RegionaccessKeysecretAccessKey ,我的mobile numberSubjectmessage post filling this when I try to run this, I get the below response. 当我试图运行这个时填充这个,我收到以下回复。

{ ResponseMetadata: { RequestId: '30d54840-1aa8-5ad4-8de7-19cad1ed033f' },
  MessageId: '7cc1d99e-b835-5015-b84e-88147370a9fe' }

but there is no sms delivered to my mobile. 但没有短信发送到我的手机。

I thought that the service is not available in my country and then tried sending the message from SMS console shown below. 我认为该服务在我的国家/地区不可用,然后尝试从下面显示的SMS控制台发送消息。 I received a text message on my mobile. 我在手机上收到了一条短信。

在此输入图像描述

Here I'm not using any topic and I need to send message individually, there is no bulk message to be sent. 这里我没有使用任何topic ,我需要单独发送消息,没有要发送的批量消息。

Please guide me on where am I going wrong and how can I fix this. 请指导我哪里出错了,我该如何解决这个问题。

Thanks 谢谢

Update 更新

Thanks for the quick test balent . 感谢快速测试人才

This thing is working, the saddest part is that the message is delivered after 9 hrs. 这件事情正在发挥作用,最悲伤的部分是9小时后发出的消息。 I'm in India and our code starts something like this +91XXXXXXXXXX and I did the same. 我在印度,我们的代码开始像这样+91XXXXXXXXXX ,我做了同样的事情。 But when tried through the console(SMS screenshot), the message was instant, can someone please shower some light on how this can be fixed. 但是当通过控制台尝试(短信截图)时,消息是即时的,有人可以告诉我们如何解决这个问题。 ie the sms to be sent instantly. 即即时发送的短信。

Thank you for your question and updated answer, to reduce time of delivery in India, setting the attribute DefaultSMSType to "Transactional" delivered it immediately. 感谢您的问题和更新的答案,以减少在印度的交货时间,将属性DefaultSMSType设置为“Transactional”立即交付。

sns.setSMSAttributes( { attributes : { DefaultSMSType : "Transactional" } }, function(error){ if(error){ console.log(error); } } );

Explanation- there are two types one is promotional which is default, and not time critical and one is transactional, time critical used for otp. 解释 - 有两种类型,一种是促销,它是默认的,而不是时间关键的,一种是交易的,时间关键用于otp。 There is a price difference I suppose in using either of the options. 我认为在使用任一选项时存在价格差异。 Upon reading your answer I tried the way you did and the sms were delayed, so I used the api given here to change to transactional and it gave instant messages. 在阅读你的答案后,我尝试了你的方式并且短信被延迟了,所以我使用这里给出的api改为事务性,它给了即时消息。

http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#publish-property http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#publish-property

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM