Browse Source

添加用户是否关注公众号接口

jk-GitHub-coder 4 years ago
parent
commit
e370ff4a53

+ 36 - 0
YijiaRestful/src/main/java/com/platform/yijia/controller/AppUserInfoController.java

@@ -82,6 +82,42 @@ public class AppUserInfoController {
         return AesDecryptUtil.decryptEncryptedData(jsonObject.get("encryptedData").toString(), jsonObject.get("sessionKey").toString(), jsonObject.get("iv").toString(), "UTF-8").toString();
     }
 
+    //判断使用小程序支付的用户是否关注公众号
+    @RequestMapping(value = "/whetherFollowGzh", method = RequestMethod.GET)
+    @ResponseBody
+    public String whetherFollowGzh(@RequestParam String unionId, Integer stationId){
+        Gson gson =new Gson();
+        //返回结果集
+        ResultData resultData = null;
+        if (unionId !=null){
+            Map<String, String> param = new HashMap<>();
+            param.put("unionId", unionId);
+            param.put("userType", "1");
+            String openId = appUserInfoService.whetherFollowGzh(param);
+            if(openId !=null){
+                Map<String, String> m = stationService.getStationAppIdAndAppSecret(stationId);
+                String gzhAppId ="";
+                String gzhAppSecret ="";
+                String accessToken ="";
+                if(m !=null && m.containsKey("gzhAppId") && m.containsKey("gzhAppSecret")){
+                    gzhAppId = m.get("gzhAppId");
+                    gzhAppSecret = m.get("gzhAppSecret");
+                    accessToken  = this.getTokenByRedisCache(gzhAppId, gzhAppSecret);
+                    net.sf.json.JSONObject unionIdInfo = WeiXinUserUtil.getUnionIdInfo(accessToken, openId);
+                    if(unionIdInfo.containsKey("subscribe") && unionIdInfo.get("subscribe").equals("1")){
+                        resultData = ResultData.success(CodeMsg.SUCCESS);
+                    }else {
+                        resultData = ResultData.error(CodeMsg.NO_FollowGzh);
+                    }
+                }
+            }else {
+                resultData = ResultData.error(CodeMsg.USERGZHINFO_EXSIST);
+            }
+        }
+        return gson.toJson(resultData);
+    }
+
+
     //获取公众号信息
     @RequestMapping(value = "/getGzhUserInfo", method = RequestMethod.GET)
     @ResponseBody

+ 8 - 5
YijiaRestful/src/main/java/com/platform/yijia/controller/PayController.java

@@ -801,11 +801,14 @@ public class PayController {
                                     //客户公众号积分增加通知
                                     //customerPoints.getBlogOpenId()
                                     //weiXinPushIntegralInfo(infoMap.get("stationId").toString(), infoMap.get("consumer").toString(), customerPointsRecord.getIntegral().toString(), customerPoints.getPoints().toString(), customerPoints.getBlogOpenId());
-                                    this.weiXinPushIntegralInfo(infoMap.get("stationId").toString()
-                                            , infoMap.get("consumer").toString()
-                                            , customerPointsRecord.getIntegral().toString()
-                                            , customerPoints.getPoints().toString()
-                                            , "oJR5R6r4EJhaORFcPap70r_mtFZo");
+                                   if(customerPoints.getBlogOpenId() !=null){
+                                       this.weiXinPushIntegralInfo(infoMap.get("stationId").toString()
+                                               , infoMap.get("consumer").toString()
+                                               , customerPointsRecord.getIntegral().toString()
+                                               , customerPoints.getPoints().toString()
+                                               , customerPoints.getBlogOpenId());
+                                   }
+
                                 }
                             }
 

+ 7 - 0
YijiaRestful/src/main/java/com/platform/yijia/dao/AppUserInfoMapper.java

@@ -9,6 +9,13 @@ import org.apache.ibatis.annotations.Param;
 
 public interface AppUserInfoMapper {
 
+    /**
+     * 判断使用小程序支付的用户是否关注公众号
+     * @param map
+     * @return
+     */
+    String whetherFollowGzh(Map map);
+
     /***
      * 判断该App用户是否已注册
      * @param map

+ 7 - 0
YijiaRestful/src/main/java/com/platform/yijia/service/AppUserInfoService.java

@@ -24,4 +24,11 @@ public interface AppUserInfoService {
 
     //查询客户UnionId
     String getUserUnionId(AppUserInfo appUserInfo);
+
+    /**
+     * 判断使用小程序支付的用户是否关注公众号
+     * @param map
+     * @return
+     */
+    String whetherFollowGzh(Map map);
 }

+ 11 - 0
YijiaRestful/src/main/java/com/platform/yijia/service/impl/AppUserInfoServiceImpl.java

@@ -82,4 +82,15 @@ public class AppUserInfoServiceImpl implements AppUserInfoService {
     public String getUserUnionId(AppUserInfo appUserInfo) {
         return appUserInfoMapper.getUserUnionId(appUserInfo);
     }
+
+
+    /**
+     * 判断使用小程序支付的用户是否关注公众号
+     * @param map
+     * @return
+     */
+    @Override
+    public String whetherFollowGzh(Map map) {
+        return appUserInfoMapper.whetherFollowGzh(map);
+    }
 }

+ 3 - 1
YijiaRestful/src/main/java/com/platform/yijia/utils/CodeMsg.java

@@ -9,8 +9,10 @@ public class CodeMsg {
     public static CodeMsg SERVER_EXCEPTION = new CodeMsg(500100,"服务端异常");
     public static CodeMsg USER_NOT_EXSIST = new CodeMsg(-1,"用户不存在");
     public static CodeMsg USER_EXSIST = new CodeMsg(-1,"用户已存在");
-    public static CodeMsg ACCOUNT_DISABLE = new CodeMsg(-3,"该账号已被停用");
     public static CodeMsg PASSWORD_ERROR = new CodeMsg(-2,"密码错误");
+    public static CodeMsg ACCOUNT_DISABLE = new CodeMsg(-3,"该账号已被停用");
+    public static CodeMsg NO_FollowGzh = new CodeMsg(-4,"未关注公众号");
+    public static CodeMsg USERGZHINFO_EXSIST = new CodeMsg(-5,"系统暂无此用户公众号信息");
     public static CodeMsg SEARCH_FAIL = new CodeMsg(001,"查询失败");
     public static CodeMsg INSERT_FAIL = new CodeMsg(001,"添加失败");
 

+ 17 - 0
YijiaRestful/src/main/resources/mapper/AppUserInfoMapper.xml

@@ -458,5 +458,22 @@
     </where>
   </update>
 
+  <!-- 判断使用小程序支付的用户是否关注公众号-->
+  <select id="whetherFollowGzh" parameterType="map" resultType="String">
+    SELECT
+        blog_openid AS openId
+    FROM
+        app_user_info
+    <where>
+      <if test="userType !=null and userType !=''">
+        user_type = #{userType}
+      </if>
+      <if test="unionId !=null and unionId !=''">
+        AND union_id = #{unionId}
+      </if>
+    </where>
+
+  </select>
+
 
 </mapper>