|
@@ -12,8 +12,10 @@ import com.fs.common.utils.StringUtils;
|
|
|
import com.fs.common.utils.date.DateUtil;
|
|
|
import com.fs.company.mapper.CompanyUserMapper;
|
|
|
import com.fs.config.cloud.CloudHostProper;
|
|
|
+import com.fs.core.config.WxMaConfig;
|
|
|
import com.fs.core.config.WxMaConfiguration;
|
|
|
import com.fs.course.config.CourseConfig;
|
|
|
+import com.fs.course.config.CourseMaConfig;
|
|
|
import com.fs.course.domain.*;
|
|
|
import com.fs.course.mapper.FsCourseDomainNameMapper;
|
|
|
import com.fs.course.mapper.FsCourseLinkMapper;
|
|
@@ -25,6 +27,7 @@ import com.fs.course.service.IFsCourseLinkService;
|
|
|
import com.fs.course.service.IFsUserCourseService;
|
|
|
import com.fs.his.config.FsSysConfig;
|
|
|
import com.fs.his.utils.ConfigUtil;
|
|
|
+import com.fs.his.utils.HttpUtil;
|
|
|
import com.fs.qw.domain.QwGroupChat;
|
|
|
import com.fs.qw.domain.QwGroupChatUser;
|
|
|
import com.fs.qw.domain.QwUser;
|
|
@@ -33,8 +36,12 @@ import com.fs.qw.mapper.QwUserMapper;
|
|
|
import com.fs.qw.service.IQwGroupChatService;
|
|
|
import com.fs.qw.service.IQwGroupChatUserService;
|
|
|
import com.fs.qw.vo.GroupUserExternalVo;
|
|
|
+import com.fs.system.domain.SysConfig;
|
|
|
+import com.fs.system.mapper.SysConfigMapper;
|
|
|
import com.fs.system.service.ISysConfigService;
|
|
|
import com.fs.voice.utils.StringUtil;
|
|
|
+import com.google.common.reflect.TypeToken;
|
|
|
+import com.google.gson.Gson;
|
|
|
import lombok.Synchronized;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
|
|
@@ -42,6 +49,7 @@ import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
import me.chanjar.weixin.mp.api.WxMpService;
|
|
|
import org.apache.http.HttpEntity;
|
|
|
import org.apache.http.client.ClientProtocolException;
|
|
|
+import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
import org.apache.http.client.methods.HttpPost;
|
|
|
import org.apache.http.entity.StringEntity;
|
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
@@ -104,9 +112,15 @@ public class FsCourseLinkServiceImpl implements IFsCourseLinkService
|
|
|
@Autowired
|
|
|
private CompanyUserMapper companyUserMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ConfigUtil configUtil;
|
|
|
+
|
|
|
@Autowired
|
|
|
CloudHostProper cloudHostProper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SysConfigMapper sysConfigMapper;
|
|
|
+
|
|
|
private static String TOKEN_VALID_CODE = "40001";
|
|
|
|
|
|
private volatile Integer version = 0;
|
|
@@ -817,4 +831,87 @@ public class FsCourseLinkServiceImpl implements IFsCourseLinkService
|
|
|
}
|
|
|
return "";
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R getWxaCodeGenerateScheme(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("/")) {
|
|
|
+// pageUrl = pageUrl.substring(1);
|
|
|
+ pageUrl = "pages_course/video";
|
|
|
+ }
|
|
|
+ //处理参数
|
|
|
+ String query = split[1];
|
|
|
+ query = URLEncoder.encode(query, StandardCharsets.UTF_8.toString());
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ SysConfig sysConfig3 = sysConfigMapper.selectConfigByConfigKey("courseMa.config");
|
|
|
+ List<CourseMaConfig> courseMaConfigs = JSON.parseArray(sysConfig3.getConfigValue(), CourseMaConfig.class);
|
|
|
+ if (courseMaConfigs!=null&& !courseMaConfigs.isEmpty()){
|
|
|
+ for (CourseMaConfig courseMaConfig : courseMaConfigs) {
|
|
|
+ if (appId.equals(courseMaConfig.getAppid())) {
|
|
|
+
|
|
|
+ //获取微信token
|
|
|
+
|
|
|
+ String url="https://api.weixin.qq.com/cgi-bin/stable_token";
|
|
|
+ HashMap<String, String> map = new HashMap<>();
|
|
|
+ map.put("grant_type","client_credential");
|
|
|
+ map.put("appid",courseMaConfig.getAppid());
|
|
|
+ map.put("secret",courseMaConfig.getSecret());
|
|
|
+
|
|
|
+
|
|
|
+ String accessToken = HttpUtil.endApi(url, null, map);
|
|
|
+
|
|
|
+ Map<String, String> accessTokenMap = new Gson().fromJson(accessToken, new TypeToken<Map<String, Object>>(){}.getType());
|
|
|
+
|
|
|
+
|
|
|
+ HttpPost httpPost = new HttpPost("https://api.weixin.qq.com/wxa/generate_urllink?access_token=" + accessTokenMap.get("access_token"));
|
|
|
+ JSONObject bodyObj = new JSONObject();
|
|
|
+ bodyObj.put("path", pageUrl);
|
|
|
+ bodyObj.put("query", query);
|
|
|
+ bodyObj.put("env_version", "release");
|
|
|
+
|
|
|
+ StringEntity entity = new StringEntity(bodyObj.toJSONString(),"UTF-8");
|
|
|
+ httpPost.setEntity(entity);
|
|
|
+ httpPost.setHeader("Content-type", "application/json");
|
|
|
+ httpPost.setHeader("cache-control","max-age=0");
|
|
|
+ HttpEntity response = client.execute(httpPost).getEntity();
|
|
|
+ String responseString = EntityUtils.toString(response);
|
|
|
+
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(responseString);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if(null != jsonObject && !jsonObject.isEmpty() && jsonObject.containsKey("url_link")){
|
|
|
+ return R.ok().put("urlLink",jsonObject.getString("url_link")) ;
|
|
|
+ }else {
|
|
|
+ return R.error("获取失败:"+jsonObject.getString("errmsg"));
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ return R.error("未配置小程序id");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ } else {
|
|
|
+ return R.error("页面链接错误,获取失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (ClientProtocolException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|