当前位置:网站首页>Implementation of API short message gateway based on golang
Implementation of API short message gateway based on golang
2022-07-27 03:47:00 【Julywhj】
The overall design of SMS Gateway
In the message system , The connection between SMS gateway and SMS channel is the core function . SMS gateway is the interface to provide services , All operations that need to send text messages need to be distributed to the corresponding channels through the SMS Gateway . Once shaped , There are few follow-up , It's also hard to adjust . The short message channel is to receive the request of the gateway , Call the channel interface to perform the real operation of sending SMS . The interface of each channel , The transmission modes are different , So here , The function of SMS Gateway relative to SMS channel module , Similar to... In design patterns wrapper, Encapsulate the differences of various channels , Present a unified interface to the gateway . The function of gateway is to provide general interface for business , Some public operations that interact with channels , It will also be placed in the gateway .
One 、 Function Overview
The services provided by the message system to other systems include channel management 、 Signature management 、 SMS template management 、 Application management 、 Business type management 、 SMS record management .
- Channel management : The short message gateway maintains multiple channel providers , Configure the identity of the channel provider ID、 identity key Other information , Supported channel providers : Tencent cloud 、 Alicloud, etc
- Signature management : Configure different SMS signatures under channel providers , Provide data basis for subsequent SMS sending .
- SMS template management : Configure different SMS template information , You can also select different template information in the business configuration , notes : Different channel templates are slightly different , For details, please refer to the instruction document .
- Application management : Configure the application information of SMS Gateway docking , You can configure the number of SMS messages available in the application management 、 Limit the number of messages per minute , Control the number of SMS messages used by different applications through the number of available applications .
- The business management : Configure the business scenario of sending SMS , Such as registered business 、 Log in to business 、 Order notice 、 Payment success notification and other different business information . After adding business information , Generate business number , The business system sends the SMS template according to the business number .
Two 、 The overall architecture

smsGolang
3、 ... and 、 Management platform

Jiezi learning programming - Channel configuration

Jiezi learning programming - Add channel providers

Jiezi learning programming - SMS signature template

Jiezi learning programming - Add SMS signature

Jiezi learning programming - Template list

Jiezi learning programming - Add SMS template

Jiezi learning programming - Application management

Jiezi learning programming - Add application

Jiezi learning programming - Business template configuration

Jiezi learning programming - Add a business template

Jiezi learning programming - Send records

Jiezi learning programming - Send SMS test page
Four 、 service API
Request address :/api/v1/send-message
Request mode :POST
Request parameters :
| Field name | Field description | Field type | If required | remarks |
|---|---|---|---|---|
| businessNo | Business number | String | yes | |
| phones | Mobile number collection | List | yes | Multiple cell phone numbers "," Division |
| params | Template filling parameters | List | no | Multiple parameters "," Division |
Sample request parameters :
{
"businessNo": "B-000003",
"phones": [
"+86182XXXXXX68"
],
"params": ["123456"]
}
Response parameter :
| Field name | Field description | Field type | If required | remarks |
|---|---|---|---|---|
| requestId | requestId | String | yes | |
| code | Status code | Int | yes | |
| msg | The channel returns a message | String | yes | |
| data | The response data | Int | no |
Examples of response parameters :
{
"requestId": "b9c0fd5e-3a43-4039-a224-2a5ae99385e1",
"code": 200,
"msg": "{\"sms_send_status\":[{\"fee\":1,\"message\":\"OK\",\"code\":\"OK\",\"phone\":\"+8618232533068\"}],\"request_id\":\"771D1C9C-74AD-582E-B5EB-5FB12C038497\"}",
"data": 200
}
nothing 、 Database design
5.1 SMS channel configuration table
Configure different channel information , Like Tencent cloud 、 Alibaba cloud 、 Qiniuyun and so on
sms_service_provider_config ( Service provider configuration table )
| Field name | Field description | Field type | If required | remarks |
|---|---|---|---|---|
| channel_no | Channel programming | String | yes | Tencent、AliYun |
| provider_name | Service provider name | String | yes | Alibaba cloud 、 Tencent cloud |
| provider_no | Service provider number | String | yes | Aly、txy |
| access_key_id | Identification | String | yes | tencent :SecretId |
| access_key_secret | Authentication key | String | yes | tencent :SecretKey |
| endpoint | Call domain name | String | yes | |
| sdk_app_id | application ID | String | no | Tencent cloud is required |
| region | List of regions | String | no | Tencent cloud is required :ap-beijing、ap-guangzhou、ap-nanjing |
| remark | remarks | String | no | |
| ext_json | Extension field | String | no | |
| status | state | Bool | yes | 1 Enable 0 Ban |
5.2 SMS signature configuration table
sms_sign_config( SMS signature configuration table )
| Field number | Field description | Field type | If required | remarks |
|---|---|---|---|---|
| sign_name | Signature name | String | yes | |
| provider_no | Service provider number | String | yes | Aly、txy |
| provider_name | Service provider name | String | yes | |
| remark | remarks | String | no | |
| ext_json | Extension field | String | no | |
| status | state | Bool | yes | 1 Enable 0 Ban |
5.3 SMS template configuration table
sms_template_config( SMS template configuration table )
| Field number | Field description | Field type | If required | remarks |
|---|---|---|---|---|
| sign_name | Signature name | String | yes | |
| provider_no | Service provider number | String | yes | Aly、txy |
| template_no | Template number | String | yes | |
| template_content | Template content | String | yes | |
| third_party_template_no | Third party template number | String | yes | |
| remark | remarks | String | no | |
| ext_json | Extension field | String | no | |
| status | state | Bool | yes | 1 Enable 0 Ban |
3.4 Application configuration table
sms_app_config ( Application management configuration table )
| Field number | Field description | Field type | If required | remarks |
|---|---|---|---|---|
| app_no | application ID | String | yes | |
| app_name | apply name | String | yes | Aly、txy |
| available_number | Quantity available | Int | yes | Available SMS packages |
| current_limiting | Current limiting quantity | Int | yes | The number of messages allowed to be sent per minute |
| use_number | Used quantity | Int | yes | |
| remark | remarks | String | no | |
| ext_json | Extension field | String | no | |
| status | state | Bool | yes | 1 Enable 0 Ban |
5.5 Business configuration table
sms_business_config( Business configuration table )
| Field number | Field description | Field type | If required | remarks |
|---|---|---|---|---|
| app_no | application ID | String | yes | |
| business_name | Business name | String | yes | Aly、txy |
| business_no | Business number | String | yes | |
| template_no | Template number | String | yes | |
| business_desc | Business description | String | no | |
| remark | remarks | String | no | |
| ext_json | Extension field | String | no | |
| status | state | Bool | yes | 1 Enable 0 Ban |
5.6 Send log table
sms_send_log( Send record sheet )
| Field number | Field description | Field type | If required | remarks |
|---|---|---|---|---|
| app_no | application ID | String | yes | |
| business_no | Business number | String | yes | |
| status | state | Int | yes | |
| fee | Number of pricing items | Int | yes | |
| phone_number | Send mobile number | String | yes | |
| message | Interface response message | String | yes | |
| code | Interface response status code | String | yes | |
| content | send content | String | yes | |
| remark | remarks | String | no | |
| ext_json | Extension field | String | no |
6、 ... and 、 Technology stack
Jiezi learning programming (julywhj.cn)
Mysql、Redis、
7、 ... and 、 Source code
Official account : Jiezi learning programming , reply : " SMS Gateway " obtain .

边栏推荐
- Code review pyramid
- OC message mechanism
- 复盘:图像有哪些基本属性?关于图像的知识你知道哪些?图像的参数有哪些
- 在typora中插入图片和视频
- Principle understanding and application of hash table and consistent hash
- 【无标题】JDBC连接数据库读超时
- Typescript TS basic knowledge interface, generics
- 复盘:DFS与BFS的主要区别,在思想上的区别,代码实现上的区别
- Connman introduction
- Csu18m91 is used as the master controller of the intelligent scale scheme
猜你喜欢

客户端发送一条sql如何与服务器交互

Smart pointer shared_ ptr、unique_ ptr、weak_ ptr

Introduction to database - Introduction to database

Learning and understanding of four special data types of redis

Duplicate disc: what are the basic attributes of an image? What do you know about images? What are the parameters of the image

关于使用hyperbeach出现/bin/sh: 1: packr2: not found的解决方案

Cocos game practice-04-collision detection and NPC rendering

Basic concept and essence of Architecture

Introduction to database - a brief introduction to MySQL

MySQL中文失败问题
随机推荐
Spark Learning Notes (IV) -- spark core programming RDD
Binary tree (Beijing University of Posts and Telecommunications machine test questions) (day85)
若依的环境的部署以及系统的运行
[regular] judgment, mobile number, ID number
flask_restful中reqparse解析器继承
Deeply understand the underlying data structure and algorithm of MySQL index
Safe-arc/warner power supply maintenance xenon lamp power supply maintenance analysis
connman介绍
MySQL的数据库有关操作
The application and significance of digital twins are the main role and conceptual value of electric power.
Record the problem of PHP program accessing system files incorrectly
基于OpenCV的轮廓检测(1)
Double disk: the main differences between DFS and BFS, the differences in ideology, and the differences in code implementation
MySQL中文失败问题
About the solution of using hyperbeach to appear /bin/sh: 1: packr2: not found
Explain
数据库概论 - 数据库的介绍
Maximum continuous subsequence (day 77)
一种分布式深度学习编程新范式:Global Tensor
基于OpenCV的轮廓检测(2)