|
@@ -1,5 +1,6 @@
|
|
|
package com.management.platform.controller;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.management.platform.entity.Custom;
|
|
@@ -20,6 +21,8 @@ import org.apache.http.util.EntityUtils;
|
|
|
import org.dom4j.Document;
|
|
|
import org.dom4j.DocumentHelper;
|
|
|
import org.dom4j.Element;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
@@ -50,6 +53,12 @@ public class WechatCallbackController {
|
|
|
@Resource
|
|
|
private WechatAccountService wechatAccountService;
|
|
|
|
|
|
+ @Value(value = "${wxqr.app_id}")
|
|
|
+ private String appId;
|
|
|
+
|
|
|
+ @Value(value = "${wxqr.app_secret}")
|
|
|
+ private String appsecret;
|
|
|
+
|
|
|
private final ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
|
|
// 微信配置验证接口(GET请求)
|
|
@@ -225,7 +234,8 @@ public class WechatCallbackController {
|
|
|
if (StringUtils.isNotEmpty(userId)){
|
|
|
accessToken= getAccessToken(userId);
|
|
|
}else {
|
|
|
- accessToken= getAccessToken();
|
|
|
+ accessToken= getAccessToken(appId,appsecret);
|
|
|
+ log.info("accessToken==>"+accessToken);
|
|
|
}
|
|
|
if (accessToken == null) {
|
|
|
return null;
|
|
@@ -271,4 +281,16 @@ public class WechatCallbackController {
|
|
|
return wechatAccountService.getAccessToken(wechatAccount.getCompanyId(), wechatAccount.getAppId());
|
|
|
}
|
|
|
|
|
|
+ public String getAccessToken(String appId, String appSecret) {
|
|
|
+ String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appId + "&secret=" + appSecret;
|
|
|
+ log.info("url==>"+url);
|
|
|
+ try {
|
|
|
+ ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
|
|
|
+ JSONObject json = JSONObject.parseObject(response.getBody());
|
|
|
+ return json.getString("access_token");
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException("获取access_token失败", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|