Polyv Help Center

Help Center

Send Alibaba Cloud SMS Notification

Updated: 2023-04-04 09:31:23

API Description

1、根据用户配置的模板发送短信通知
2、(timestamp, appId)参与sign签名,并和sign一起通过url传递,请求体参数不参与签名,通过post请求体传递【请设置请求头contentType:application/json】
3、接口支持https协议

API URL

http://api.polyv.net/live/v4/user/sms/send

Request Method

POST

API Constraints

  1. The API supports both HTTP and HTTPS. HTTPS is recommended for security. API calls are subject to rate limits. See details

  2. API call rate limits: a single user or IP can send up to 2000 SMS messages per day, and a single phone number can receive up to 10 messages per day.

  3. Before use, the account must be configured with an Alibaba Cloud SMS template.

Request Parameter Description

Parameter Required Type Description
appId true String Account appId See details in Get Secret Key
timestamp true Long Current 13-digit millisecond timestamp, valid for 3 minutes
sign true String Signature, a 32-character uppercase MD5 value. The appSecret key used to generate the signature is critical for communication data security. It must not be stored on the client side for direct use. All APIs must be called through the customer's own server to relay requests to the POLYV server for response data. See details in Signature Generation Rules

Request Body Parameter Description

Parameter Required Type Description
phoneNumbers true Array Phone numbers, 11 digits each, maximum 200
templateParamNames true Array Parameter names of the SMS template
templateParamValues true Array Parameter values corresponding to the template parameter names, one-to-one mapping

Example

http://api.polyv.net/live/v4/user/sms/send?appId=frlr1zazn3&timestamp=1656903040000&sign=9E0DCCEAB6A9D255717C9BEAB66CFDCA

Request body JSON parameters:

{
    "phoneNumbers": [1768909,17680476163],
    "templateParamNames": ["code"],
    "templateParamValues": [9802]
}

Response Parameter Description

Parameter Type Description
code Integer Status code, same as HTTP status code, used to determine the basic response status
status String Response result, determined by the business. Returns "success" on success, "error" on failure
success Boolean Whether the response is successful
requestId String Request ID, a unique UUID generated for each request. Only used for troubleshooting and debugging, not for business logic
error Object Error information when the status code is not 200 See details in Error Field Description
data Array See details in Data Field Description

Error Parameter Description

Parameter Type Description
code Integer Error code, used to identify the specific error reason
desc String Error description, corresponding to error.code

Data Parameter Description

Parameter Type Description
phoneNumber String Phone number
status Integer SMS status
-1: Send failed, phone number exceeded daily send limit
-2: Send failed, invalid phone number (non-numeric, incorrect length)
11: Send failed (failed to call Alibaba Cloud SMS API)
12: Send successful (successfully called Alibaba Cloud SMS API, entered SMS send queue waiting to be sent, not yet successfully delivered to the phone)
serialNo String Alibaba Cloud receipt ID serial number returned on successful send

Java Request Example

For quick integration of the base code, download the relevant dependency source code. Click here to download the source code. After downloading, add it to your own source project. The test cases include HttpUtil.java and LiveSignUtil.java, both contained in the downloaded file.

It is strongly recommended to use the Live Java SDK for API integration. The Live Java SDK provides unified encapsulation and optimization for API call logic, exception handling, data signing, and HTTP request thread pools.

private static final Logger log = LoggerFactory.getLogger(AccountTest.class);
/**
 * 发送阿里云短信通知
 * @throws IOException
 * @throws NoSuchAlgorithmException
 */
@Test
public void sendSmsTest() throws IOException, NoSuchAlgorithmException {
    //公共参数,填写自己的实际参数
    String appId = super.appId;
    String appSecret = super.appSecret;
    String timestamp = String.valueOf(System.currentTimeMillis());
    
    //业务参数
    String url = "http://api.polyv.net/live/v4/user/sms/send";
    List<String> phoneNumbers = Arrays.asList("17677777777");
    List<String> templateParamNames = Arrays.asList("code");
    List<String> templateParamValues = Arrays.asList("9876");
    
    //http 调用逻辑
    Map<String, String> requestMap = new HashMap<>();
    requestMap.put("appId", appId);
    requestMap.put("timestamp", timestamp);
    
    Map<String, Object> jsonMap = new HashMap<>();
    jsonMap.put("phoneNumbers", phoneNumbers);
    jsonMap.put("templateParamNames", templateParamNames);
    jsonMap.put("templateParamValues", templateParamValues);
    
    requestMap.put("sign", LiveSignUtil.getSign(requestMap, appSecret));
    
    url = HttpUtil.appendUrl(url, requestMap);
    String response = HttpUtil.postJsonBody(url, JSON.toJSONString(jsonMap), null);
    
    log.info("测试发送短信通知成功:{}", response);
    //do somethings
    
}

Response Example

For global system error descriptions, see Global Error Description

Success Example

{
    "code": 200,
    "status": "success",
    "requestId": "f2a4a564-4dd6-4a9f-b58e-05580cd69939",
    "data": [
        {
            "serialNo": "605320356903663783^0",
            "phoneNumber": "17680476163",
            "status": 12
        },
        {
            "serialNo": null,
            "phoneNumber": "1768909",
            "status": -2
        }
    ],
    "success": true
}

Error Example

{
    "code": 400,
    "status": "error",
    "requestId": "d310b70bc329403f87f77f9203d50f89.128.16360831552223589",
    "error": {
        "code": 20001,
        "desc": "application not found."
    },
    "success": false
}
联系客服,在线咨询