puzhibing
2023-10-08 22199bbdda579861736420fe26c2873ab0f5d21c
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
75
76
77
package com.sinata.rest.core.aliyun.bankcardverification;
 
import com.alibaba.fastjson.JSON;
import com.sinata.rest.core.aliyun.bankcardverification.model.BankCardVerificationData;
import com.sinata.rest.core.aliyun.bankcardverification.model.BankCardVerificationResult;
import com.sinata.rest.core.aliyun.realname.HttpUtils;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
 
import java.util.HashMap;
import java.util.Map;
 
/**
 * 银行卡二三四要素
 * https://market.aliyun.com/products/57000002/cmapi00037886.html?spm=5176.2020520132.101.3.23ad7218wSuxwn#sku=yuncode3188600001
 *
 * @author goku
 * @date 2020/10/28
 */
public class BankCardVerificationApi {
 
    public static void main(String[] args) {
        BankCardVerificationApi.verification("622202310000000000000", "XX", null, null);
    }
 
    /**
     * 银行卡验证
     *
     * @param accountNo     银行卡卡号
     * @param name          持卡人姓名
     * @param idCardCode    身份证号码 (三要素认证必填)
     * @param bankPreMobile 银行预留手机号码(四要素认证必填)
     */
    public static BankCardVerificationResult verification(String accountNo, String name, String idCardCode, String bankPreMobile) {
        String host = "https://zball.market.alicloudapi.com";
        String path = "/creditop/BankCardQuery/BankCardVerification";
        String method = "GET";
        String appcode = "da792d41240848e3b79713e9e4f039d1";
        Map<String, String> headers = new HashMap<String, String>(2);
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        Map<String, String> querys = new HashMap<String, String>(4);
        // 银行卡卡号
        querys.put("accountNo", accountNo);
        // 持卡人姓名
        querys.put("name", name);
        // 身份证号码 (三要素认证必填)
        querys.put("idCardCode", idCardCode);
        // 银行预留手机号码(四要素认证必填)
        querys.put("bankPreMobile", bankPreMobile);
 
 
        try {
            /**
             * 重要提示如下:
             * HttpUtils请从
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
             * 下载
             *
             * 相应的依赖请参照
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
             */
            HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
            //System.out.println(response.toString());
            /*
             * 获取response的body
             * {"error_code":0,"reason":"成功","result":{"accountNo":"622202**************","name":"苟*","idCardCore":"","bankPreMobile":"","result":"F","message":"无效卡号或卡号不存在,请换卡重试或联系发卡行","messagetype":5}}
             * {"error_code":0,"reason":"成功","result":{"accountNo":"622202*************","name":"苟*","idCardCore":"","bankPreMobile":"","result":"T","message":"银行卡鉴权成功","messagetype":0}}
             * System.out.println(EntityUtils.toString(response.getEntity()));
             */
            return JSON.parseObject(EntityUtils.toString(response.getEntity()), BankCardVerificationData.class).getResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}