sending sms from java web app using aws sns

后端 未结 4 1886
星月不相逢
星月不相逢 2021-02-10 18:50

A user will create an account on my web app. The app will need to authenticate the user by sending a text message to the mobile phone number that the user provides. The text m

4条回答
  •  心在旅途
    2021-02-10 19:18

    Some methods have been deprecated in AWS SDK.

    BasicAWSCredentials awsCredentials = new BasicAWSCredentials("CLIENT-ID", "SECRET-KEY");
    AmazonSNS snsClient = AmazonSNSClientBuilder.standard()
                         .withRegion(Regions.fromName("YOUR_REGION"))
         .withCredentials(new AWSStaticCredentialsProvider(awsCredentials)).build();
    
    Map smsAttributes = new HashMap();
    smsAttributes.put("AWS.SNS.SMS.SenderID",new MessageAttributeValue().withStringValue("SENDER-ID").withDataType("String");
    smsAttributes.put("AWS.SNS.SMS.SMSType",new MessageAttributeValue().withStringValue("Transactional").withDataType("String"));
    
    PublishRequest request = new PublishRequest();
    request.withMessage("YOUR MESSAGE")
    .withPhoneNumber("E.164-PhoneNumber")
    .withMessageAttributes(smsAttributes);
    PublishResult result=snsClient.publish(request);
    

提交回复
热议问题