营业执照检查

第一步:检查准备

public String businessLicenseCheck(String businessLicenseUrl){
        String url = "https://bizlicense.market.alicloudapi.com/rest/160601/ocr/ocr_business_license.json";
        String method = "POST";
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("Authorization", "APPCODE " + userSystemConstant.getAliAppCode());
        headers.put("Content-Type", "application/json; charset=UTF-8");
        Map<String, String> querys = new HashMap<String, String>();
        String bodys = "{\"image\":\""+businessLicenseUrl+"\"}";
        try {
            String response = HttpsRequestUtil.httpsRequest(url, method, headers, bodys);
            //获取response的body
            if(response.equals("Invalid Result - invalid business license")){
                return null;
            }
            return response;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

实体类 

@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CompanyAuthVO implements Serializable {
    private static final long serialVersionUID = 3584743219477515646L;
    @ApiModelProperty(value = "id")
    @NotNull(message = "id不能为空", groups = {Update.class})
    private Integer id;
    @ApiModelProperty(value = "用户id", hidden = true)
    private Integer userAccountId;
    @ApiModelProperty(value = "企业名称")
    @NotBlank(message = "企业名称", groups = {Insert.class, Update.class})
    private String companyName;
    @ApiModelProperty(value = "统一社会信用代码")
    @NotBlank(message = "统一社会信用代码", groups = {Insert.class, Update.class})
    private String creditCode;
    @ApiModelProperty(value = "营业执照")
    @NotBlank(message = "营业执照", groups = {Insert.class, Update.class})
    private String licenseImg;
    @ApiModelProperty(value = "企业认证状态,0未通过,1已通过")
    private Integer authStatus;
}

第二步:请求资源检查

public static String httpsRequest(String url, String method, Map<String, String> headerMap, String bodyData)
            throws Exception {
        HttpsURLConnection conn = null;
        OutputStream out = null;
        String rsp = null;
        byte[] byteArray = bodyData.getBytes("utf-8");
        try {
            URL uri = new URL(url);
            conn = (HttpsURLConnection) uri.openConnection();
            // 忽略证书验证--Begin
            conn.setHostnameVerifier(new TrustAnyHostnameVerifier());
            // 忽略证书验证--End
            conn.setRequestMethod(method);
            conn.setDoInput(true);
            conn.setDoOutput(true);
            conn.setRequestProperty("Host", uri.getHost());
            conn.setRequestProperty("Content-Type", "application/json; charset=utf-8");
            if (headerMap != null) {
                Iterator<Map.Entry<String, String>> it = headerMap.entrySet().iterator();
                while (it.hasNext()) {
                    Map.Entry<String, String> entry = it.next();
                    conn.setRequestProperty(entry.getKey(), entry.getValue());
                }
            }
            out = conn.getOutputStream();
            out.write(byteArray);
            out.close();

            if (conn.getResponseCode() == 200) {
                rsp = getStreamAsString(conn.getInputStream(), "utf-8");
            } else {
//                rsp = getStreamAsString(conn.getErrorStream(), "utf-8");
                InputStream errorStream = conn.getErrorStream();
                if (errorStream != null) {
                    rsp = getStreamAsString(errorStream, "utf-8");
                } else {
                    // 处理没有错误流的情况,例如返回默认错误信息
                    rsp = "Invalid Result - invalid business license";
                }
            }
        } catch (Exception e) {
            if (null != out) {
                out.close();
            }
            e.printStackTrace();
        }
        return rsp;
    }

数据流处理

private static String getStreamAsString(InputStream stream, String charset) throws IOException {
        try {
            Reader reader = new InputStreamReader(stream, charset);
            StringBuilder response = new StringBuilder();

            final char[] buff = new char[1024];
            int read = 0;
            while ((read = reader.read(buff)) > 0) {
                response.append(buff, 0, read);
            }
            return response.toString();
        } finally {
            if (stream != null) {
                stream.close();
            }
        }
    }

最后:对照用户填写信息

public ResultBody companyCheck(CompanyAuthVO companyAuthVO) {
        String businessRes = qccEntAuthUtil.businessLicenseCheck(companyAuthVO.getLicenseImg());
        if (businessRes == null) {
            ResultBody resultBody = ResultBody.error(ResultEnum.BUSINESS_LICENSE_CHECK_ANALYSIS_ERROR);
            return resultBody;
        }
        //将字符串转化成json对象
        JSONObject businessResJson = JSONObject.parseObject(businessRes);
        System.out.println(businessResJson.toString());
        if (businessResJson.getString("success").equals("false")) {
            return ResultBody.error(ResultEnum.BUSINESS_LICENSE_CHECK_ANALYSIS_ERROR);
        } else {
            if (businessResJson.getString("name").equals(this.convert(companyAuthVO.getCompanyName()))
                    && businessResJson.getString("reg_num").equals(companyAuthVO.getCreditCode())) {
                String check2Res = qccEntAuthUtil.check2(companyAuthVO.getCompanyName(), companyAuthVO.getCreditCode());
                if (check2Res != null) {
                    String status = qccEntAuthUtil.FormartJson(check2Res, "Status");
                    if (status.equals("200")) {
                        Integer verifyCode = qccEntAuthUtil.resultFormatJson(check2Res);
                        if (verifyCode.equals(1)) {
                            return ResultBody.success();
                        }
                        String returnString = "";
                        if (verifyCode.equals(0)) {
                            returnString = "统一社会信用代码有误";
                        } else if (verifyCode.equals(2)) {
                            returnString = "企业名称不一致";
                        } else if (verifyCode.equals(3)) {
                            returnString = "法定代表人名称不一致";
                        }
                        return ResultBody.error(returnString);
                    }
                    String errorString = "";
                    if (status.equals("201")) {
                        errorString = "查询无结果";
                    } else if (status.equals("202")) {
                        errorString = "查询参数错误,请检查";
                    } else if (status.equals("205")) {
                        errorString = "等待处理中";
                    } else if (status.equals("207")) {
                        errorString = "请求数据的条目数超过上限(5000)";
                    } else if (status.equals("208")) {
                        errorString = "此接口不支持此公司类型查询";
                    } else if (status.equals("209")) {
                        errorString = "企业数量超过上限";
                    } else if (status.equals("213")) {
                        errorString = "参数长度不能小于2";
                    } else if (status.equals("215")) {
                        errorString = "不支持的查询关键字";
                    } else if (status.equals("218")) {
                        errorString = "该企业暂不支持空壳扫描";
                    } else if (status.equals("219")) {
                        errorString = "该企业暂不支持准入尽调";
                    } else if (status.equals("105")) {
                        errorString = "接口已下线停用";
                    } else if (status.equals("110")) {
                        errorString = "当前相同查询连续出错,请等2小时后重试";
                    } else {
                        errorString = "认证报错,请联系管理员";
                    }
                    return ResultBody.error(errorString);
                } else {
                    return ResultBody.error("认证报错");
                }
            } else {
                return ResultBody.error(ResultEnum.BUSINESS_LICENSE_CHECK_PARAMETER_ERROR);
            }
        }
    }

  • 10
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个 Oracle 营业执照代码校验函数的示例: ```sql CREATE OR REPLACE FUNCTION check_license_code(p_license_code IN VARCHAR2) RETURN VARCHAR2 IS v_license_code VARCHAR2(15) := UPPER(p_license_code); v_check_code CHAR(1); v_weight_array CONSTANT VARCHAR2(10) := '123456789ABCDEFGHJKLMNPQRTUWXY'; v_weight_num_array CONSTANT VARCHAR2(10) := '31791065432'; BEGIN -- 校验长度和字符合法性 IF LENGTH(v_license_code) <> 15 OR REGEXP_LIKE(v_license_code, '[^0-9A-Z]') THEN RETURN 'INVALID_LICENSE_CODE'; END IF; -- 计算校验码 v_check_code := v_weight_array(MOD(SUM(DECODE(SUBSTR(v_license_code, LEVEL, 1), v_weight_array, INSTR(v_weight_array, SUBSTR(v_license_code, LEVEL, 1)), NULL) * TO_NUMBER(SUBSTR(v_weight_num_array, LEVEL, 1))), 31) + 1); -- 检查校验码 IF SUBSTR(v_license_code, 15, 1) <> v_check_code THEN RETURN 'INVALID_CHECK_CODE'; ELSE RETURN 'VALID_LICENSE_CODE'; END IF; END; / ``` 该函数接收一个营业执照代码作为参数,返回一个字符串,表示校验结果。如果营业执照代码不符合规则,则返回 "INVALID_LICENSE_CODE",如果校验码不正确,则返回 "INVALID_CHECK_CODE",否则返回 "VALID_LICENSE_CODE"。使用该函数时,只需要传入营业执照代码即可。例如: ```sql SELECT check_license_code('123456789012345') FROM DUAL; -- 返回 'INVALID_LICENSE_CODE' SELECT check_license_code('1234567890123456') FROM DUAL; -- 返回 'INVALID_LICENSE_CODE' SELECT check_license_code('1234567890123456A') FROM DUAL; -- 返回 'VALID_LICENSE_CODE' SELECT check_license_code('1234567890123456B') FROM DUAL; -- 返回 'INVALID_CHECK_CODE' ``` 注意,在实际应用中,可能需要根据具体要求对该函数进行调整。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值