Commit 8fe041c3 by zhengxj

finish 身份证,银行卡ocr on 20191015 by zhengxj

git-svn-id: svn://192.168.3.233/frms/code/car-service/trunk/car-service@24243 aeb6102e-e053-11e5-9fec-f9ebc45caf4b
1 parent ee2bc4f3
......@@ -73,6 +73,9 @@ public class WechatUtils {
public String GET_WXACODE_UNLIMIT = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=$ACCESS_TOKEN$";
public String BANK_CARD_OCR_URL = "https://api.weixin.qq.com/cv/ocr/bankcard?type=photo&img_url=$IMG_URL$&access_token=$ACCESS_TOKEN$";
public String ID_CARD_OCR_URL = "https://api.weixin.qq.com/cv/ocr/idcard?type=photo&img_url=$IMG_URL$&access_token=$ACCESS_TOKEN$";
@Resource
RedisCacheUtil redisCacheUtil;
......@@ -369,7 +372,7 @@ public class WechatUtils {
logger.info(Base64.encodeBase64String(result));
returnMap.put("img", prefix + img);
returnMap.put("code", "200");
return returnMap;
}
// inputStream = new ByteArrayInputStream(result);
......@@ -408,4 +411,84 @@ public class WechatUtils {
}
public Map<String, String> bankCardOcr(String imgUrl) {
HttpUtils httpUtils = new HttpUtils();
Map<String, String> returnMap = new HashMap<>(4);
returnMap.put("code", "500");
String appid = PropertiesUtil.getProperty(Constants.WECHAT_MINI_MECHANIC_APPID);
String secret = PropertiesUtil.getProperty(Constants.WECHAT_MINI_MECHANIC_SECRET);
String accessToken = null;
try {
accessToken = this.getWechatToken(appid, secret);
} catch (Exception e) {
logger.error("获取小程序access_token请求异常!");
throw new RuntimeException(e);
}
String url = this.BANK_CARD_OCR_URL.replace("$ACCESS_TOKEN$", accessToken).replace("$IMG_URL$", imgUrl);
String result;
try {
result = httpUtils.post(url, null);
} catch (Exception e) {
logger.error("银行卡ocr请求异常!");
throw new RuntimeException(e);
}
if (StringUtils.isEmpty(result)) {
JSONObject jb = JSON.parseObject(result);
if (jb.containsKey("id") && "0".equals(jb.getString("errcode"))) {
returnMap.put("code", "200");
returnMap.put("id", jb.getString("id"));
return returnMap;
}
}
return returnMap;
}
public Map<String, String> IDCardOcr(String imgUrl) {
HttpUtils httpUtils = new HttpUtils();
Map<String, String> returnMap = new HashMap<>(4);
returnMap.put("code", "500");
String appid = PropertiesUtil.getProperty(Constants.WECHAT_MINI_MECHANIC_APPID);
String secret = PropertiesUtil.getProperty(Constants.WECHAT_MINI_MECHANIC_SECRET);
String accessToken = null;
try {
accessToken = this.getWechatToken(appid, secret);
} catch (Exception e) {
logger.error("获取小程序access_token请求异常!");
throw new RuntimeException(e);
}
String url = this.ID_CARD_OCR_URL.replace("$ACCESS_TOKEN$", accessToken).replace("$IMG_URL$", imgUrl);
String result;
try {
result = httpUtils.post(url, null);
} catch (Exception e) {
logger.error("身份证ocr请求异常!");
throw new RuntimeException(e);
}
if (StringUtils.isEmpty(result)) {
JSONObject jb = JSON.parseObject(result);
if (jb.containsKey("id") && "0".equals(jb.getString("errcode"))) {
returnMap.put("code", "200");
String type = jb.getString("type");
returnMap.put("type", type);
if ("front".equalsIgnoreCase(type)) {
returnMap.put("id", jb.getString("id"));
}
return returnMap;
}
}
return returnMap;
}
}
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!