| | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.aliyun.cloudauth20190307.Client; |
| | | import com.aliyun.cloudauth20190307.models.Id2MetaVerifyResponse; |
| | | import com.aliyun.cloudauth20221125.models.EntElementVerifyRequest; |
| | | import com.aliyun.cloudauth20221125.models.EntElementVerifyResponse; |
| | | import com.aliyun.cloudauth20221125.models.EntElementVerifyResponseBody; |
| | | import com.aliyun.tea.TeaException; |
| | | import com.aliyun.teaopenapi.models.Config; |
| | | import com.aliyun.teautil.models.RuntimeOptions; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import static com.aliyun.teautil.Common.assertAsString; |
| | | |
| | | /** |
| | | * @author mitao |
| | |
| | | config.endpoint = "cloudauth.aliyuncs.com"; |
| | | return new Client(config); |
| | | } |
| | | |
| | | /** |
| | | * <b>description</b> : |
| | | * <p>使用AK&SK初始化账号Client</p> |
| | | * @return Client |
| | | * |
| | | * @throws Exception |
| | | */ |
| | | public static com.aliyun.cloudauth20221125.Client createBusinessLicenseClient() throws Exception { |
| | | Config config = new Config() |
| | | .setAccessKeyId("LTAI5tFSeci96NRF6p6UN69G") |
| | | .setAccessKeySecret("25t5zmWkueoQd81Zka70uPKRPgaMiV"); |
| | | config.endpoint = "cloudauth.aliyuncs.com"; |
| | | return new com.aliyun.cloudauth20221125.Client(config); |
| | | } |
| | | |
| | | public Boolean verifyIdCard(String userName,String idCardNo) { |
| | | //姓名第一个字密文+ 姓名其他部分明文。 |
| | | String firstCharacter = userName.substring(0, 1); |
| | |
| | | // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。 |
| | | // 错误 message |
| | | System.out.println(error.getMessage()); |
| | | // 诊断地址 |
| | | System.out.println(error.getData().get("Recommend")); |
| | | com.aliyun.teautil.Common.assertAsString(error.message); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | public static Boolean verifyBusinessLicense(String businessLicenseNo,String companyName,Long userId) { |
| | | com.aliyun.cloudauth20221125.Client client = null; |
| | | try { |
| | | client = createBusinessLicenseClient(); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | EntElementVerifyRequest entElementVerifyRequest = new EntElementVerifyRequest() |
| | | .setLicenseNo(businessLicenseNo) |
| | | .setEntName(companyName) |
| | | .setSceneCode("000001") |
| | | .setMerchantBizId(businessLicenseNo) |
| | | .setMerchantUserId(String.valueOf(userId)) |
| | | .setInfoVerifyType("ENT_2META") |
| | | .setUserAuthorization("1"); |
| | | RuntimeOptions runtime = new RuntimeOptions(); |
| | | try { |
| | | // 复制代码运行请自行打印 API 的返回值 |
| | | EntElementVerifyResponse entElementVerifyResponse = client.entElementVerifyWithOptions(entElementVerifyRequest, runtime); |
| | | EntElementVerifyResponseBody body = entElementVerifyResponse.getBody(); |
| | | EntElementVerifyResponseBody.EntElementVerifyResponseBodyResult result = body.getResult(); |
| | | String bizCode = result.getBizCode(); |
| | | return "1".equals(bizCode); |
| | | } catch (TeaException error) { |
| | | // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。 |
| | | // 错误 message |
| | | System.out.println(error.getMessage()); |
| | | // 诊断地址 |
| | | System.out.println(error.getData().get("Recommend")); |
| | | assertAsString(error.message); |
| | | } catch (Exception _error) { |
| | | TeaException error = new TeaException(_error.getMessage(), _error); |
| | | // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。 |
| | | // 错误 message |
| | | System.out.println(error.getMessage()); |
| | | // 诊断地址 |
| | | System.out.println(error.getData().get("Recommend")); |
| | | assertAsString(error.message); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | } |
| | | |
| | | } |