Commit 585001db by zhengxj

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

git-svn-id: svn://192.168.3.233/frms/code/car-service/trunk/car-service@24256 aeb6102e-e053-11e5-9fec-f9ebc45caf4b
1 parent 3d25e11d
...@@ -18,6 +18,7 @@ import java.io.IOException; ...@@ -18,6 +18,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
...@@ -422,6 +423,7 @@ public class WechatUtils { ...@@ -422,6 +423,7 @@ public class WechatUtils {
String accessToken = null; String accessToken = null;
try { try {
imgUrl = URLEncoder.encode(imgUrl, "UTF-8");
accessToken = this.getWechatToken(appid, secret); accessToken = this.getWechatToken(appid, secret);
} catch (Exception e) { } catch (Exception e) {
logger.error("获取小程序access_token请求异常!"); logger.error("获取小程序access_token请求异常!");
...@@ -438,11 +440,12 @@ public class WechatUtils { ...@@ -438,11 +440,12 @@ public class WechatUtils {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
if (StringUtils.isEmpty(result)) { if (!StringUtils.isEmpty(result)) {
JSONObject jb = JSON.parseObject(result); JSONObject jb = JSON.parseObject(result);
if (jb.containsKey("id") && "0".equals(jb.getString("errcode"))) { if (jb.containsKey("id") && 0 == jb.getInteger("errcode")) {
returnMap.put("code", "200"); returnMap.put("code", "200");
returnMap.put("id", jb.getString("id")); returnMap.put("id", jb.getString("id"));
returnMap.put("id", jb.getString("number"));
return returnMap; return returnMap;
} }
} }
...@@ -450,6 +453,7 @@ public class WechatUtils { ...@@ -450,6 +453,7 @@ public class WechatUtils {
} }
public Map<String, String> IDCardOcr(String imgUrl) { public Map<String, String> IDCardOcr(String imgUrl) {
HttpUtils httpUtils = new HttpUtils(); HttpUtils httpUtils = new HttpUtils();
Map<String, String> returnMap = new HashMap<>(4); Map<String, String> returnMap = new HashMap<>(4);
...@@ -461,6 +465,7 @@ public class WechatUtils { ...@@ -461,6 +465,7 @@ public class WechatUtils {
String accessToken = null; String accessToken = null;
try { try {
accessToken = this.getWechatToken(appid, secret); accessToken = this.getWechatToken(appid, secret);
imgUrl = URLEncoder.encode(imgUrl, "UTF-8");
} catch (Exception e) { } catch (Exception e) {
logger.error("获取小程序access_token请求异常!"); logger.error("获取小程序access_token请求异常!");
throw new RuntimeException(e); throw new RuntimeException(e);
...@@ -476,9 +481,9 @@ public class WechatUtils { ...@@ -476,9 +481,9 @@ public class WechatUtils {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
if (StringUtils.isEmpty(result)) { if (!StringUtils.isEmpty(result)) {
JSONObject jb = JSON.parseObject(result); JSONObject jb = JSON.parseObject(result);
if (jb.containsKey("id") && "0".equals(jb.getString("errcode"))) { if (0 == jb.getInteger("errcode")) {
returnMap.put("code", "200"); returnMap.put("code", "200");
String type = jb.getString("type"); String type = jb.getString("type");
returnMap.put("type", type); returnMap.put("type", type);
......
...@@ -24,14 +24,23 @@ ...@@ -24,14 +24,23 @@
*/ */
package com.glsx.usercenter.controller; package com.glsx.usercenter.controller;
import java.net.URLEncoder;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.glsx.common.constants.Constants;
import com.glsx.common.constants.ResultObject; import com.glsx.common.constants.ResultObject;
import com.glsx.common.utils.PropertiesUtil;
import com.glsx.common.utils.wehcat.WechatUtils;
import com.glsx.usercenter.constants.ResultCodeEnum; import com.glsx.usercenter.constants.ResultCodeEnum;
import com.glsx.usercenter.pojo.sp.ProviderVo; import com.glsx.usercenter.pojo.sp.ProviderVo;
import com.glsx.usercenter.utils.ShiroUtil;
/** /**
* @ClassName: MechanicController * @ClassName: MechanicController
...@@ -44,6 +53,10 @@ import com.glsx.usercenter.pojo.sp.ProviderVo; ...@@ -44,6 +53,10 @@ import com.glsx.usercenter.pojo.sp.ProviderVo;
@RequestMapping(value = "/mechanic") @RequestMapping(value = "/mechanic")
public class MechanicController extends BaseReportController { public class MechanicController extends BaseReportController {
@Autowired
private WechatUtils wechatUtils;
/** /**
* *
* *
...@@ -58,16 +71,44 @@ public class MechanicController extends BaseReportController { ...@@ -58,16 +71,44 @@ public class MechanicController extends BaseReportController {
* *
*/ */
@GetMapping("/getMechanicInfo") @GetMapping("/getMechanicInfo")
public ResultObject getMechanicInfo(Integer id) { public ResultObject getMechanicInfo() {
// TODO 区分已认证与未认证技工信息 // TODO 区分已认证与未认证技工信息
int userId = ShiroUtil.getUserId();
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), null); return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), null);
} }
@PostMapping("/verify") @PostMapping("/verify")
public ResultObject verify(Integer id, String bankCarkImgUrl, String IDCardFrontImgUrl, String IDCardBackImgUrl) { public ResultObject verify(@RequestParam(required = true) String bankCarkImgUrl,
// TODO 调用腾讯的api, @RequestParam(required = true) String IDCardFrontImgUrl,
@RequestParam(required = true) String IDCardBackImgUrl) {
int userId = ShiroUtil.getUserId();
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), null);
}
@PostMapping("/IdCardOcr")
public ResultObject IdCardOcr(@RequestParam(required = true) String IDCardImgUrl,
@RequestParam(required = true) String type) {
// 调用腾讯的api,type :front人像面,back国徽面
// 人像面
// :https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1571135839622&di=09097184eb8db10cb60686a8b52a19b2&imgtype=0&src=http%3A%2F%2Fwww.xinhui.gov.cn%2Fgzjg%2Fgzj%2Fsjz%2Fzcwj_51410%2F201902%2FW020190228370232880733.jpg
// 国徽面
// :https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1571135978582&di=8108dc9745eeed6fa57dbdc61f03450d&imgtype=0&src=http%3A%2F%2Fcimg.163.com%2Fnews%2F0403%2F29%2Fqq5.jpg
Map<String, String> map = wechatUtils.IDCardOcr(IDCardImgUrl);
if ("200".equals(map.get("code")) && type.equalsIgnoreCase(map.get("type"))) {
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), null); return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), null);
} }
return new ResultObject(ResultCodeEnum.FAIL.getCode(), "请按照要求上传合格的照片!", null);
}
@PostMapping("/bankCardOcr")
public ResultObject IDCardOcr(@RequestParam(required = true) String BankCardBackImgUrl) {
// 调用腾讯的api
Map<String, String> map = wechatUtils.bankCardOcr(BankCardBackImgUrl);
if (map.containsKey("id") && !map.get("id").isEmpty()) {
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), null);
}
return new ResultObject(ResultCodeEnum.FAIL.getCode(), "请按照要求上传合格的照片!", null);
}
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!