Face Recognition
Compares a user's face photo against the ID photo in the public security database and returns a similarity score with the verification result, for real-person authentication. The photo is passed via a public URL. Billed per package, 1 deduction per call.
API info
| Item | Value |
|---|
| Endpoint | POST /api/v3/ylsm |
| Billing | Package |
Request parameters
| Parameter | Type | Required | Description |
|---|
name | string | Yes | Name (must be correct; used to locate the database record) |
idcard | string | Yes | ID card number (must be correct) |
file_url | string | Yes | Public URL of the face photo, JPG/PNG supported |
Request example
PHP
<?php
$app_id = 'YOUR_APP_ID';
$app_key = 'YOUR_APP_KEY';
$url = 'https://yunsapi.com/api/v3/ylsm';
$params = [
'name' => 'Zhang San',
'idcard' => '370102199011185566',
'file_url' => 'https://example.com/face.jpg',
];
$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 FaceDemo {
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/ylsm";
String body = "{\"name\":\"Zhang San\",\"idcard\":\"370102199011185566\",\"file_url\":\"https:
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": "success",
"data": {
"score": 95,
"verify": 1,
"message": "the system considers them the same person",
"remain": 9
},
"request_id": "req_xxx"
}
Response parameters
| Parameter | Type | Description |
|---|
data.score | integer | Face similarity score, 0-100; higher means more similar |
data.verify | integer | 1 means passed, 0 means failed |
data.message | string | Verification result description |
data.remain | integer | Remaining quota in the package |
Note: verify = 1 is generally a match. If your business needs a higher bar, set your own threshold with score.