fix(asms): 截取问题
This commit is contained in:
+10
@@ -856,6 +856,16 @@ public class LawsAsmsOpenApiServiceImpl extends ServiceImpl<LawsAsmsOpenApiMappe
|
|||||||
|
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
String imageUrl = matcher.group(1);
|
String imageUrl = matcher.group(1);
|
||||||
|
int endIndex = 0;
|
||||||
|
try {
|
||||||
|
endIndex = imageUrl.indexOf("\" alt");
|
||||||
|
}catch (Exception e){
|
||||||
|
try {
|
||||||
|
endIndex = imageUrl.indexOf("\" />");
|
||||||
|
}catch (Exception e2){
|
||||||
|
endIndex = imageUrl.indexOf("\" >");
|
||||||
|
}
|
||||||
|
}
|
||||||
String urlSuffix = imageUrl.substring(imageUrl.indexOf("getImg"),
|
String urlSuffix = imageUrl.substring(imageUrl.indexOf("getImg"),
|
||||||
imageUrl.indexOf("\" alt"));
|
imageUrl.indexOf("\" alt"));
|
||||||
String url = asmsPostUtil.getHost() + urlSuffix;
|
String url = asmsPostUtil.getHost() + urlSuffix;
|
||||||
|
|||||||
+38
-19
@@ -598,26 +598,45 @@ public class SynchronizationAsmsService {
|
|||||||
stringBuilder.append("<p>").append(articleContent).append("</p>");
|
stringBuilder.append("<p>").append(articleContent).append("</p>");
|
||||||
articleContent = stringBuilder.toString();
|
articleContent = stringBuilder.toString();
|
||||||
}else {
|
}else {
|
||||||
String urlSuffix = articleContent.substring(articleContent.indexOf("getImg"),
|
// 定义正则表达式匹配 img 标签及其属性值
|
||||||
articleContent.indexOf("\" alt"));
|
Pattern pattern = Pattern.compile("(<\\s*img[^>]*>)");
|
||||||
String imageUrl = asmsPostUtil.getHost() + urlSuffix;
|
Matcher matcher = pattern.matcher(articleContent);
|
||||||
String fileName = imageUrl.substring(imageUrl.lastIndexOf("/") + 1);
|
|
||||||
// 获取图片
|
while (matcher.find()) {
|
||||||
HttpHeaders headers = new HttpHeaders();
|
String imageUrl = matcher.group(1);
|
||||||
headers.set(HttpHeaders.USER_AGENT, "Mozilla/5.0");
|
int endIndex = 0;
|
||||||
headers.set(HttpHeaders.ACCEPT, MediaType.ALL_VALUE);
|
try {
|
||||||
HttpEntity<String> entity = new HttpEntity<>(headers);
|
endIndex = imageUrl.indexOf("\" alt");
|
||||||
ResponseEntity<byte[]> responseEntity = restTemplate.exchange(imageUrl, HttpMethod.GET, entity, byte[].class);
|
}catch (Exception e){
|
||||||
if (HttpStatus.OK == responseEntity.getStatusCode()) {
|
try {
|
||||||
byte[] imageBytes = responseEntity.getBody();
|
endIndex = imageUrl.indexOf("\" />");
|
||||||
MultipartFile file = new MockMultipartFile(fileName, fileName, "application/octet-stream", imageBytes);
|
}catch (Exception e2){
|
||||||
// 上传图片
|
endIndex = imageUrl.indexOf("\" >");
|
||||||
OSSFile oSSFile = ossFileService.uploadLocalForSplit(file, "", "", "");
|
}
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
}
|
||||||
stringBuilder.append("<p>").append("<img class=\"wordImg\" style=\"width:100%;height:100%\" src=\"")
|
String urlSuffix = imageUrl.substring(imageUrl.indexOf("getImg"),
|
||||||
.append(oSSFile.getUrl()).append("\">").append("</p>");
|
endIndex);
|
||||||
articleContent = stringBuilder.toString();
|
String url = asmsPostUtil.getHost() + urlSuffix;
|
||||||
|
String fileName = url.substring(url.lastIndexOf("/") + 1);
|
||||||
|
// 获取图片
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.set(HttpHeaders.USER_AGENT, "Mozilla/5.0");
|
||||||
|
headers.set(HttpHeaders.ACCEPT, MediaType.ALL_VALUE);
|
||||||
|
HttpEntity<String> entity = new HttpEntity<>(headers);
|
||||||
|
ResponseEntity<byte[]> responseEntity = restTemplate.exchange(url, HttpMethod.GET, entity, byte[].class);
|
||||||
|
if (HttpStatus.OK == responseEntity.getStatusCode()) {
|
||||||
|
byte[] imageBytes = responseEntity.getBody();
|
||||||
|
MultipartFile file = new MockMultipartFile(fileName, fileName,"application/octet-stream" ,imageBytes);
|
||||||
|
// 上传图片
|
||||||
|
OSSFile oSSFile = ossFileService.uploadLocalForSplit(file, "", "", "");
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
stringBuilder.append("<img class=\"wordImg\" style=\"width:100%;height:100%\" src=\"")
|
||||||
|
.append(oSSFile.getUrl()).append("\">");
|
||||||
|
// 在此处进行替换操作,将图片链接替换为新的地址或者删除该图片标签等
|
||||||
|
articleContent = articleContent.replaceAll(imageUrl,stringBuilder.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return articleContent;
|
return articleContent;
|
||||||
|
|||||||
Reference in New Issue
Block a user