SMS Verification Code
Sends a verification code through the Alibaba Cloud SMS service. You may pass a custom code, or leave it blank and let the platform generate a random 6-digit one. Billed per package, 1 deduction per call.
API info
| Item | Value |
|---|
| Endpoint | POST /api/v3/dxyzm |
| Billing | Package |
Request parameters
| Parameter | Type | Required | Description |
|---|
phone | string | Yes | Recipient phone number (11 digits) |
code | string | No | Custom 6-digit code; generated by the platform if omitted |
Request example
PHP
<?php
$app_id = 'YOUR_APP_ID';
$app_key = 'YOUR_APP_KEY';
$url = 'https://yunsapi.com/api/v3/dxyzm';
$params = ['phone' => '13800138000'];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'X-APP-ID: ' . $app_id,
'X-APP-KEY: ' . $app_key,
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($ch);
curl_close($ch);
echo $resp;
Java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class SmsDemo {
public static void main(String[] args) throws Exception {
String appId = "YOUR_APP_ID";
String appKey = "YOUR_APP_KEY";
String url = "https://yunsapi.com/api/v3/dxyzm";
String body = "{\"phone\":\"13800138000\"}";
HttpClient client = HttpClient.newHttpClient();
HttpRequest req = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Content-Type", "application/json")
.header("X-APP-ID", appId)
.header("X-APP-KEY", appKey)
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
HttpResponse<String> resp = client.send(req, HttpResponse.BodyHandlers.ofString());
System.out.println(resp.body());
}
}
Response example
{
"code": 0,
"msg": "sent successfully",
"data": {
"phone": "13800138000",
"code": "123456",
"generated": false,
"remain": 9
},
"request_id": "req_xxx"
}
Response parameters
| Parameter | Type | Description |
|---|
data.phone | string | Recipient phone number |
data.code | string | The code sent this time; compare it with the code you generated locally |
data.generated | boolean | true if generated by the platform, false if a custom code was used |
data.remain | integer | Remaining quota in the package |