|
@@ -1,16 +1,20 @@
|
|
|
package com.book.push.service.wx.impl;
|
|
|
|
|
|
+import com.book.dao.cps.pojo.AdminConfig;
|
|
|
import com.book.dao.cps.pojo.Platform;
|
|
|
import com.book.push.config.RedisProperties;
|
|
|
import com.book.push.config.WxOpenInRedisBookConfigStorage;
|
|
|
import com.book.push.handler.*;
|
|
|
+import com.book.push.service.dao.AdminConfigService;
|
|
|
import com.book.push.service.dao.PlatformService;
|
|
|
import com.book.push.service.redis.RedisService;
|
|
|
import com.book.push.service.wx.WxThirdPartService;
|
|
|
-import lombok.AllArgsConstructor;
|
|
|
+import com.book.push.utils.JsonUtils;
|
|
|
+import com.book.push.utils.Md5Util;
|
|
|
+import com.book.push.vo.AuthorizerInfo;
|
|
|
+import com.book.push.vo.ComponentInfo;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import me.chanjar.weixin.open.api.WxOpenService;
|
|
|
-import me.chanjar.weixin.open.api.impl.WxOpenInRedisConfigStorage;
|
|
|
import me.chanjar.weixin.open.api.impl.WxOpenServiceImpl;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -20,6 +24,7 @@ import org.springframework.stereotype.Service;
|
|
|
import redis.clients.jedis.JedisPool;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
@@ -63,6 +68,8 @@ public class WxThirdPartServiceImpl implements WxThirdPartService {
|
|
|
private RedisService redisService;
|
|
|
@Autowired
|
|
|
private JedisPool jedisPool;
|
|
|
+ @Autowired
|
|
|
+ private AdminConfigService adminConfigService;
|
|
|
|
|
|
private WxThirdPartMessageRouter wxThirdPartMessageRouter;
|
|
|
public static final String PLATFORM_KEY_PREFIX = "platformId_%d";
|
|
@@ -70,32 +77,37 @@ public class WxThirdPartServiceImpl implements WxThirdPartService {
|
|
|
|
|
|
@PostConstruct
|
|
|
public void init() {
|
|
|
-
|
|
|
+ logger.info("------------------------------ WxThirdPartServiceImpl init ----------------------------------");
|
|
|
Map<Integer, Platform> integerPlatformMap = platformService.selectAll();
|
|
|
Set<Integer> platFormIdSet = integerPlatformMap.keySet();
|
|
|
platFormIdSet.stream().forEach(id -> {
|
|
|
Platform platform = integerPlatformMap.get(id);
|
|
|
+ logger.info("platform_id:" + id + "-->"+platform.toString());
|
|
|
WxOpenService wxOpenService = new WxOpenServiceImpl();
|
|
|
- WxOpenInRedisBookConfigStorage inRedisConfigStorage = new WxOpenInRedisBookConfigStorage(jedisPool, String.format(PLATFORM_KEY_PREFIX, id));
|
|
|
+ WxOpenInRedisBookConfigStorage inRedisConfigStorage = new WxOpenInRedisBookConfigStorage(platform, jedisPool, String.format(PLATFORM_KEY_PREFIX, id));
|
|
|
inRedisConfigStorage.setComponentAppId(platform.getAppid());
|
|
|
inRedisConfigStorage.setComponentAppSecret(platform.getSecret());
|
|
|
|
|
|
- //FIXME 这里有错误,请注意修改
|
|
|
- if (redisService.get(inRedisConfigStorage.getVerifyTicketCacheKey())==null){
|
|
|
+
|
|
|
+ logger.info("从redis 取值 ComponentVerifyTicket ,key = " + inRedisConfigStorage.getVerifyTicketCacheKey());
|
|
|
+ if (redisService.get(inRedisConfigStorage.getVerifyTicketCacheKey()) == null) {
|
|
|
logger.error("ComponentVerifyTicket is null in redis for key :" + inRedisConfigStorage.getVerifyTicketCacheKey());
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
|
|
|
inRedisConfigStorage.setComponentVerifyTicket(redisService.get(inRedisConfigStorage.getVerifyTicketCacheKey()));
|
|
|
}
|
|
|
- if (redisService.get(inRedisConfigStorage.getComponentTokenCacheKey())==null){
|
|
|
+ logger.info("从redis 取值 ComponentToken ,key = " + inRedisConfigStorage.getComponentTokenCacheKey());
|
|
|
+ if (redisService.get(inRedisConfigStorage.getComponentTokenCacheKey()) == null) {
|
|
|
logger.error("ComponentToken is null in redis for key :" + inRedisConfigStorage.getComponentTokenCacheKey());
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
|
|
|
inRedisConfigStorage.setComponentToken(redisService.get(inRedisConfigStorage.getComponentTokenCacheKey()));
|
|
|
}
|
|
|
|
|
|
+
|
|
|
inRedisConfigStorage.setComponentAesKey(platform.getAesKey());
|
|
|
wxOpenService.setWxOpenConfigStorage(inRedisConfigStorage);
|
|
|
+ updateAllAuthorizerAccessToken(inRedisConfigStorage);
|
|
|
wxOpenServiceMap.put(id, wxOpenService);
|
|
|
});
|
|
|
|
|
@@ -142,7 +154,34 @@ public class WxThirdPartServiceImpl implements WxThirdPartService {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private void updateAllAuthorizerAccessToken(WxOpenInRedisBookConfigStorage wxOpenInRedisBookConfigStorage) {
|
|
|
+ logger.info("updateAllAuthorizerAccessToken... ");
|
|
|
+ Platform platform = wxOpenInRedisBookConfigStorage.getPlatform();
|
|
|
+ List<AdminConfig> list = adminConfigService.selectByPlatformId(platform.getId());
|
|
|
+ for (AdminConfig adminConfig : list) {
|
|
|
+ logger.info("adminConfig:" + "-->"+adminConfig.toString());
|
|
|
+
|
|
|
+ String appid = adminConfig.getAppid();
|
|
|
+
|
|
|
+ String json = adminConfig.getJson().toString();
|
|
|
+ AdminConfig.Info info = JsonUtils.getObject(json, AdminConfig.Info.class);
|
|
|
+ AdminConfig.AuthorizationInfo authorization_info = info.getAuthorization_info();
|
|
|
+ String authorizer_refresh_token = authorization_info.getAuthorizer_refresh_token();
|
|
|
+ wxOpenInRedisBookConfigStorage.updateAuthorizerRefreshToken(appid, authorizer_refresh_token);
|
|
|
+ AuthorizerInfo authorizerInfo = new AuthorizerInfo(wxOpenInRedisBookConfigStorage.getComponentAppId(), appid, adminConfig.getRefreshToken());
|
|
|
+ String authorizerTokenCacheKey = wxOpenInRedisBookConfigStorage.getAuthorizerTokenCacheKey(authorizerInfo);
|
|
|
+ String token = redisService.get(authorizerTokenCacheKey);
|
|
|
+ if (token == null) {
|
|
|
+ logger.error("AuthorizerToken is null in redis for key :" + authorizerTokenCacheKey);
|
|
|
+ } else {
|
|
|
+ wxOpenInRedisBookConfigStorage.updateAuthorizerAccessToken(appid, token, redisService.getExpiresTime(authorizerTokenCacheKey).intValue());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
@Override
|
|
@@ -154,4 +193,22 @@ public class WxThirdPartServiceImpl implements WxThirdPartService {
|
|
|
public WxThirdPartMessageRouter getWxThirdPartMessageRouter() {
|
|
|
return this.wxThirdPartMessageRouter;
|
|
|
}
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ ComponentInfo componentInfo = new ComponentInfo("wxa6f2133192bfbcac", "a828e6b5eb87419e50826c60b9a20201"
|
|
|
+ , "ticket@@@kI-lexDGVC9dLKjHuXesqMt8sabH42EJyyRo9ben7uXISTMdDyBkxT-j53rCDZpWOkB2PuYMYiLenH6Y9FloEg");
|
|
|
+ System.out.println(JsonUtils.toJsonString(componentInfo));
|
|
|
+ String s = WxThirdPartService.COMPONENT_TOKEN_KEY_PREFIX + Md5Util.md5(JsonUtils.toJsonString(componentInfo));
|
|
|
+
|
|
|
+ System.out.println(s);
|
|
|
+
|
|
|
+ //
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ AuthorizerInfo authorizerInfo = new AuthorizerInfo("wxa6f2133192bfbcac","wxe1271417b2ff5b1c","refreshtoken@@@N0INeuo9aWT1PdFNIfSTynUm8eI5gGp9fmg_SAG69p8");
|
|
|
+ System.out.println(JsonUtils.toJsonString(authorizerInfo));
|
|
|
+ String s1 = WxThirdPartService.COMPONENT_TOKEN_KEY_PREFIX + Md5Util.md5(JsonUtils.toJsonString(authorizerInfo));
|
|
|
+ System.out.println(s1);
|
|
|
+ }
|
|
|
}
|