Monday, April 5, 2021

Send Transactional SMS with API

This post cover how to send transactional SMS using the Alibaba Cloud Short Message Service API.

Transactional SMS usually come with One Time PIN (OTP) to verify the user identity who is using your app. It is considered as one of the common two factor authentication method. The OTP is unique and bind to a specific account and it is generated using hash algorithm. The hash algorithm I would recommend is HMAC based one time password, for more details please refer to this Wiki: https://en.wikipedia.org/wiki/HMAC-based_One-Time_Password. You may also find a lot sample code library available from Google.

Prior in calling the Short Message Service API from your system, you need to create an Access Key first. You need the access key to get authorized to invoke the API method to send SMS.



After creating an Access Key, you can go to the Developer Guide to check out the sample code. I find that Alibaba Cloud have done a very good job in online documentation and even provide a real time interpreter to test the source code on the fly which actually help improving the learning curve of the developer. It allow the developer perform code modification directly from the browser and test the code and monitor the difference.


The highlighted yellow text below from the sample source code is the place where you need to modify base on the Access Key that you had generated earlier. The aqua text below is where you put your HMAC One Time Password.

using System;
using System.Collections.Generic;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Core.Http;

namespace CommonRequestDemo
{
class Program
{
static void Main(string[] args)
{
IClientProfile profile = DefaultProfile.GetProfile("ap-southeast-1", "<accessKeyId>", "<accessSecret>");
DefaultAcsClient client = new DefaultAcsClient(profile);
CommonRequest request = new CommonRequest();
request.Method = MethodType.POST;
request.Domain = "dysmsapi.ap-southeast-1.aliyuncs.com";
request.Version = "2018-05-01";
request.Action = "SendMessageToGlobe";
// request.Protocol = ProtocolType.HTTP;
request.AddQueryParameters("To", "601612312312");
request.AddQueryParameters("Message", "Your OTP is 123456 from Alibaba Cloud");

try {
CommonResponse response = client.GetCommonResponse(request);
Console.WriteLine(System.Text.Encoding.Default.GetString(response.HttpResponse.Content));
}
catch (ServerException e)
{
Console.WriteLine(e);
}
catch (ClientException e)
{
Console.WriteLine(e);
}
}
}
}

The following link contain all the possible error codes which is useful for you to troubleshoot any issue when you attempt to send SMS.

5 comments:

  1. The best promotional sms software

    and SMS marketing software for lead generation. Get a free mass texting

    software demo with customer ...

    ReplyDelete
  2. Bulk sms is for business of all sizes and budget.
    Bulk SMS stands for Short Message Service and refers to the
    sending of short text messages from one device to another in most cases
    from one mobile phone.


    ReplyDelete
  3. The best trasnctionalsms

    software and SMS marketing software for lead

    generation. Get a free mass texting software demo

    with customer ...

    ReplyDelete
  4. The best mass sms

    software and SMS marketing software for lead

    generation. Get a free mass texting software demo

    with customer ...

    ReplyDelete

Send Transactional SMS with API

This post cover how to send transactional SMS using the Alibaba Cloud Short Message Service API. Transactional SMS usually come with One Tim...