2017-05-19 78 views
1

我正在嘗試使用AWS World Wide Messaging Service使用C#/ .Net Core。使用AWS SNS發送短信 - .Net核心

但是,我沒有收到我的電話號碼中的消息。下面是代碼:

public static async Task<PublishResponse> sendSMS() 
     { 

      string accessKey = "my Key"; 
      string secretAccessKey = "my secret key"; 
      var client = new AmazonSimpleNotificationServiceClient(accessKey, 
      secretAccessKey, RegionEndpoint.USEast1); 

      string phoneNumber = "my number"; 

      PublishRequest req = new PublishRequest(); 
      req.Message = "Hellloooo from core"; 
      req.PhoneNumber = "+2" + phoneNumber; 
      PublishResponse res = await client.PublishAsync(req); 
      return res; 
     } 

我在主函數中調用此方法:

public static void Main(string[] args) 
     { 
      var respond = sendSMS();  
     } 

我很感激,如果有人可以幫助我。在此先感謝

回答

-1

public static async Task<PublishResponse> SendMessageToMobileAsync(string countryCode, string mobileNumber, string message) 
 
    { 
 
     var accessKey = "xxx"; 
 
     var secretKey = "xxx"; 
 
     var client = new AmazonSimpleNotificationServiceClient(accessKey, secretKey, RegionEndpoint.USEast1); 
 
     var messageAttributes = new Dictionary<string, MessageAttributeValue>(); 
 
     var smsType = new MessageAttributeValue 
 
     { 
 
      DataType = "String", 
 
      StringValue = "Transactional" 
 
     }; 
 

 
     messageAttributes.Add("AWS.SNS.SMS.SMSType", smsType); 
 
     
 
     PublishRequest request = new PublishRequest 
 
     { 
 
      Message = message, 
 
      PhoneNumber = countryCode + mobileNumber, 
 
      MessageAttributes = messageAttributes 
 
     }; 
 

 
     return await client.PublishAsync(request); 
 

 
    }

+1

你應該說明你已經張貼在這裏什麼。我知道它是一個OP問題的解決方案,但是這個代碼實際上做了什麼?它是如何工作的? – stybl

+0

此代碼可用於通過AWS SNS向任何手機號碼發送交易文本消息。您只需要更改AWS賬戶的accessKey和secretKey即可。希望這可以幫助。 –