Dinstar GSM Gateway HTTP API (v201910)
Dinstar GSM Gateway HTTP API (v201910)
Dinstar GSM Gateway HTTP API (v201910)
I
Introduction of API
Change Logs
Version 1.1 2019-10-16
1. Add ‘get_status’ to API.
II
Introduction of API
Contents
User Manual V2.1............................................................................................................................... I
Version 1.1 2019-10-16 ...................................................................................................................................... II
Version 1.0 2016-12-8 ........................................................................................................................................ II
Version 0.5 2015-7-22 ........................................................................................................................................ II
Version 0.4 2015-4-24 ........................................................................................................................................ II
Version 0.3 2015-3-20 ........................................................................................................................................ II
Version 0.2 2015-1-22 ........................................................................................................................................ II
Version 0.1 2014-12-25 ...................................................................................................................................... II
III
Introduction of API
6 Receive SMS................................................................................................................................. 11
6.1 Request ........................................................................................................................................................... 11
6.2 Request Parameter .......................................................................................................................................... 11
6.3 Response Parameter ....................................................................................................................................... 11
6.4 Example of Receiving SMS ........................................................................................................................... 12
6.5 Suggestion ...................................................................................................................................................... 12
IV
Introduction of API
19 NAT .............................................................................................................................................. 36
19.1 Application Scenarios ................................................................................................................................... 36
19.2 Configuration section ................................................................................................................................... 36
19.3 API Changes ................................................................................................................................................. 37
20 FAQ .............................................................................................................................................. 38
20.1 How can you specify a port for sending SMS? ............................................................................................ 38
20.2 How to match an SMS sending result with an SMS sending request? ......................................................... 38
V
Introduction of API
VI
Introduction of API
1 Introduction of API
1.1 Application Scenarios
API enables an SMS server to communicate with lots of gateways, and then users can send
and receive SMS through this server.
Internet Internet
2) Please enable the API function before your test. On the web interface of the gateway, select
Mobile Configuration Basic Configuration in the menu bar, and then select new-version
API. Only version 1102 or later version of the gateway supports the new-version API.
1
Introduction of API
a) The gateway supports 2 types of encoding, namely GSM 7 bit and UCS2. GSM 7bit is
suitable for sending messages that contain ASCII and some Latin alphabets, while UCS2 is
suitable for sending anything, including Chinese, Korean, Japanese and even emoji .
b) For GSM 7bit, it is possible to send up to 160 characters (packed in up to 140 octets) in one
SMS message. But for UCS2, one SMS message could only contain 70 characters at
maximum.
c) The gateway supports Concatenated_SMS, which means the gateway will split your long
messages into smaller SMS.
2
Send SMS
2 Send SMS
2.1 Request
POST https://gateway_ip/api/send_sms
Optional Parameter
port Array of Integer Number of port for sending SMS
Each port number should be an integer, ranging
from 0 to 31
encoding String It can be ‘unicode’or ‘gsm-7bit’
Default is ‘unicode’
request_status_report Boolen It is used to determine whether to use SMS
status report. It can be true or false
Default is true
3
Send SMS
Note:
1. The example above comes with the default username and password.
Use the real username and password of your own gateway.
Response:
{"error_code":202,
"sn":"xxxx-xxxx-xxxx-xxxx","sms_in_queue":2,"task_id":2}
4
Query SMS Sending Result
3.1 Request
POST https://gateway_ip/api/query_sms_result
user_id Array of Integers Each user ID here is used to match the user ID carried
in Send Sms Request
This user_id is the unique value which is set during
sending SMS. (refer to “send SMS”, “Request
parameters”)
This parameter is recommended for practice.
5
Query SMS Sending Result
result Array of Objects Results of SMS sending; Each result includes the
following information:
port: port for sending SMS
number: destination number of the sent SMS
user_id: match with the user ID carried in SMS
sending request
time: the time of sending SMS
status: sending status, which could be FAILED,
SENDING, SENT_OK and DELIVERED
count: count of SMS segments. A long SMS message
is divided into several segments and then is sent.
succ_count: count of SMS segments that are sent
successfully
ref_id: the first reference ID of this SMS, which is
used to match SMS delivery status. The range of
reference ID is from 0 to 255. Reference ID is
generally used together with telephone number, port
number and even sending time to match a delivery
status
imsi: IMSI of the SIM card.
Response:
{"error_code":200,"sn":"xxxx-xxxx-xxxx-xxxx","result":[{"port"
:0,"user_id":1,"number":"12351","time":"2014-12-21
12:06:01","status":"SENT_OK","count":3, "succ_count":3,
"ref_id":12,"imsi":"460004642148063"}]}
6
Query SMS Sending Result
{"sn":"xxxx-xxxx-xxxx-xxxx","sms_result":[{"port":1,"number":"
10086","time":"2016-07-12
01:46:02","status":"DELIVERED","count":1,"succ_count":1,"ref_i
d":215,"imsi":"460004642148063"}]}
7
Query SMS Delivery Status
4.1 Request
POST https://gateway_ip/api/query_sms_deliver_status
8
Query SMS Delivery Status
Response:
{"error_code":200,"sn":"xxxx-xxxx-xxxx-xxxx","result":[{"port"
:0, "number":"12341234","time":"2014-12-21 12:06:01","ref_id":12,
"status_code":0,"imsi":"460004642148063"}]}
{"sn":"xxxx-xxxx-xxxx-xxxx","sms_deliver_status":[{"port":1,"n
umber":"10086","time":"2016-07-12
15:46:53","ref_id":215,"status_code":0,"imsi":"460004642148063
"}]}
9
Query Number of SMS Messages to Be Sent
5.1 Request
GET https://gateway_ip/api/query_sms_in_queue
http://gateway_ip/api/query_incoming_sms
Response:
{"error_code":200,"sn":"xxxx-xxxx-xxxx-xxxx","in_queue":0}
10
Receive SMS
6 Receive SMS
6.1 Request
GET https://gateway_ip/api/query_incoming_sms
Optional Parameter
11
Receive SMS
https://gateway_ip/api/query_incoming_sms?flag=all
Response:
{"error_code":200,"sn":"xxxx-xxxx-xxxx-xxxx","sms":[{"incoming
_sms_id":1, "port":2, "number":
"123456789","smsc":"+8613800123456","timestamp":"2014-12-09
17:11:18","text":"This is a test"},],"read":1, "unread":0}
{"sn":"da00-0030-1901-2817","sms":[{"incoming_sms_id":1,"port"
:1,"number":"6717","smsc":"+8613800757511","timestamp":"2016-0
7-12 15:46:18","text":"test"}]}
6.5 Suggestion
1. Use Push Service for getting SMS.
12
Send USSD
2. Incoming sms id should be increased every time. For example, First request, without
incoming_sms_id is OK. But Seconde request, the incoming_sms_id should be the max id in
the first response.
7 Send USSD
7.1 Request
POST https://gateway_ip/api/send_ussd
Optional Parameter
command String It can be "send" or "cancel"; default value is "send"
13
Send USSD
Response:
{"error_code":202,"sn":"xxxx-xxxx-xxxx-xxxx","result":[{"port"
:0, "status":503},{"port":1, "status":503},{"port":2,
"status":200}]}
14
Query USSD Reply
15
Query USSD Reply
Response:
{"error_code":200,"sn":"xxxx-xxxx-xxxx-xxxx","reply":[{"port":
1, "text":" "},{"port":2, "text": "Test…"},{"port":3, "text":
""}]}
16
Stop SMS Sending Task
9.1 Request
GET https://gateway_ip/api/stop_sms
https://gateway_ip/api/stop_sms?task_id=1
Response:
{"error_code":200,"sn":"xxxx-xxxx-xxxx-xxxx"}
17
Get Port Information of Gateway
10.1 Request
GET https://gateway_ip/api/get_port_info
18
Get Port Information of Gateway
https://gateway_ip/api/get_port_info?port=1,2,3&info_type=imei
,imsi,iccid,smsc,type,number,reg,slot,callstate,signal,gprs,re
main_credit,remain_monthly_credit,remain_daily_credit:,remain_
daily_calltime,remain_hourly_calltime,remain_daily_connect
Response:
{"error_code":200,"sn":"xxxx-xxxx-xxxx-xxxx","info":[{"port":1,
"type":"WCDMA","imei":"863070017005173","imsi":"","iccid":"","
19
Get Port Information of Gateway
smsc":"","number":"","reg":"NO_SIM","callstate":"Idle","signal
":0,"gprs":"detached","remain_credit":"1000.00","remain_monthl
y_credit":"500.00","remain_daily_credit":"300.00","remain_dail
y_call_time":"100","remain_hourly_call_time":"10","remain_dail
y_connected":"100"},{"port":2,
"type":"GSM","imei":"358967042917201","imsi":"460016529802215"
,"iccid":"89860114840400428150","smsc":"+8613010868500","numbe
r":"","reg":"REGISTER_OK","callstate":"Idle","signal":0,"gprs"
:"detached","remain_credit":"1000.00","remain_monthly_credit":
"500.00","remain_daily_credit":"300.00","remain_daily_call_tim
e":"100","remain_hourly_call_time":"10","remain_daily_connecte
d":"100"},{"port":3,
"type":"GSM","imei":"358967042917201","imsi":"","iccid":"","sm
sc":"","number":"","reg":"NO_SIM","callstate":"Idle","signal":
0,"gprs":"detached","remain_credit":"1000.00","remain_monthly_
credit":"500.00","remain_daily_credit":"300.00","remain_daily_
call_time":"100","remain_hourly_call_time":"10","remain_daily_
connected":"100"}]}
20
Set Port Information of Gateway
11.1 Request
GET https://gateway_ip/api/set_port_info
21
Set Port Information of Gateway
https://gateway_ip/api/set_port_info?port=1&action=power¶m
=off
Response:
{"error_code":200,"sn":"xxxx-xxxx-xxxx-xxxx”}
22
Get CDR
12 Get CDR
12.1 Request
POST https://gateway_ip/api/get_cdr
23
Get CDR
Response:
{"error_code":200,"sn":"xxxx-xxxx-xxxx-xxxx","cdr":[{"port":2,
"start_date":"2015-07-21 16:35:20","answer_date":"2015-07-21
16:35:31","duration":3,"source_number":"1010","destination_num
ber":"6717","direction":"ip->gsm","ip":"172.16.100.136","codec
":"G.711U","hangup":"called","gsm_code":16,"bcch":""}]}
24
Query STK Info
13.1 Request
GET https://gateway_ip/GetSTKView
Required Parameter
port Integer
25
Query STK Info
http://gateway_ip/GetSTKView?port=0
Response:
{"title":"神州行天地
","item":[{"item_id":1,"item_string":"item1_text"},{"item_id":
2,"item_string":"itme2_text"},{"item_id":3,"item_string":"item
3_text"}],"input_type":"2,"frame_id":750}
26
STK Operation
14 STK Operation
14.1 Request
POST https://gateway_ip/STKGo
Required Parameter
port Integer
Optional Parameter
item Integer
param String
27
Query Frame ID of STK
15.1 Request
GET https://gateway_ip/GetSTKCurrFrameIndex
Required Parameter
port Integer
frame_id Integer
https://gateway_ip/GetSTKCurrFrameIndex?port=0
Response:
{"frame_id":32}
28
Get Device Status
16.1 Request
POST https://gateway_ip/api/get_status
Required Parameter
performance
16.4 Example
Request:
29
Get Device Status
Response:
{"performance":{"cpu_used":"39","flash_total":"27648","flash_used":"17428","
memory_total":"109448","memory_cached":"34192","memory_buffers":"0","memory_
free":"58928","memory_used":"50520"}}
30
Push Event
17 Push Event
In the latest version, the gateway can push some events such as SMS, SMS sending results
and SMS delivery status to your web server.
Once you selected push SMS, all SMS messages received by the gateway will be pushed to
your web server. The context of SMS pushing is very similar to the response of querying
incoming sms.
{"sn":"xxxx-xxxx-xxxx-xxxx","sms":[{"incoming_sms_id":1,"port"
:1,"number":"6717","smsc":"+8613800757511","timestamp":"2016-0
7-12 15:46:18","text":"test"}]}
The result of SMS pushing is similar to the response of Query Send SMS Result.
{"sn":"xxxx-xxxx-xxxx-xxxx","sms_result":[{"port":1,"number":"
10086","time":"2016-07-12
01:46:02","status":"DELIVERED","count":1,"succ_count":1,"ref_i
d":215,"imsi":"460004642148063"}]}
31
Push Event
USSD
{"sn":"xxxx-xxxx-xxxx-xxxx","ussd":[{"port":1,"text":"Thank
you!"}]}
{"sn":"xxxx-xxxx-xxxx-xxxx","register":[{"port":8,"iccid":"<NUL
L>","imsi":"<NULL>","number":"13714637674","status":"down","seq
uence":1,"slot":2}]}
Note: Multi-SIM gateway will push SIM Register Status with “slot”.
CDR:
{"sn":"xxxx-xxxx-xxxx-xxxx","cdr":[{"port":2,"start_date":"201
5-07-21 16:35:20","answer_date":"2015-07-21
16:35:31","duration":3,"source_number":"1010","destination_num
ber":"6717","direction":"ip->gsm","ip":"172.16.100.136","codec
":"G.711U","hangup":"called","gsm_code":16,"bcch":""}]}
Note: Only answered call will be pushed. For All the CDR, please ues “get_cdr”
Device:
{"sn":"xxxx-xxxx-xxxx-xxxx","device":{"port_number":32,"IP":"1
72.18.55.142","MAC":"F8-A0-3D-48-E5-19","status":"power_off"}}
{"sn":"xxxx-xxxx-xxxx-xxxx","device":{"port_number":32,"IP":"1
72.18.55.142","MAC":"F8-A0-3D-48-E5-19","status":"power_on"}}
Abnormal:
{"sn":"xxxx-xxxx-xxxx-xxxx","exception_info":{"port":0,"type":
"call_fail","action":"reset"}}
32
CALL Forward
18 CALL Forward
33
CALL Forward
34
CALL Forward
18.7 Example
1. Set call forward
https://gateway_ip/api/set_port_info?port=8&action=CallForward¶m=Uncondi
tional&number=15013828917
{"error_code":200,"sn":"xxxx-xxxx-xxxx-xxxx"}
https://gateway_ip/api/set_port_info?port=8&action=CheckCallForward
{"error_code":200,"sn":"xxxx-xxxx-xxxx-xxxx"}
3. Get result
https://gateway_ip/api/get_port_info?port=8&info_type=CallForward
{"error_code":200,"sn":"xxxx-xxxx-xxxx-xxxx","info":[{"port":8,"CallForwardi
ng":{"Unconditional":"15013828917"}}]}
35
NAT
19 NAT
36
NAT
(1) Connect to the DRP server and send the password of the account for authentication
Request: https://drpserver_ip:port/doLogin?Username=admin&password=admin
After the DRP server authentication passes, it returns 200 OK, indicating that the server
accepts the subsequent requests from the API client;
(2) After passing the authentication, send the device serial number to the DRP server:
After the DRP server matches the corresponding device, it replies 200 OK, indicating that
subsequent requests of the API client are forwarded to the device specified by the serial
number;
(3) Follow-up according to the specific function to send the corresponding request, see the
API specific usage (the model api client requests are sent to the DRP server);
37
FAQ
20 FAQ
SMS delivery status is received by gateway in unspecific time. It is connected with an SMS
sending result by a ref_id. And it is better to query delivery status after SENT_OK is
returned. For a long SMS message which will be divided into 3 smaller SMS segments, if the
first ref_id in SMS sending result is 0 and those of other two SMS segments are 1 and 2
respectively, at least 3 delivery statuses will be received, carrying ref_id 0, 1 and 2
respectively.
38
FAQ
curl libcurl
CURLOPT_SSL_VERIFYPEER,
-k
CURLOPT_SSL_VERIFYHOST,
-u CURLOPT_USERPWD
--anyauth CURLOPT_HTTPAUTH
-H CURLOPT_HTTPHEADER
-d CURLOPT_POSTFIELDSCURLOPT_POSTFIELDS
PHP example:
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY ) ;
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type:
application/json;"));
curl_setopt($curl, CURLOPT_USERPWD, "admin:admin");
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
C#,JAVA,PYTHON and other programming language have their own lib for sending http
request, please check the programming manual for help.
39