|
@@ -744,83 +744,84 @@ public class FsCourseLinkServiceImpl implements IFsCourseLinkService
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public String getGotoWxAppLink(String linkStr) {
|
|
|
-// CloseableHttpClient client = null;
|
|
|
-// try {
|
|
|
-// client = HttpClients.createDefault();
|
|
|
-// String[] split = linkStr.split("\\?");
|
|
|
-// if (split.length == 2 && split[0].length() > 0 && split[1].length() > 0) {
|
|
|
-// //处理页面路径
|
|
|
-// String pageUrl = split[0];
|
|
|
-// if (pageUrl.startsWith("/")) {
|
|
|
-// pageUrl = pageUrl.substring(1);
|
|
|
-// }
|
|
|
-// //处理参数
|
|
|
-// String query = split[1];
|
|
|
-// String json = configService.selectConfigByKey("course.config");
|
|
|
-// CourseConfig config = JSON.parseObject(json, CourseConfig.class);
|
|
|
-// String miniprogramAppid = config.getMiniprogramAppid();
|
|
|
-// if (StringUtils.isBlank(miniprogramAppid)) {
|
|
|
-// return "未配置点播小程序id";
|
|
|
-// }
|
|
|
-// if(StringUtils.isBlank(code)){
|
|
|
-// return "参数错误,请传入code";
|
|
|
-// }
|
|
|
-// //获取微信token
|
|
|
-// final WxMaService wxService = WxMaConfiguration.getMaService("wx76cb55db092a41ae");
|
|
|
-// String token = wxService.getAccessToken();
|
|
|
-// HttpPost httpPost = new HttpPost("https://api.weixin.qq.com/wxa/generate_urllink?access_token=" + token);
|
|
|
-// JSONObject bodyObj = new JSONObject();
|
|
|
-// bodyObj.put("path", pageUrl);
|
|
|
-// bodyObj.put("query", query);
|
|
|
-// log.info("微信小程序请求参数打印:{}", bodyObj.toJSONString());
|
|
|
-// StringEntity entity = new StringEntity(bodyObj.toJSONString(),"UTF-8");
|
|
|
-// httpPost.setEntity(entity);
|
|
|
-// httpPost.setHeader("Content-type", "application/json");
|
|
|
-// HttpEntity response = client.execute(httpPost).getEntity();
|
|
|
-// String responseString = EntityUtils.toString(response);
|
|
|
-// log.info("微信小程序接口响应数据:{}", responseString);
|
|
|
-// JSONObject jsonObject = JSONObject.parseObject(responseString);
|
|
|
-// if(null != jsonObject && !jsonObject.isEmpty() && jsonObject.containsKey("url_link")){
|
|
|
-// return jsonObject.getString("url_link");
|
|
|
-// }
|
|
|
-// } else {
|
|
|
-// return "页面链接错误,获取失败";
|
|
|
-// }
|
|
|
-//
|
|
|
-// } catch (WxErrorException e) {
|
|
|
-// throw new RuntimeException(e);
|
|
|
-// } catch (ClientProtocolException e) {
|
|
|
-// throw new RuntimeException(e);
|
|
|
-// } catch (IOException e) {
|
|
|
-// throw new RuntimeException(e);
|
|
|
-// }
|
|
|
- String json = configService.selectConfigByKey("course.config");
|
|
|
- CourseConfig config = JSON.parseObject(json, CourseConfig.class);
|
|
|
- String miniprogramAppid = config.getMiniprogramAppid();
|
|
|
- if (StringUtils.isBlank(miniprogramAppid)) {
|
|
|
- return "未配置点播小程序id";
|
|
|
- }
|
|
|
-// String envVersion = "trial";
|
|
|
-// String envVersion = version;
|
|
|
- if (StringUtils.isNotBlank(linkStr)) {
|
|
|
- //解析pageLink
|
|
|
+ public String getGotoWxAppLink(String linkStr,String appId) {
|
|
|
+ CloseableHttpClient client = null;
|
|
|
+ try {
|
|
|
+ client = HttpClients.createDefault();
|
|
|
String[] split = linkStr.split("\\?");
|
|
|
if (split.length == 2 && split[0].length() > 0 && split[1].length() > 0) {
|
|
|
//处理页面路径
|
|
|
- String pageUrl =split[0];
|
|
|
- if(pageUrl.startsWith("/")){
|
|
|
+ String pageUrl = split[0];
|
|
|
+ if (pageUrl.startsWith("/")) {
|
|
|
pageUrl = pageUrl.substring(1);
|
|
|
}
|
|
|
//处理参数
|
|
|
String query = split[1];
|
|
|
-// query = query.replace("\\u003d", "=");
|
|
|
- String wxAppLink = getWxAppLink(miniprogramAppid, pageUrl, query);
|
|
|
- return wxAppLink;
|
|
|
+ query = URLEncoder.encode(query, StandardCharsets.UTF_8.toString());
|
|
|
+ String json = configService.selectConfigByKey("course.config");
|
|
|
+ CourseConfig config = JSON.parseObject(json, CourseConfig.class);
|
|
|
+ String miniprogramAppid = config.getMiniprogramAppid();
|
|
|
+ if (StringUtils.isBlank(miniprogramAppid)) {
|
|
|
+ return "未配置点播小程序id";
|
|
|
+ }
|
|
|
+// if(StringUtils.isBlank(code)){
|
|
|
+// return "参数错误,请传入code";
|
|
|
+// }
|
|
|
+ //获取微信token
|
|
|
+ final WxMaService wxService = WxMaConfiguration.getMaService(appId);
|
|
|
+ String token = wxService.getAccessToken();
|
|
|
+ HttpPost httpPost = new HttpPost("https://api.weixin.qq.com/wxa/generate_urllink?access_token=" + token);
|
|
|
+ JSONObject bodyObj = new JSONObject();
|
|
|
+ bodyObj.put("path", pageUrl);
|
|
|
+ bodyObj.put("query", query);
|
|
|
+ log.info("微信小程序请求参数打印:{}", bodyObj.toJSONString());
|
|
|
+ StringEntity entity = new StringEntity(bodyObj.toJSONString(),"UTF-8");
|
|
|
+ httpPost.setEntity(entity);
|
|
|
+ httpPost.setHeader("Content-type", "application/json");
|
|
|
+ HttpEntity response = client.execute(httpPost).getEntity();
|
|
|
+ String responseString = EntityUtils.toString(response);
|
|
|
+ log.info("微信小程序接口响应数据:{}", responseString);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(responseString);
|
|
|
+ if(null != jsonObject && !jsonObject.isEmpty() && jsonObject.containsKey("url_link")){
|
|
|
+ return jsonObject.getString("url_link");
|
|
|
+ }
|
|
|
} else {
|
|
|
return "页面链接错误,获取失败";
|
|
|
}
|
|
|
+
|
|
|
+ } catch (WxErrorException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ } catch (ClientProtocolException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
}
|
|
|
+// String json = configService.selectConfigByKey("course.config");
|
|
|
+// CourseConfig config = JSON.parseObject(json, CourseConfig.class);
|
|
|
+// String miniprogramAppid = config.getMiniprogramAppid();
|
|
|
+// if (StringUtils.isBlank(miniprogramAppid)) {
|
|
|
+// return "未配置点播小程序id";
|
|
|
+// }
|
|
|
+//// String envVersion = "trial";
|
|
|
+//// String envVersion = version;
|
|
|
+// if (StringUtils.isNotBlank(linkStr)) {
|
|
|
+// //解析pageLink
|
|
|
+// String[] split = linkStr.split("\\?");
|
|
|
+// if (split.length == 2 && split[0].length() > 0 && split[1].length() > 0) {
|
|
|
+// //处理页面路径
|
|
|
+// String pageUrl =split[0];
|
|
|
+// if(pageUrl.startsWith("/")){
|
|
|
+// pageUrl = pageUrl.substring(1);
|
|
|
+// }
|
|
|
+// //处理参数
|
|
|
+// String query = split[1];
|
|
|
+//// query = query.replace("\\u003d", "=");
|
|
|
+// String wxAppLink = getWxAppLink(miniprogramAppid, pageUrl, query);
|
|
|
+// return wxAppLink;
|
|
|
+// } else {
|
|
|
+// return "页面链接错误,获取失败";
|
|
|
+// }
|
|
|
+// }
|
|
|
return "";
|
|
|
}
|
|
|
}
|