为什么印度 phone 号码没有收到我通过 Amazon SNS 发送的 SMS 消息?
Why are my SMS messages sent via Amazon SNS not being received by Indian phone numbers?
我正在尝试在我的 Springboot 应用程序中使用 Amazon SNS 发送短信。
这是配置class:
@Configuration
@ConfigurationProperties("aws")
public class AwsConfig {
private String accessKeyId;
private String secretAccessKey;
public String getAccessKeyId() {
return accessKeyId;
}
public void setAccessKeyId(String accessKeyId) {
this.accessKeyId = accessKeyId;
}
public String getSecretAccessKey() {
return secretAccessKey;
}
public void setSecretAccessKey(String secretAccessKey) {
this.secretAccessKey = secretAccessKey;
}
public AWSStaticCredentialsProvider awsCredentials() {
BasicAWSCredentials credentials = new BasicAWSCredentials(accessKeyId, secretAccessKey );
return new AWSStaticCredentialsProvider(credentials);
}
@Bean
public AmazonSimpleEmailService getAmazonSimpleEmailService() {
return AmazonSimpleEmailServiceClientBuilder.standard().withCredentials(awsCredentials())
.withRegion("us-east-1").build();
}
@Bean
public AmazonSNS getAmazonSNS() {
return AmazonSNSClientBuilder.standard().withCredentials(awsCredentials())
.withRegion("us-east-1").build();
}
}
这是class发送消息:
@Service
public class SmsSendingServiceImpl {
@Autowired
private AmazonSNS amazonSNS;
public void sendSMS()
{
Map<String, MessageAttributeValue> smsAttributes = new HashMap<String, MessageAttributeValue>();
smsAttributes.put("AWS.SNS.SMS.SenderID", new MessageAttributeValue()
.withStringValue("SENDER")
.withDataType("String"));
smsAttributes.put("AWS.SNS.SMS.SMSType", new MessageAttributeValue()
.withStringValue("Transactional")
.withDataType("String"));
try {
PublishResult result = amazonSNS.publish(new PublishRequest()
.withMessage("This is a test sms.")
.withPhoneNumber("+91-**********").withMessageAttributes(smsAttributes));
System.out.println("Messsage Sent. "+result.getMessageId());
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
在调用 sendSMS()
时,我确实在控制台输出中收到了 Message Sent.
消息,但是提到的 phone 号码没有收到短信。
为此,我尝试了几种不同的 phone 数字。 None 他们正在接收任何消息。
可能值得一提的是,所有这些数字都是印度的。
有人可以指出这可能是什么原因吗?
我指的是 YouTube video。
您遇到的问题是,印度是一个对短信使用非数字发件人 ID 有特殊要求的国家。
基于 SNS 的 Supported Regions and countries 文档:
Country or region ISO code Supports sender IDs Supports two-way SMS (Amazon Pinpoint only)
India IN Yes3 Yes
请注意,印度的 Supports sender IDs 列标记为 Yes3。
注释部分指出:
- Senders are required to use a pre-registered alphabetic sender ID. Additional registration steps are required. For more information, see Special requirements for sending SMS messages to recipients in India.
为了你的origination identity, you can either have origination numbers or sender IDs.
在您的情况下,您不能选择使用原始号码,因为印度法律要求使用发件人 ID。
相反的情况也存在,因为加拿大、中国和美国等国家/地区要求使用原始号码(阅读:U.S. product number comparison for different number types for the number you need to purchase & the SMS cost calculator)。
来自AWS:
This feature (origination numbers) does not apply when sending SMS to countries where local limitations, laws, or regulations require the use of Sender Ids in the place of origination numbers, for example India.
因此,您必须遵循 Special requirements for sending SMS messages to recipients in India 指南。这就是上面需要额外的注册步骤的意思。
不幸的是,对于 AWS 显然需要遵守的当地国家/地区法律,没有解决方法。
也就是说,国内服务可能可以“规避”AWS的法律限制(因为它们domestic/may与电信等有特殊合同)。如果您不想to/can不注册发件人 ID,其他服务可能也值得一看。
我正在尝试在我的 Springboot 应用程序中使用 Amazon SNS 发送短信。
这是配置class:
@Configuration
@ConfigurationProperties("aws")
public class AwsConfig {
private String accessKeyId;
private String secretAccessKey;
public String getAccessKeyId() {
return accessKeyId;
}
public void setAccessKeyId(String accessKeyId) {
this.accessKeyId = accessKeyId;
}
public String getSecretAccessKey() {
return secretAccessKey;
}
public void setSecretAccessKey(String secretAccessKey) {
this.secretAccessKey = secretAccessKey;
}
public AWSStaticCredentialsProvider awsCredentials() {
BasicAWSCredentials credentials = new BasicAWSCredentials(accessKeyId, secretAccessKey );
return new AWSStaticCredentialsProvider(credentials);
}
@Bean
public AmazonSimpleEmailService getAmazonSimpleEmailService() {
return AmazonSimpleEmailServiceClientBuilder.standard().withCredentials(awsCredentials())
.withRegion("us-east-1").build();
}
@Bean
public AmazonSNS getAmazonSNS() {
return AmazonSNSClientBuilder.standard().withCredentials(awsCredentials())
.withRegion("us-east-1").build();
}
}
这是class发送消息:
@Service
public class SmsSendingServiceImpl {
@Autowired
private AmazonSNS amazonSNS;
public void sendSMS()
{
Map<String, MessageAttributeValue> smsAttributes = new HashMap<String, MessageAttributeValue>();
smsAttributes.put("AWS.SNS.SMS.SenderID", new MessageAttributeValue()
.withStringValue("SENDER")
.withDataType("String"));
smsAttributes.put("AWS.SNS.SMS.SMSType", new MessageAttributeValue()
.withStringValue("Transactional")
.withDataType("String"));
try {
PublishResult result = amazonSNS.publish(new PublishRequest()
.withMessage("This is a test sms.")
.withPhoneNumber("+91-**********").withMessageAttributes(smsAttributes));
System.out.println("Messsage Sent. "+result.getMessageId());
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
在调用 sendSMS()
时,我确实在控制台输出中收到了 Message Sent.
消息,但是提到的 phone 号码没有收到短信。
为此,我尝试了几种不同的 phone 数字。 None 他们正在接收任何消息。
可能值得一提的是,所有这些数字都是印度的。
有人可以指出这可能是什么原因吗?
我指的是 YouTube video。
您遇到的问题是,印度是一个对短信使用非数字发件人 ID 有特殊要求的国家。
基于 SNS 的 Supported Regions and countries 文档:
Country or region ISO code Supports sender IDs Supports two-way SMS (Amazon Pinpoint only)
India IN Yes3 Yes
请注意,印度的 Supports sender IDs 列标记为 Yes3。
注释部分指出:
- Senders are required to use a pre-registered alphabetic sender ID. Additional registration steps are required. For more information, see Special requirements for sending SMS messages to recipients in India.
为了你的origination identity, you can either have origination numbers or sender IDs.
在您的情况下,您不能选择使用原始号码,因为印度法律要求使用发件人 ID。
相反的情况也存在,因为加拿大、中国和美国等国家/地区要求使用原始号码(阅读:U.S. product number comparison for different number types for the number you need to purchase & the SMS cost calculator)。
来自AWS:
This feature (origination numbers) does not apply when sending SMS to countries where local limitations, laws, or regulations require the use of Sender Ids in the place of origination numbers, for example India.
因此,您必须遵循 Special requirements for sending SMS messages to recipients in India 指南。这就是上面需要额外的注册步骤的意思。
不幸的是,对于 AWS 显然需要遵守的当地国家/地区法律,没有解决方法。
也就是说,国内服务可能可以“规避”AWS的法律限制(因为它们domestic/may与电信等有特殊合同)。如果您不想to/can不注册发件人 ID,其他服务可能也值得一看。