|
|
@@ -773,17 +773,35 @@ public class FsCourseLinkServiceImpl implements IFsCourseLinkService
|
|
|
CloseableHttpClient client = null;
|
|
|
try {
|
|
|
client = HttpClients.createDefault();
|
|
|
- String[] split = linkStr.split("\\?.*?=");
|
|
|
- String key = linkStr.replaceAll(".*\\?(.*?)=.*", "$1");
|
|
|
- if (split.length == 2 && split[0].length() > 0 && split[1].length() > 0) {
|
|
|
- //处理页面路径
|
|
|
- String pageUrl = split[0];
|
|
|
- if (pageUrl.startsWith("/")) {
|
|
|
- pageUrl = pageUrl.substring(1);
|
|
|
+ int queryIndex = linkStr.indexOf("?");
|
|
|
+ if (queryIndex == -1 || queryIndex == linkStr.length() - 1) {
|
|
|
+ return "链接格式错误,缺少参数";
|
|
|
+ }
|
|
|
+ String pageUrl = linkStr.substring(0, queryIndex);
|
|
|
+ String queryString = linkStr.substring(queryIndex + 1);
|
|
|
+ if (pageUrl.startsWith("/")) {
|
|
|
+ pageUrl = pageUrl.substring(1);
|
|
|
+ }
|
|
|
+ String[] paramPairs = queryString.split("&");
|
|
|
+ StringBuilder encodedQuery = new StringBuilder();
|
|
|
+ for (int i = 0; i < paramPairs.length; i++) {
|
|
|
+ String pair = paramPairs[i];
|
|
|
+ int equalIndex = pair.indexOf("=");
|
|
|
+ if (equalIndex > 0 && equalIndex < pair.length() - 1) {
|
|
|
+ String key = pair.substring(0, equalIndex);
|
|
|
+ String value = pair.substring(equalIndex + 1);
|
|
|
+ if (encodedQuery.length() > 0) {
|
|
|
+ encodedQuery.append("&");
|
|
|
+ }
|
|
|
+ encodedQuery.append(key).append("=").append(URLEncoder.encode(value, StandardCharsets.UTF_8.toString()));
|
|
|
+ } else if (equalIndex == -1) {
|
|
|
+ if (encodedQuery.length() > 0) {
|
|
|
+ encodedQuery.append("&");
|
|
|
+ }
|
|
|
+ encodedQuery.append(pair);
|
|
|
}
|
|
|
- //处理参数
|
|
|
- String query = split[1];
|
|
|
- query = key + "=" + URLEncoder.encode(query, StandardCharsets.UTF_8.toString());
|
|
|
+ }
|
|
|
+ String query = encodedQuery.toString();
|
|
|
// String json = configService.selectConfigByKey("course.config");
|
|
|
// CourseConfig config = JSON.parseObject(json, CourseConfig.class);
|
|
|
// String miniprogramAppid = config.getMiniprogramAppid();
|
|
|
@@ -824,9 +842,7 @@ public class FsCourseLinkServiceImpl implements IFsCourseLinkService
|
|
|
if(null != jsonObject && !jsonObject.isEmpty() && jsonObject.containsKey("url_link")){
|
|
|
return jsonObject.getString("url_link");
|
|
|
}
|
|
|
- } else {
|
|
|
return "页面链接错误,获取失败";
|
|
|
- }
|
|
|
|
|
|
} catch (WxErrorException e) {
|
|
|
throw new RuntimeException(e);
|
|
|
@@ -835,7 +851,6 @@ public class FsCourseLinkServiceImpl implements IFsCourseLinkService
|
|
|
} catch (IOException e) {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
- return "";
|
|
|
}
|
|
|
|
|
|
@Override
|