YunShang API

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

ItemValue
EndpointPOST /api/v3/alipaysm
BillingBuyout

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)

    ParameterTypeRequiredDescription
    actionstringYesFixed value start
    user_namestringYesReal name
    cert_nostringYesID card number
    mobilestringNoAlipay-bound mobile number
    logon_idstringNoAlipay login account

    Request parameters (action=result)

    ParameterTypeRequiredDescription
    actionstringYesFixed value result
    auth_codestringYesAuth 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';
    
    // Step 1: start verification
    $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;
    
    // Step 2: after user authorization, query with the auth code
    $params2 = [
        'action'    => 'result',
        'auth_code' => 'USER_AUTH_CODE',
    ];
    // POST $params2 the same way (code omitted)

    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 {
            // Step 1: start verification
            String body = "{\"action\":\"start\",\"user_name\":\"Zhang San\",\"cert_no\":\"110101198806052133\"}";
            String resp = post(body);
            System.out.println(resp);
    
            // Step 2: query with the auth code after user authorization
            // String body2 = "{\"action\":\"result\",\"auth_code\":\"USER_AUTH_CODE\"}";
            // System.out.println(post(body2));
        }
    
        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

    ParameterTypeDescription
    data.tokenstringToken of this verification (start)
    data.verify_idstringVerification record ID, useful for reconciliation (start)
    data.auth_urlstringAlipay authorization link to open (start)
    data.verifystringResult, 1 matched, 0 mismatch (result)
    data.user_namestringVerified name (result)
    data.cert_nostringVerified 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.