chengkun
2025-06-05 4080b5997b38ca84b3b203c7101dcadb97b76925
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package com.alipay.easysdk.member.identification;
 
import com.alipay.easysdk.TestAccount;
import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.factory.Factory.Member;
import com.alipay.easysdk.kernel.util.ResponseChecker;
import com.alipay.easysdk.member.identification.models.AlipayUserCertifyOpenCertifyResponse;
import com.alipay.easysdk.member.identification.models.AlipayUserCertifyOpenInitializeResponse;
import com.alipay.easysdk.member.identification.models.AlipayUserCertifyOpenQueryResponse;
import com.alipay.easysdk.member.identification.models.IdentityParam;
import com.alipay.easysdk.member.identification.models.MerchantConfig;
import org.junit.Before;
import org.junit.Test;
 
import java.util.UUID;
 
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
 
public class ClientTest {
 
    @Before
    public void setUp() {
        Factory.setOptions(TestAccount.Mini.CONFIG);
    }
 
    @Test
    public void testInit() throws Exception {
        IdentityParam identityParam = new IdentityParam();
        identityParam.identityType = "CERT_INFO";
        identityParam.certType = "IDENTITY_CARD";
        identityParam.certName = "张三";
        identityParam.certNo = "5139011988090987631";
        MerchantConfig merchantConfig = new MerchantConfig();
        merchantConfig.returnUrl = "www.taobao.com";
        AlipayUserCertifyOpenInitializeResponse response = Member.Identification().init(
                UUID.randomUUID().toString(), "FACE", identityParam, merchantConfig);
 
        assertThat(ResponseChecker.success(response), is(true));
        assertThat(response.code, is("10000"));
        assertThat(response.msg, is("Success"));
        assertThat(response.subCode, is(nullValue()));
        assertThat(response.subMsg, is(nullValue()));
        assertThat(response.httpBody, not(nullValue()));
        assertThat(response.certifyId, not(nullValue()));
    }
 
    @Test
    public void testCertify() throws Exception {
        AlipayUserCertifyOpenCertifyResponse response = Member.Identification().certify("1226a454daf65c2abbbe0b7b8dc30d20");
 
        assertThat(ResponseChecker.success(response), is(true));
        assertThat(response.body, containsString("https://openapi.alipay.com/gateway.do?alipay_sdk=alipay-easysdk-java-"));
        assertThat(response.body, containsString("sign"));
    }
 
    @Test
    public void testQuery() throws Exception {
        AlipayUserCertifyOpenQueryResponse response = Member.Identification().query("89ad1f1b8171d9741c3e5620fd77f9de");
 
        assertThat(ResponseChecker.success(response), is(false));
        assertThat(response.code, is("40004"));
        assertThat(response.msg, is("Business Failed"));
        assertThat(response.subCode, is("CERTIFY_ID_EXPIRED"));
        assertThat(response.subMsg, is("认证已失效"));
        assertThat(response.httpBody, not(nullValue()));
        assertThat(response.passed, is(nullValue()));
        assertThat(response.identityInfo, is(nullValue()));
        assertThat(response.materialInfo, is(nullValue()));
    }
}