yangdamao 11 часов назад
Родитель
Сommit
6958be1d11

+ 3 - 3
zhichen-api/src/main/java/com/zhichen/controller/wx/WeChatJsApiController.java

@@ -6,11 +6,11 @@ import com.github.xiaoymin.knife4j.annotations.ApiSupport;
 import com.zhichen.common.core.domain.AjaxResult;
 import com.zhichen.common.core.redis.RedisCache;
 import com.zhichen.framework.web.service.WeChatSignatureService;
+import com.zhichen.modules.wx.bo.WxLoginBody;
 import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.Map;
 import java.util.concurrent.TimeUnit;

+ 14 - 0
zhichen-api/src/main/java/com/zhichen/controller/wx/WxLoginController.java

@@ -223,4 +223,18 @@ public class WxLoginController
         Map<String,String> map = wxLoginService.liveGzh_login(loginBody);
         return AjaxResult.success(map);
     }
+
+    /**
+     * 检测关注状态(前端调用)
+     *
+     * @param loginBody 检测关注状态(前端调用)
+     * @return 结果
+     */
+    @ApiOperation("检测关注状态")
+    @PostMapping("/app/common/wechat/checkFollowStatus")
+    public AjaxResult checkFollowStatus(@RequestBody WxLoginBody loginBody)
+    {
+        Map<String,String> map = wxLoginService.checkFollowStatus(loginBody);
+        return AjaxResult.success(map);
+    }
 }

+ 32 - 7
zhichen-framework/src/main/java/com/zhichen/framework/web/service/WxLoginService.java

@@ -1292,13 +1292,12 @@ public class WxLoginService implements IWxLoginService {
 
     @Override
     public Map<String, String> liveGzh_login(WxLoginBody loginBody) {
-//        initData();
-//        String param = String.format(gzh_wxAuthParam, gzh_appid, gzh_appsrcret, loginBody.getCode());
-//        String resultString = HttpUtils.sendGet(gzh_wxAuthUrl, param);
-//        //解析json
-//        JSONObject jsonObject = (JSONObject) JSONObject.parse(resultString);
-//        String openId = String.valueOf(jsonObject.get("openid"));
-        String openId = "omVp-2IJwoD9yY0nmkn03ZRI-Dd0";
+        initData();
+        String param = String.format(gzh_wxAuthParam, gzh_appid, gzh_appsrcret, loginBody.getCode());
+        String resultString = HttpUtils.sendGet(gzh_wxAuthUrl, param);
+        //解析json
+        JSONObject jsonObject = (JSONObject) JSONObject.parse(resultString);
+        String openId = String.valueOf(jsonObject.get("openid"));
         User user = iUserService.queryByOpenId(openId);;
         Map<String, String> map = new HashMap<>();
         if (user == null) {
@@ -1355,6 +1354,32 @@ public class WxLoginService implements IWxLoginService {
         return map;
     }
 
+    @Override
+    public Map<String, String> checkFollowStatus(WxLoginBody loginBody) {
+        initData();
+        String param = String.format(gzh_wxAuthParam, gzh_appid, gzh_appsrcret, loginBody.getCode());
+        String resultString = HttpUtils.sendGet(gzh_wxAuthUrl, param);
+        //解析json
+        JSONObject jsonObject = (JSONObject) JSONObject.parse(resultString);
+        String openId = String.valueOf(jsonObject.get("openid"));
+        String url = "https://api.weixin.qq.com/cgi-bin/user/info";
+        String param2 = String.format(
+                "access_token=%s&openid=%s&lang=zh_CN",
+                getWxGzhAccessToken(), openId
+        );
+        String result = HttpUtils.sendGet(url,param2);
+        JSONObject json = JSONObject.parseObject(result);
+
+        Map<String,String> map = new HashMap<>();
+        if (json.containsKey("subscribe")) {
+            Integer subscribe = json.getInteger("subscribe");
+            map.put("isFollow",subscribe.toString());
+            return map; // 1:关注, 0:未关注
+        }
+        map.put("isFollow","0");
+        return map;
+    }
+
     public Boolean subGzh(String openId) {
         String unionId = getWxGzhUserCgiInfo(openId);
         if (Validator.isNotEmpty(unionId)) {

+ 2 - 0
zhichen-system/src/main/java/com/zhichen/modules/wx/service/IWxLoginService.java

@@ -43,4 +43,6 @@ public interface IWxLoginService
     String getWxSmallStudyCentreLink();
 
     Map<String, String> liveGzh_login(WxLoginBody loginBody);
+
+    Map<String, String> checkFollowStatus(WxLoginBody loginBody);
 }