Browse Source

推送公众号消息时,向用户前端发送websocket消息

lighter 4 năm trước cách đây
mục cha
commit
b8aa67e7bd

+ 6 - 1
src/main/java/thyyxxk/wxservice_server/service/WxApiService.java

@@ -35,6 +35,7 @@ import thyyxxk.wxservice_server.entity.wxapi.GenMzPayQrcodeParam;
 import thyyxxk.wxservice_server.entity.wxapi.PushMessageParam;
 import thyyxxk.wxservice_server.entity.wxapi.WxPayOrder;
 import thyyxxk.wxservice_server.utils.*;
+import thyyxxk.wxservice_server.websocket.WebSocketServer;
 
 import java.nio.charset.StandardCharsets;
 import java.util.*;
@@ -438,7 +439,7 @@ public class WxApiService {
         int statusCode = response.getStatusLine().getStatusCode();
         String ret = EntityUtils.toString(response.getEntity());
         httpClient.close();
-        if (statusCode == 200) {
+        if (statusCode == ExceptionEnum.SUCCESS.getCode()) {
             long timesStamp = System.currentTimeMillis() / 1000;
             WxPayOrder order = new WxPayOrder();
             order.setAppId(PropertiesUtil.getProperty("appId"));
@@ -482,6 +483,10 @@ public class WxApiService {
             content.replace("touser", openId);
             String res = template.postForObject(wxUrl, content, String.class);
             log.info("推送消息:内容:{},结果:{}", content, res);
+            JSONObject resObj = JSONObject.parseObject(res);
+            if (resObj.getIntValue("errcode") == 0) {
+                WebSocketServer.sendMessage(openId, "您有一条新的本院公众号消息。");
+            }
         }
     }