|
|
@@ -4,6 +4,7 @@ import cn.hutool.http.Header;
|
|
|
import cn.hutool.http.HttpRequest;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.yunfeiyun.agmp.iot.common.util.dev.XctToCbdUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -16,9 +17,12 @@ public class YfCbdRecogeService {
|
|
|
private static String username = "软件事业部专用";
|
|
|
private static String password = "2024@yfkj!@#$";
|
|
|
|
|
|
- private static String recogeUrlByA = "http://8.136.98.49:8002/identify/9143";
|
|
|
+ private static String recogeUrlByCbdA = "http://8.136.98.49:8002/identify/9143";
|
|
|
|
|
|
- private static String recogeUrlByB = "http://8.136.98.49:8002/identify/9153";
|
|
|
+ private static String recogeUrlByCbdB = "http://8.136.98.49:8002/identify/9153";
|
|
|
+
|
|
|
+// private static String recogeUrlByXct = "https://web.hnyfwlw.com:58002/identify/20222";
|
|
|
+ private static String recogeUrlByXct = "http://8.136.98.49:8002/identify/20222";
|
|
|
|
|
|
public byte[] getImgBytes(String imgUrl){
|
|
|
return HttpUtil.downloadBytes(imgUrl);
|
|
|
@@ -34,11 +38,22 @@ public class YfCbdRecogeService {
|
|
|
return jsonObject.getJSONObject("data");
|
|
|
}
|
|
|
|
|
|
+ private JSONObject getXctRecogeResult(String content) {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(content);
|
|
|
+ log.info("[云飞吸虫塔手动识别服务]: 识别结果:{}", jsonObject);
|
|
|
+ if (jsonObject.getIntValue("code") != 0){
|
|
|
+ log.error("[云飞吸虫塔手动识别服务]: 识别失败,错误信息:{}", jsonObject);
|
|
|
+ throw new RuntimeException("识别失败,请检查图片是否正确");
|
|
|
+ }
|
|
|
+ JSONObject resultData = jsonObject.getJSONObject("data");
|
|
|
+ return XctToCbdUtil.xctToCbdData(resultData);
|
|
|
+ }
|
|
|
+
|
|
|
public JSONObject getRecogeResultByA(String imgUrl){
|
|
|
String[] pathTemp = imgUrl.split("/");
|
|
|
String fileName = pathTemp[pathTemp.length - 1];
|
|
|
byte[] fileBytes = getImgBytes(imgUrl);
|
|
|
- HttpRequest request = HttpUtil.createPost(recogeUrlByA);
|
|
|
+ HttpRequest request = HttpUtil.createPost(recogeUrlByCbdA);
|
|
|
request.basicAuth(username, password);
|
|
|
request.form("imageFile", fileBytes, fileName);
|
|
|
String response = request.execute().body();
|
|
|
@@ -49,7 +64,7 @@ public class YfCbdRecogeService {
|
|
|
String[] pathTemp = imgUrl.split("/");
|
|
|
String fileName = pathTemp[pathTemp.length - 1];
|
|
|
byte[] fileBytes = getImgBytes(imgUrl);
|
|
|
- HttpRequest request = HttpUtil.createPost(recogeUrlByB);
|
|
|
+ HttpRequest request = HttpUtil.createPost(recogeUrlByCbdB);
|
|
|
request.header(Header.USER_AGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36");
|
|
|
request.basicAuth(username, password);
|
|
|
request.contentType("multipart/form-data");
|
|
|
@@ -58,6 +73,19 @@ public class YfCbdRecogeService {
|
|
|
return getRecogeResult(response);
|
|
|
}
|
|
|
|
|
|
+ public JSONObject getRecogeResultByXct(String imgUrl){
|
|
|
+ String[] pathTemp = imgUrl.split("/");
|
|
|
+ String fileName = pathTemp[pathTemp.length - 1];
|
|
|
+ byte[] fileBytes = getImgBytes(imgUrl);
|
|
|
+ HttpRequest request = HttpUtil.createPost(recogeUrlByXct);
|
|
|
+ request.header(Header.USER_AGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36");
|
|
|
+ request.basicAuth(username, password);
|
|
|
+ request.contentType("multipart/form-data");
|
|
|
+ request.form("imageFile", fileBytes, fileName);
|
|
|
+ String response = request.execute().body();
|
|
|
+ return getXctRecogeResult(response);
|
|
|
+ }
|
|
|
+
|
|
|
// public static void main(String[] args) {
|
|
|
// YfCbdRecogeService service = new YfCbdRecogeService();
|
|
|
// JSONObject result = service.getRecogeResultByA("https://web.hnyfwlw.com:58003/Basics/cbd/864865062128484/2024/9/29/864865062128484-20240929-004951.jpg");
|