Alipay Real-name Verification
Verifies name and ID number consistency via Alipay, with optional mobile number and login account checks. This API requires the user to jump to Alipay for authorization and works in two steps: start the verification to obtain an authorization link, then query the result with the auth code. Billed per buyout, long-term use within the licensed scope.
API info
| Item | Value |
|---|
| Endpoint | POST /api/v3/alipaysm |
| Billing | Buyout |
Flow
Call action=start with the user's info to get the auth_url authorization link
Guide the user to open auth_url in a browser and complete Alipay authorization
Alipay redirects back with an auth code; use it to call action=result and query the result
Request parameters (action=start)
| Parameter | Type | Required | Description |
|---|
action | string | Yes | Fixed value start |
user_name | string | Yes | Real name |
cert_no | string | Yes | ID card number |
mobile | string | No | Alipay-bound mobile number |
logon_id | string | No | Alipay login account |
Request parameters (action=result)
| Parameter | Type | Required | Description |
|---|
action | string | Yes | Fixed value result |
auth_code | string | Yes | Auth code obtained after user authorization |
Request example
PHP
<?php
$app_id = 'YOUR_APP_ID';
$app_key = 'YOUR_APP_KEY';
$base = 'https://yunsapi.com/api/v3/alipaysm';
$params = [
'action' => 'start',
'user_name' => 'Zhang San',
'cert_no' => '110101198806052133',
];
$ch = curl_init($base);
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;
$params2 = [
'action' => 'result',
'auth_code' => 'USER_AUTH_CODE',
];
Java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class AlipayDemo {
static final String APP_ID = "YOUR_APP_ID";
static final String APP_KEY = "YOUR_APP_KEY";
static final String URL = "https://yunsapi.com/api/v3/alipaysm";
public static void main(String[] args) throws Exception {
String body = "{\"action\":\"start\",\"user_name\":\"Zhang San\",\"cert_no\":\"110101198806052133\"}";
String resp = post(body);
System.out.println(resp);
}
static String post(String body) throws Exception {
HttpClient client = HttpClient.newHttpClient();
HttpRequest req = HttpRequest.newBuilder()
.uri(URI.create(URL))
.header("Content-Type", "application/json")
.header("X-APP-ID", APP_ID)
.header("X-APP-KEY", APP_KEY)
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
HttpResponse<String> resp = client.send(req, HttpResponse.BodyHandlers.ofString());
return resp.body();
}
}
Response example (start)
{
"code": 0,
"msg": "started",
"data": {
"token": "a1b2c3d4e5f67890",
"verify_id": "671ffcda5447bc87e9ed2f669eb143d4",
"auth_url": "https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=xxx&scope=id_verify"
},
"request_id": "req_xxx"
}
Response example (result)
{
"code": 0,
"msg": "success",
"data": {
"verify": "1",
"user_name": "Zhang San",
"cert_no": "110101198806052133"
},
"request_id": "req_xxx"
}
Response parameters
| Parameter | Type | Description |
|---|
data.token | string | Token of this verification (start) |
data.verify_id | string | Verification record ID, useful for reconciliation (start) |
data.auth_url | string | Alipay authorization link to open (start) |
data.verify | string | Result, 1 matched, 0 mismatch (result) |
data.user_name | string | Verified name (result) |
data.cert_no | string | Verified ID number (result) |
Note: the authorization link expires, so guide the user to finish authorization promptly. On failure the API returns business codes 1200 / 1201.