|
@@ -12,6 +12,8 @@ import com.aliyun.green20220302.models.ImageModerationRequest;
|
|
|
import com.aliyun.green20220302.models.ImageModerationResponse;
|
|
|
import com.aliyun.green20220302.models.TextModerationRequest;
|
|
|
import com.aliyun.green20220302.models.TextModerationResponse;
|
|
|
+import com.aliyun.ocr_api20210707.models.RecognizeGeneralRequest;
|
|
|
+import com.aliyun.ocr_api20210707.models.RecognizeGeneralResponse;
|
|
|
import com.aliyun.teaopenapi.models.Config;
|
|
|
import com.aliyun.teautil.models.RuntimeOptions;
|
|
|
import com.chelvc.framework.aliyun.config.AliyunProperties;
|
|
@@ -32,6 +34,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
@Slf4j
|
|
|
public class DefaultAliyunHandler implements AliyunHandler {
|
|
|
private final String scene;
|
|
|
+ private final com.aliyun.ocr_api20210707.Client ocr;
|
|
|
private final com.aliyun.green20220302.Client green;
|
|
|
private final com.aliyun.captcha20230305.Client captcha;
|
|
|
private final com.aliyun.dypnsapi20170525.Client dypnsapi;
|
|
@@ -43,8 +46,13 @@ public class DefaultAliyunHandler implements AliyunHandler {
|
|
|
this.runtime.connectTimeout = 10000;
|
|
|
|
|
|
try {
|
|
|
- // 初始化green客户端
|
|
|
+ //初始化ocr客户端
|
|
|
Config config = this.getConfig(properties);
|
|
|
+ config.endpoint = "ocr-api.cn-hangzhou.aliyuncs.com";
|
|
|
+ this.ocr = new com.aliyun.ocr_api20210707.Client(config);
|
|
|
+
|
|
|
+ // 初始化green客户端
|
|
|
+ config = this.getConfig(properties);
|
|
|
config.endpoint = "green-cip.cn-shanghai.aliyuncs.com";
|
|
|
config.setRegionId("cn-shanghai");
|
|
|
config.setReadTimeout(6000);
|
|
@@ -172,4 +180,22 @@ public class DefaultAliyunHandler implements AliyunHandler {
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String recognizeGeneral(@NonNull RecognizeGeneralRequest request) {
|
|
|
+ RecognizeGeneralResponse response;
|
|
|
+ try {
|
|
|
+ response = this.ocr.recognizeGeneralWithOptions(request, this.runtime);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ if (response == null || response.body == null) {
|
|
|
+ throw new RuntimeException("Invalid aliyun response");
|
|
|
+ }
|
|
|
+ if (StringUtils.notEmpty(response.body.code)) {
|
|
|
+ log.error("Aliyun general recognize failed: {}, {}", response.body.code, response.body.message);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return response.body.data;
|
|
|
+ }
|
|
|
}
|