通用接口
| 40 | * 通用接口 |
| 41 | */ |
| 42 | @RestController |
| 43 | public class CommonController{ |
| 44 | @Autowired |
| 45 | private CommonService commonService; |
| 46 | |
| 47 | @Autowired |
| 48 | private ConfigService configService; |
| 49 | |
| 50 | private static AipFace client = null; |
| 51 | |
| 52 | private static String BAIDU_DITU_AK = null; |
| 53 | |
| 54 | @RequestMapping("/location") |
| 55 | public R location(String lng,String lat) { |
| 56 | if(BAIDU_DITU_AK==null) { |
| 57 | BAIDU_DITU_AK = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "baidu_ditu_ak")).getValue(); |
| 58 | if(BAIDU_DITU_AK==null) { |
| 59 | return R.error("请在配置管理中正确配置baidu_ditu_ak"); |
| 60 | } |
| 61 | } |
| 62 | Map<String, String> map = BaiduUtil.getCityByLonLat(BAIDU_DITU_AK, lng, lat); |
| 63 | return R.ok().put("data", map); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * 人脸比对 |
| 68 | * |
| 69 | * @param face1 人脸1 |
| 70 | * @param face2 人脸2 |
| 71 | * @return |
| 72 | */ |
| 73 | @RequestMapping("/matchFace") |
| 74 | public R matchFace(String face1, String face2,HttpServletRequest request) { |
| 75 | if(client==null) { |
| 76 | /*String AppID = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "AppID")).getValue();*/ |
| 77 | String APIKey = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "APIKey")).getValue(); |
| 78 | String SecretKey = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "SecretKey")).getValue(); |
| 79 | String token = BaiduUtil.getAuth(APIKey, SecretKey); |
| 80 | if(token==null) { |
| 81 | return R.error("请在配置管理中正确配置APIKey和SecretKey"); |
| 82 | } |
| 83 | client = new AipFace(null, APIKey, SecretKey); |
| 84 | client.setConnectionTimeoutInMillis(2000); |
| 85 | client.setSocketTimeoutInMillis(60000); |
| 86 | } |
| 87 | JSONObject res = null; |
| 88 | try { |
| 89 | File file1 = new File(request.getSession().getServletContext().getRealPath("/upload")+"/"+face1); |
| 90 | File file2 = new File(request.getSession().getServletContext().getRealPath("/upload")+"/"+face2); |
| 91 | String img1 = Base64Util.encode(FileUtil.FileToByte(file1)); |
| 92 | String img2 = Base64Util.encode(FileUtil.FileToByte(file2)); |
| 93 | MatchRequest req1 = new MatchRequest(img1, "BASE64"); |
| 94 | MatchRequest req2 = new MatchRequest(img2, "BASE64"); |
| 95 | ArrayList<MatchRequest> requests = new ArrayList<MatchRequest>(); |
| 96 | requests.add(req1); |
| 97 | requests.add(req2); |
| 98 | res = client.match(requests); |
| 99 | System.out.println(res.get("result")); |
nothing calls this directly
no outgoing calls
no test coverage detected