API REFERENCE
共 8983字,需浏览 18分钟
·
2023-04-25 13:42
common
host
https://uni.apistd.com
public parameters
Public parameters are the parameters that must be carried when calling the API request, and are uniformly transmitted using the URL Query parameter.
name | type | required | description | example |
---|---|---|---|---|
action | string | true | interface name | sms.message.send |
accessKeyId | string | true | AccessKey ID | rQJEk4mz6gZzTC9X8XHfpQ1Vt |
access authentication
UniSMS provides the following two authentication methods for developers to choose from, which can be set in the 「console-Certificate Management」, and the default is simple mode.
- simple mode [default]:This mode only verifies the
AccessKey ID
and does not verify the signature of the request parameters, which is convenient for developers to access quickly. - HMAC mode:This mode need
AccessKey Secret
to verify the request parameters to strengthen the security and authenticity of the request.
simple mode
Use the simple mode to complete the access authentication, just pass the AccessKey ID
value obtained from the console-credential management to the URL Query parameter accessKeyId
to complete the authentication.
HMAC mode
To complete access authentication using the HMAC mode, all URL Query parameters need to be arranged in dictionary order as the text string to be signed, and signed according to the specified signature hash algorithm.
Add the required public parameters (Query) as follows:
name | type | required | description | example |
---|---|---|---|---|
algorithm | string | true | Signature hash algorithm, currently only supports hmac-sha256 | hmac-sha256 |
timestamp | number | true | Timestamp (ms), accepted tolerance time 10 minutes | 1620243278785 |
nonce | string | true | Random string, between 8-64 characters | d7041f4746a09b10 |
signature | string | true | sign | xvv9UjzOrQFWe7fFS5IUU9iqIZrncvF093SqXsnfcK8= |
Signature generation step
1. Extract all URL Query parameter pairs in the request, and sort them in lexicographical order (positive order) according to the parameter Key,use = join Key-Value,use & joinare paired to form the text string to be signed, as shown in the following example:
accessKeyId=rQJEk4mz6gZzTC9X8XHfpQ1Vt&action=sms.message.send&algorithm=hmac-sha256&nonce=d7041f4746a09b10×tamp=1620269782258
2. use HmacSHA256 algorithm,use AccessKey ID corresponding AccessKey Secret as key,generate a signature for the "text to be signed",output Base64 (或 Hex) string,as shown in the following example:
xvv9UjzOrQFWe7fFS5IUU9iqIZrncvF093SqXsnfcK8=
3.Add the signature string as the value of signature to the query parameter of the request URL to send the request. The final complete request URL example is as follows:
https://uni.apistd.com/?action=sms.message.send&accessKeyId=rQJEk4mz6gZzTC9X8XHfpQ1Vt&algorithm=hmac-sha256×tamp=1620269782258&nonce=d7041f4746a09b10&signature=xvv9UjzOrQFWe7fFS5IUU9iqIZrncvF093SqXsnfcK8%3D
Send message
Use this interface to send a text message to one or more recipients. Please read the common before reading this document.
inteface
- name:
sms.message.send
- HTTP Method:
POST
- Content-Type:
application/json
Request Data
name | type | required | description | example |
---|---|---|---|---|
to | string | string[] | true | phone number, use E.164 format | +8618688061234 |
signature | string | true | signature,between 2-16 characters | UniSMS |
content | string | false | message context,templateId or content choose one | your verification code is 9153,Valid for 15 minutes. |
templateId | string | false | SMS templateId or templateId templateCode,templateId or content choose one | login_notify |
templateData | JSON | false | - | {"code": "9153", "ttl": "15"} |
* Note: In order to help developers migrate quickly, UniSMS supports the use of the content parameter to directly pass in text, and new access users are recommended to use templateId to pass parameters first
Request Example
curl -X POST 'https://uni.apistd.com/?action=sms.message.send&accessKeyId=YOUR_ACCESS_KEY_ID' \
-H 'Content-Type: application/json' \
-d '{
"to": "+861860571xxxx",
"signature": "UniSms",
"templateId": "signup",
"templateData": {"code": "3241", "ttl": "10"}
}'
response
name | type | description | example |
---|---|---|---|
code | string | business code | 105400 |
message | string | business message | InsufficientFunds |
data | JSON | business result |
response.data
name | type | description | example |
---|---|---|---|
status | string | - | sent |
recipients | integer | - | 1 |
messageCount | integer | if context too long, may be split | 1 |
totalAmount | number | - | 0.045 |
payAmount | number | - | 0.045 |
virtualAmount | number | - | 0 |
messages | JSON[] | - | ⬇️ |
response.data.messages
name | type | description | example |
---|---|---|---|
id | string | identity | 7cf4b5c12c5ad49379ce07290d9b00bb |
to | string | phone number (E.164) | +8618688061234 |
regionCode | string | - | CN |
countryCode | string | - | 86 |
messageCount | integer | - | 1 |
status | string | - | sent |
upstream | string | real upstream | emay.standard |
price | string | - | 0.040000 |
Response Example
Success
Status Code: 200
, Response Body:
{
"code": "0",
"message": "Success",
"data": {
"recipients": 2,
"messageCount": 2,
"totalAmount": "0.187500",
"payAmount": "0.187500",
"virtualAmount": "0",
"messages": [
{
"id": "4e88293e50aac21d027a9d6c0f33661e",
"to": "+8618688061234",
"regionCode": "CN",
"countryCode": "86",
"messageCount": 1,
"status": "sent",
"upstream": "emay.standard",
"price": "0.050000"
},
{
"id": "ce02a6c4195c6f8c4b6a7250ccb3b0a1",
"to": "+12894260331",
"regionCode": "CA",
"countryCode": "1",
"messageCount": 1,
"status": "sent",
"upstream": "emay.intl.standard",
"price": "0.137500"
}
]
}
}
Error
Status Code: 400
, Response Body:
{
"code": "105400",
"message": "InsufficientFunds"
}
Voice verification code
Use this interface to send a voice verification code (to make a call) to a recipient. Read API Common before reading this document.
inteface
- name:
sms.voice.verification.send
- HTTP Method:
POST
- Content-Type:
application/json
Request
name | type | required | description | example |
---|---|---|---|---|
to | string | true | phone number | +8618509872103 |
code | string | true | between 2-16 characters | 5201 |
* Note: The use of international mobile phone numbers is not supported at the moment
Example
curl -X POST 'https://uni.apistd.com/?action=sms.voice.verification.send&accessKeyId=YOUR_ACCESS_KEY_ID' \
-H 'Content-Type: application/json' \
-d '{
"to": "+861850987xxxx",
"code": "5201"
}'
Response
name | type | example |
---|---|---|
code | string | 101301 |
message | string | NoUpstreamAvailable |
data | JSON | ⬇️ |
Response.data
name | type | example |
---|---|---|
status | string | sent |
recipients | integer | 1 |
messageCount | integer | 1 |
totalAmount | number | 0.05 |
payAmount | number | 0.05 |
messages | JSON[] |
Response.data.messages
name | type | description | example |
---|---|---|---|
id | string | message identy | 7086bf2f0c2e944b15b08897277d8414 |
to | string | phone number (E.164) | +8618509872103 |
regionCode | string | - | CN |
countryCode | string | - | 86 |
messageCount | integer | if context too long, may be split | 1 |
status | string | - | sent |
upstream | string | - | monyun.standard |
price | string | - | 0.050000 |
Response
when success
Status Code: 200
, Response Body:
{
"data": {
"recipients": 1,
"messageCount": 1,
"totalAmount": "0.050000",
"payAmount": "0.050000",
"virtualAmount": "0",
"messages": [
{
"id": "7086bf2f0c2e944b15b08897277d8414",
"to": "+8618509872103",
"regionCode": "CN",
"countryCode": "86",
"messageCount": 1,
"status": "sent",
"upstream": "monyun.standard",
"price": "0.050000"
}
]
},
"code": "0",
"message": "Success"
}
when error
Status Code: 400
, Response Body:
{
"code": "101303",
"message": "NoUpstreamAvailable"
}
Error code and description
code | description | explanation |
---|---|---|
0 | Ok | Request success |
101000 | Internal | Inner error |
101301 | NoUpstreamConfigured | No valid upstream channel set. Please check whether the expert mode is turned on and the channel configuration is not completed, you can switch to the fusion mode to quickly solve the problem |
101303 | NoUpstreamAvailable | All upstream channels failed, indicating that the request has no available upstreams |
104001 | MissingParams | - |
104002 | InvalidParams | - |
104003 | RestrictedParams | - |
104110 | MissingAccessKeyId | - |
104111 | InvalidAccessKeyId | - |
104201 | InvalidSignature | Please refer to API Common to generate a request signature |
104202 | InvalidSignatureTimestamp | Please check that the value passed in is a valid UNIX timestamp, a difference of 10 minutes from the server time is acceptable |
105001 | Unauthorized | - |
105100 | IpRestricted | Please check whether the IP restriction extension service is enabled, and make sure that the request server IP matches the configuration |
105300 | LimitExceed | Please check whether the sending frequency limit extension service is enabled, and if necessary, you can adjust the limit upper limit by yourself |
105400 | InsufficientFunds | - |
107111 | InvalidPhoneNumbers | - |
107120 | MissingSmsSignature | - |
107121 | SmsSignatureNotExists | Please visit the control panel to add |
107122 | InvalidSmsSignature | The signature has not been approved or is currently under review |
107123 | RestrictedSmsSignature | Please contact your Account Manager to find out if there are negotiation restrictions |
107141 | SmsTemplateNotExists | Please visit the control panel to add. If you are using a review-free template that starts with pub_ , please check whether the template code is correct |
107143 | MissingSmsTemplateData | - |
107144 | InvaildSmsTemplateData | - |
107145 | RestrictedSmsTemplate | Please contact your Account Manager to find out if there are negotiation restrictions |