Browse Source

三方平台

lijilei 3 years ago
parent
commit
89dbc92f07

+ 2 - 0
book-dao/src/main/java/com/book/dao/cps/mapper/AdminConfigMapper.java

@@ -23,4 +23,6 @@ public interface AdminConfigMapper {
     List<AdminConfig> selectAll();
     List<AdminConfig> selectAll();
 
 
     AdminConfig selectByAppid(@Param("appid")String appid);
     AdminConfig selectByAppid(@Param("appid")String appid);
+
+    List<AdminConfig> selectByPlatformId(@Param("platform_id") Integer id);
 }
 }

+ 5 - 0
book-dao/src/main/resources/mapper/cps/AdminConfigMapper.xml

@@ -123,6 +123,11 @@
         where appid = #{appid,jdbcType=VARCHAR}
         where appid = #{appid,jdbcType=VARCHAR}
 
 
     </select>
     </select>
+    <select id="selectByPlatformId" resultMap="BaseResultMap">
+        select *
+        from admin_config
+        where platform_id = #{platform_id,jdbcType=INTEGER}
+    </select>
     <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
     <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
         delete
         delete
         from admin_config
         from admin_config

+ 20 - 9
book-push/src/main/java/com/book/push/config/WxOpenInRedisBookConfigStorage.java

@@ -1,11 +1,14 @@
 package com.book.push.config;
 package com.book.push.config;
 
 
+import com.book.dao.cps.pojo.Platform;
 import com.book.push.service.wx.WxThirdPartService;
 import com.book.push.service.wx.WxThirdPartService;
 import com.book.push.utils.JsonUtils;
 import com.book.push.utils.JsonUtils;
 import com.book.push.utils.Md5Util;
 import com.book.push.utils.Md5Util;
 import com.book.push.vo.AuthorizerInfo;
 import com.book.push.vo.AuthorizerInfo;
 import com.book.push.vo.ComponentInfo;
 import com.book.push.vo.ComponentInfo;
+import lombok.Getter;
 import lombok.NonNull;
 import lombok.NonNull;
+import lombok.Setter;
 import me.chanjar.weixin.open.api.impl.WxOpenInRedisConfigStorage;
 import me.chanjar.weixin.open.api.impl.WxOpenInRedisConfigStorage;
 import redis.clients.jedis.Jedis;
 import redis.clients.jedis.Jedis;
 import redis.clients.jedis.util.Pool;
 import redis.clients.jedis.util.Pool;
@@ -18,11 +21,17 @@ import redis.clients.jedis.util.Pool;
  */
  */
 
 
 public class WxOpenInRedisBookConfigStorage extends WxOpenInRedisConfigStorage {
 public class WxOpenInRedisBookConfigStorage extends WxOpenInRedisConfigStorage {
-
+    @Getter
+    @Setter
+    private Platform platform;
 
 
     public WxOpenInRedisBookConfigStorage(@NonNull Pool<Jedis> jedisPool, String keyPrefix) {
     public WxOpenInRedisBookConfigStorage(@NonNull Pool<Jedis> jedisPool, String keyPrefix) {
         super(jedisPool, keyPrefix);
         super(jedisPool, keyPrefix);
     }
     }
+    public WxOpenInRedisBookConfigStorage(Platform platform,@NonNull Pool<Jedis> jedisPool, String keyPrefix) {
+        super(jedisPool, keyPrefix);
+        this.platform = platform;
+    }
 
 
     public String getVerifyTicketCacheKey(String appid) {
     public String getVerifyTicketCacheKey(String appid) {
         return WxThirdPartService.VERIFY_TICKET_KEY_PREFIX + appid;
         return WxThirdPartService.VERIFY_TICKET_KEY_PREFIX + appid;
@@ -38,7 +47,7 @@ public class WxOpenInRedisBookConfigStorage extends WxOpenInRedisConfigStorage {
 
 
     public String getComponentTokenCacheKey(ComponentInfo componentInfo) {
     public String getComponentTokenCacheKey(ComponentInfo componentInfo) {
 
 
-        return WxThirdPartService.TOKEN_KEY_PREFIX + Md5Util.md5(JsonUtils.toJsonString(componentInfo));
+        return WxThirdPartService.COMPONENT_TOKEN_KEY_PREFIX + Md5Util.md5(JsonUtils.toJsonString(componentInfo));
     }
     }
 
 
     public String getComponentTokenCacheKey() {
     public String getComponentTokenCacheKey() {
@@ -50,32 +59,34 @@ public class WxOpenInRedisBookConfigStorage extends WxOpenInRedisConfigStorage {
         if (this.getComponentAppSecret() == null) {
         if (this.getComponentAppSecret() == null) {
             System.out.println("ComponentAppSecret is null, please set  ComponentAppSecret");
             System.out.println("ComponentAppSecret is null, please set  ComponentAppSecret");
         }
         }
-        if(this.getComponentVerifyTicket() == null){
+        if (this.getComponentVerifyTicket() == null) {
             System.out.println("ComponentVerifyTicket is null, please set  ComponentVerifyTicket");
             System.out.println("ComponentVerifyTicket is null, please set  ComponentVerifyTicket");
         }
         }
         ComponentInfo componentInfo = new ComponentInfo(getComponentAppId(), getComponentAppSecret(), getComponentVerifyTicket());
         ComponentInfo componentInfo = new ComponentInfo(getComponentAppId(), getComponentAppSecret(), getComponentVerifyTicket());
-        return WxThirdPartService.TOKEN_KEY_PREFIX + Md5Util.md5(JsonUtils.toJsonString(componentInfo));
+        return WxThirdPartService.COMPONENT_TOKEN_KEY_PREFIX + Md5Util.md5(JsonUtils.toJsonString(componentInfo));
     }
     }
 
 
 
 
     public String getAuthorizerTokenCacheKey(AuthorizerInfo authorizerInfo) {
     public String getAuthorizerTokenCacheKey(AuthorizerInfo authorizerInfo) {
 
 
-        return WxThirdPartService.TOKEN_KEY_PREFIX + Md5Util.md5(JsonUtils.toJsonString(authorizerInfo));
+        return WxThirdPartService.COMPONENT_TOKEN_KEY_PREFIX + Md5Util.md5(JsonUtils.toJsonString(authorizerInfo));
     }
     }
 
 
     @Override
     @Override
     public void setComponentVerifyTicket(String componentVerifyTicket) {
     public void setComponentVerifyTicket(String componentVerifyTicket) {
-        if (componentVerifyTicket==null){
-            throw new NullPointerException("componentVerifyTicket is null " );
+        if (componentVerifyTicket == null) {
+            throw new NullPointerException("componentVerifyTicket is null ");
         }
         }
         super.setComponentVerifyTicket(componentVerifyTicket);
         super.setComponentVerifyTicket(componentVerifyTicket);
     }
     }
 
 
     @Override
     @Override
     public void setComponentAccessToken(String componentAccessToken) {
     public void setComponentAccessToken(String componentAccessToken) {
-        if (componentAccessToken==null){
-            throw new NullPointerException("componentAccessToken is null " );
+        if (componentAccessToken == null) {
+            throw new NullPointerException("componentAccessToken is null ");
         }
         }
         super.setComponentAccessToken(componentAccessToken);
         super.setComponentAccessToken(componentAccessToken);
     }
     }
+
+
 }
 }

+ 1 - 0
book-push/src/main/java/com/book/push/service/dao/AdminConfigService.java

@@ -21,4 +21,5 @@ public interface AdminConfigService {
      AdminConfig selectByAdminId(Integer adminId);
      AdminConfig selectByAdminId(Integer adminId);
 
 
 
 
+    List<AdminConfig> selectByPlatformId(Integer id);
 }
 }

+ 5 - 0
book-push/src/main/java/com/book/push/service/dao/impl/AdminConfigServiceImpl.java

@@ -37,4 +37,9 @@ public class AdminConfigServiceImpl implements AdminConfigService {
     public AdminConfig selectByAdminId(Integer adminId) {
     public AdminConfig selectByAdminId(Integer adminId) {
         return adminConfigMapper.selectByPrimaryKey(adminId);
         return adminConfigMapper.selectByPrimaryKey(adminId);
     }
     }
+
+    @Override
+    public List<AdminConfig> selectByPlatformId(Integer id) {
+        return adminConfigMapper.selectByPlatformId(id);
+    }
 }
 }

+ 17 - 1
book-push/src/main/java/com/book/push/service/redis/RedisService.java

@@ -1,14 +1,30 @@
 package com.book.push.service.redis;
 package com.book.push.service.redis;
 
 
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
 /**
 /**
  * created in 2021/8/20
  * created in 2021/8/20
  * Project: book-store
  * Project: book-store
- *
+ * www.cnblogs.com/liuling/p/2014-4-19-04.html
  * @author win7
  * @author win7
  */
  */
 
 
 public interface RedisService {
 public interface RedisService {
+
     void set(String key, String value);
     void set(String key, String value);
 
 
     String get(String key);
     String get(String key);
+    Long getExpiresTime(String key);
+
+    void setMap(String key,Map<String, String> map);
+    List<String> getByMapKey(String key, String mapKey);
+    void setList(String key,String... val);
+    void setList(String key,List<String> list);
+    List<String> getList(String key,int begin,int end);
+
+    void setSet(String key, Set<String> set);
+
+    Set<String> getSet(String key);
 }
 }

+ 64 - 0
book-push/src/main/java/com/book/push/service/redis/impl/RedisServiceImpl.java

@@ -7,6 +7,10 @@ import org.springframework.stereotype.Service;
 import redis.clients.jedis.Jedis;
 import redis.clients.jedis.Jedis;
 import redis.clients.jedis.JedisPool;
 import redis.clients.jedis.JedisPool;
 
 
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
 /**
 /**
  * created in 2021/8/20
  * created in 2021/8/20
  * Project: book-store
  * Project: book-store
@@ -29,4 +33,64 @@ public class RedisServiceImpl implements RedisService {
         @Cleanup Jedis jedis = jedisPool.getResource();
         @Cleanup Jedis jedis = jedisPool.getResource();
         return jedis.get(key);
         return jedis.get(key);
     }
     }
+
+    @Override
+    public Long getExpiresTime(String key) {
+        @Cleanup Jedis jedis = jedisPool.getResource();
+        return jedis.ttl(key);
+
+    }
+
+    @Override
+    public void setMap(String key, Map<String, String> map) {
+        @Cleanup Jedis jedis = jedisPool.getResource();
+        jedis.hmset(key, map);
+    }
+
+    @Override
+    public List<String> getByMapKey(String key, String mapKey) {
+        @Cleanup Jedis jedis = jedisPool.getResource();
+        return jedis.hmget(key, mapKey);
+    }
+
+    @Override
+    public void setList(String key, String... val) {
+        @Cleanup Jedis jedis = jedisPool.getResource();
+        for (String s : val) {
+
+            jedis.lpush(key, s);
+        }
+    }
+
+    @Override
+    public void setList(String key, List<String> list) {
+        @Cleanup Jedis jedis = jedisPool.getResource();
+        for (String s : list) {
+
+            jedis.lpush(key, s);
+        }
+    }
+
+    @Override
+    public List<String> getList(String key, int begin, int end) {
+        @Cleanup Jedis jedis = jedisPool.getResource();
+        return jedis.lrange(key, begin, end);
+    }
+
+    @Override
+    public void setSet(String key, Set<String> set) {
+        @Cleanup Jedis jedis = jedisPool.getResource();
+        for (String s : set) {
+
+            jedis.sadd(key, s);
+        }
+    }
+
+    @Override
+    public Set<String> getSet(String key) {
+        @Cleanup Jedis jedis = jedisPool.getResource();
+        return jedis.smembers(key);
+    }
+
+
 }
 }

+ 2 - 1
book-push/src/main/java/com/book/push/service/wx/WxThirdPartService.java

@@ -14,7 +14,8 @@ import me.chanjar.weixin.open.api.WxOpenService;
 public interface WxThirdPartService {
 public interface WxThirdPartService {
 
 
     public static final String VERIFY_TICKET_KEY_PREFIX = "easywechat.open_platform.verify_ticket.";
     public static final String VERIFY_TICKET_KEY_PREFIX = "easywechat.open_platform.verify_ticket.";
-    public static final String TOKEN_KEY_PREFIX = "easywechat.kernel.access_token.";
+    public static final String COMPONENT_TOKEN_KEY_PREFIX = "easywechat.kernel.access_token.";
+    public static  final String AUTHORIZER_TOKEN_KEY_PREFIX = "easywechat.kernel.access_token.";
     WxOpenService getWxOpenServiceByPlatFormId(Integer platFormId);
     WxOpenService getWxOpenServiceByPlatFormId(Integer platFormId);
 
 
 
 

+ 2 - 0
book-push/src/main/java/com/book/push/vo/AuthorizerInfo.java

@@ -1,5 +1,6 @@
 package com.book.push.vo;
 package com.book.push.vo;
 
 
+import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.Data;
 
 
 /**
 /**
@@ -9,6 +10,7 @@ import lombok.Data;
  * @author win7
  * @author win7
  */
  */
 @Data
 @Data
+@AllArgsConstructor
 public class AuthorizerInfo {
 public class AuthorizerInfo {
  private String component_appid;
  private String component_appid;
  private String authorizer_appid;
  private String authorizer_appid;

+ 3 - 3
book-push/src/main/resources/application-pro.yml

@@ -1,8 +1,8 @@
 server:
 server:
-  port: 16063
+  port: 18089
 
 
 book:
 book:
-  debug: true
+  debug: false
   redis:
   redis:
     host: r-bp1fhw9pqpgtfnu638.redis.rds.aliyuncs.com
     host: r-bp1fhw9pqpgtfnu638.redis.rds.aliyuncs.com
     port: 6379
     port: 6379
@@ -136,4 +136,4 @@ logging:
     com:
     com:
       book:
       book:
         server:
         server:
-          mapper: debug
+          mapper: info

+ 3 - 0
book-server/src/main/java/com/book/server/config/Const.java

@@ -3,7 +3,10 @@ package com.book.server.config;
 public class Const {
 public class Const {
     public static final String CacheSplit = "_";
     public static final String CacheSplit = "_";
     public static final String EDIT_BOOK_PRE = "edit_book";
     public static final String EDIT_BOOK_PRE = "edit_book";
+
     public static  final  String URL_PAY_CENTER = "http://{appid}.{host}/home.html#/{page}?userId={userId}&payOpenid={openid}";
     public static  final  String URL_PAY_CENTER = "http://{appid}.{host}/home.html#/{page}?userId={userId}&payOpenid={openid}";
+
     public static final Long bookIdMin = 110_0001L;
     public static final Long bookIdMin = 110_0001L;
     public static final Long bookInMax = 110_9999L;
     public static final Long bookInMax = 110_9999L;
+
 }
 }

+ 1 - 1
book-server/src/main/java/com/book/server/service/impl/WxPayServiceImpl.java

@@ -246,7 +246,7 @@ public class WxPayServiceImpl implements WxPayService {
             String redirectUrl = "http://" + wxpay.getPayHost() + "/api/wxpay/page?userId=" + userId;
             String redirectUrl = "http://" + wxpay.getPayHost() + "/api/wxpay/page?userId=" + userId;
             String url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_base&state=%s#wechat_redirect";
             String url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_base&state=%s#wechat_redirect";
             try {
             try {
-                url = String.format(url, appid, URLEncoder.encode(redirectUrl, "UTF-8"), page);
+                url = String.format(url, appid, java.net.URLEncoder.encode(redirectUrl, "UTF-8"), page);
             } catch (UnsupportedEncodingException e) {
             } catch (UnsupportedEncodingException e) {
                 e.printStackTrace();
                 e.printStackTrace();
             }
             }