Selaa lähdekoodia

获取 应用权限接口

yurk 2 vuotta sitten
vanhempi
commit
d9fd008a85

+ 14 - 10
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/WeiXinCorpController.java

@@ -126,6 +126,11 @@ public class WeiXinCorpController {
         public String jsTicket = null;
         public LocalDateTime expireTime = null;
     }
+    public static Map<String, AgentItem> agentCorpTicketMap = new HashMap<String,AgentItem>();
+    public class AgentItem {
+        public String jsTicket = null;
+        public LocalDateTime expireTime = null;
+    }
 
     @Resource
     SysConfigMapper sysConfigMapper;
@@ -204,38 +209,37 @@ public class WeiXinCorpController {
         try {
             User user = userMapper.selectById(token);
             WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", user.getCompanyId()));
-
-            Item item = corpTicketMap.get(wxCorpInfo.getCorpid());
-            if (item == null || item.expireTime.isBefore(LocalDateTime.now())) {
+            AgentItem agentItem = agentCorpTicketMap.get(wxCorpInfo.getCorpid());
+            if (agentItem == null || agentItem.expireTime.isBefore(LocalDateTime.now())) {
                 //重新获取
                 String getTicketUrl = "https://qyapi.weixin.qq.com/cgi-bin/ticket/get?access_token=ACCESS_TOKEN&type=agent_config";
                 String corpToken = getCorpAccessToken(wxCorpInfo);
                 getTicketUrl = getTicketUrl.replace("ACCESS_TOKEN", corpToken);
                 String forObject = this.restTemplate.getForObject(getTicketUrl, String.class);
                 JSONObject json = JSONObject.parseObject(forObject);
-                log.info("返回:"+json.toJSONString());
+                System.out.println("返回:"+json.toJSONString());
                 if (json.getIntValue("errcode") == 0) {
                     String ticket = json.getString("ticket");
-                    Item it = new Item();
+                    AgentItem it = new AgentItem();
                     it.expireTime = LocalDateTime.now().plusSeconds(7200);
                     it.jsTicket = ticket;
-                    corpTicketMap.put(wxCorpInfo.getCorpid(), it);
-                    item = it;
+                    agentCorpTicketMap.put(wxCorpInfo.getCorpid(), it);
+                    agentItem = it;
                 }
             }
-            if (item == null) {
+            if (agentItem == null) {
                 //msg.setError("jsapiTicket获取失败");
                 msg.setError(MessageUtils.message("wx.TicketError"));
                 return msg;
             }
-            log.info("jsTicket = " + item.jsTicket);
+            System.out.println("jsTicket = " + agentItem.jsTicket);
             // 随机数
             String nonce_str = Sha1Util.getNonceStr();
             String timestamp = Sha1Util.getTimeStamp();
             // 对以下字段进行签名
             SortedMap<String, String> packageParams = new TreeMap<String, String>();
             SortedMap<String, String> packageParam = new TreeMap<String, String>();
-            packageParam.put("jsapi_ticket", item.jsTicket);
+            packageParam.put("jsapi_ticket", agentItem.jsTicket);
             packageParam.put("noncestr", nonce_str);
             packageParam.put("timestamp", ""+timestamp);
             packageParam.put("url", url);