Home  >  Article  >  Backend Development  >  ASP.NET MVC Ali is greater than the SMS interface to develop SMS group sending capabilities

ASP.NET MVC Ali is greater than the SMS interface to develop SMS group sending capabilities

高洛峰
高洛峰Original
2016-12-24 13:50:461632browse

There are many companies on the Internet that provide SMS interface services, such as NetEase Yunxin, Alibaba, etc. I need to use the SMS service for notification in my project. The actual development cycle is three days to complete the configuration, development and use. Generally speaking, the interface provided by Alibaba is easy to develop and very convenient. The SMS fee is calculated and paid. , as an individual developer, the cost of the service business I use is 0.045¥/item (less than 100,000 items).

Now we want to implement the function of sending group SMS notifications for regular meetings. All the notified object information is stored in Mysql, and the application architecture adopts asp.net MVC. First, prepare the API items to be obtained (the following service parameters need to be applied on the official website),

ASP.NET MVC阿里大于短信接口开发短信群发能

Apply for your own SMS signature and SMS template. These parameters are required according to the requirements of the service provider:

ITopClient client = new DefaultTopClient(url, appkey, secret);
AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
req.Extend = "" ;//可空,返回状态
req.SmsType = "normal" ;//不可更改
req.SmsFreeSignName = "" ;//申请的短信签名,不可填写与申请的不一
req.SmsParam = "" ;//短信模板中的变量如:{name}
req.RecNum = "13000000000" ;//手机号码
req.SmsTemplateCode = "" ;//短信模板的编号,不可出错
AlibabaAliqinFcSmsNumSendResponse rsp = client.Execute(req);
Console.WriteLine(rsp.Body);

During the specific development, it should be noted that this piece of code is an official sample. When writing the method of sending SMS messages, just paste it and then develop it. The pairing of template variables is particularly critical:

req.SmsParam = "" ;//The variables in the SMS template are such as: {name}

In this case, you need to have basic skills in string splicing, because it is a json-like ified, so

req.SmsParam ="{number:'" + Password + "'}";//Removing the double quotes is {number: 'Password'}

After finishing the details, start on the local machine The compiled dll is referenced in the project on. The dll file can be downloaded from the Alibaba official website https://www.alidayu.com/center/application/sdk. The zip package can be downloaded and decompressed to get the generated dll. Then write a A void method that can send text messages,

public void SmsSendForFindPassword(string phonenum,string Password)
 {
 string url = "https://eco.taobao.com/router/rest";
 string appkey = "********";
 string secret = "**********************";
 ITopClient client = new DefaultTopClient(url, appkey, secret);
 AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
 req.Extend = "";
 req.SmsType = "normal";//默认normal不可改动
 req.SmsFreeSignName = "院红会网宣";//短信签名必填
 req.SmsParam = "{number:'" + Password + "'}";//模板内参数必填
 req.RecNum = phonenum;//手机号码必填
 req.SmsTemplateCode = "SMS_******";//不可改动
 AlibabaAliqinFcSmsNumSendResponse rsp = client.Execute(req);
 }

This method was developed by me for administrators to retrieve passwords. It should be noted that the parameters phonenum and Password are passed in and must be retrieved from the database before being passed in. Is empty.

ITopClient client = new DefaultTopClient(url, appkey, secret);

There are two official URLs. I prefer https, which makes data transmission more secure. For specific choices, please refer to Alibaba official website documentation.

AlibabaAliqinFcSmsNumSendResponse rsp = client.Execute(req);

//After this object is instantiated, it is the last step of the api sending method call. Before that, every item must be correct. If there is an error, you can use Console.WriteLine (rsp.Body);

//Display error message

 For how to implement the group sending function, write a SendSmsForMeetingTime(string name, string time, string phonenum, string department, string minister) method function. I used List< ;Model>, read multiple pieces of data from the database into the List, use foreach (var item in list), call SendSmsForMeetingTime once in each traversal; when the traversal is completed, the information of each notification object is passed into the method parameters , after the method is executed, the call is implemented.

 Here is a description of the interface call and the process of text messages. User client/user server——>Alibaba server——>Mobile/Telecom/Unicom operator server——>The object can accept SMS service terminal. In fact, Alibaba also calls the operator's interface, but Alibaba encapsulates the interface for cheap development, and our developers can complete third-party interface development on this basis. These developments are only limited to which interfaces are encapsulated by the service provider. , developers cannot call interfaces that are not encapsulated by the service provider.

The above is my practical experience in calling API in actual projects. The project has also been tested by users, and there is no problem at present. This also shows that Alibaba is more efficient in the SMS interface service, and the efficiency of information transmission is still the conscience of the industry. .

The above is the entire content of this article. I hope it will be helpful to everyone’s learning. I also hope that everyone will support the PHP Chinese website.


For more related articles on ASP.NET MVC Alibaba SMS interface development for SMS group sending, please pay attention to the PHP Chinese website!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn