Browse Source

fix gc, pay,auth,qrcode retest

release_toaliyun_real
xiaohanzi 4 years ago
parent
commit
630283a588
13 changed files with 126 additions and 25 deletions
  1. +5
    -2
      mallinkBApi/src/main/java/com/iformall/controller/BaseController.java
  2. +5
    -2
      mallinkCApi/src/main/java/com/iformall/controller/BaseController.java
  3. +5
    -2
      mallinkPosApi/src/main/java/com/iformall/controller/BaseController.java
  4. +4
    -1
      mallinkSchedule/src/main/java/com/iformall/schedule/WeChatAccessTokenSchedule.java
  5. +4
    -1
      mallinkSchedule/src/main/java/com/iformall/schedule/WxAppVisitSchedule.java
  6. +2
    -1
      mallinkService/src/main/java/com/iformall/common/FmHttpClientBuilder.java
  7. +4
    -1
      mallinkService/src/main/java/com/iformall/service/impl/WxPayAccountServiceImpl.java
  8. +4
    -1
      mallinkService/src/main/java/com/iformall/service/impl/WxTemplateMsgServiceImpl.java
  9. +4
    -1
      mallinkService/src/main/java/com/iformall/service/msg/impl/SendSmartAppMsgServiceImpl.java
  10. +4
    -1
      mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/BaseWxPayAdapterService.java
  11. +77
    -10
      mallinkService/src/main/java/com/iformall/utils/MaUtil.java
  12. +4
    -1
      mallinkTTAdmin/src/main/java/com/iformall/controller/base/BaseController.java
  13. +4
    -1
      mallinkTTCApi/src/main/java/com/iformall/controller/BaseController.java

+ 5
- 2
mallinkBApi/src/main/java/com/iformall/controller/BaseController.java View File

@@ -46,6 +46,9 @@ public class BaseController {


@Autowired @Autowired
private WxBuserService wxBuserService; private WxBuserService wxBuserService;
@Autowired
MaUtil maUtil;


@InitBinder @InitBinder
public void InitBinder(WebDataBinder dataBinder) { public void InitBinder(WebDataBinder dataBinder) {
@@ -144,14 +147,14 @@ public class BaseController {
return openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); return openService.getWxOpenComponentService().getWxMaServiceByAppid(appId);
} else { } else {
WxAppinfo appinfo = wxAppinfoService.getByAppId(appId); WxAppinfo appinfo = wxAppinfoService.getByAppId(appId);
WxMaService service = MaUtil.getWeappService(appinfo);
WxMaService service = maUtil.getWeappService(appinfo);
return service; return service;
} }
} }


public WxMaService getWeappServiceByAppInfo(WxAppinfo appinfo) { public WxMaService getWeappServiceByAppInfo(WxAppinfo appinfo) {
if(!isFmOpen) { if(!isFmOpen) {
WxMaService service = MaUtil.getWeappService(appinfo);
WxMaService service = maUtil.getWeappService(appinfo);
return service; return service;
} }
return null; return null;


+ 5
- 2
mallinkCApi/src/main/java/com/iformall/controller/BaseController.java View File

@@ -70,6 +70,9 @@ public class BaseController {
@Qualifier("objectCommonRedisTemplate") @Qualifier("objectCommonRedisTemplate")
RedisTemplate<String, Object> objectCommonRedisTemplate; RedisTemplate<String, Object> objectCommonRedisTemplate;
@Autowired
MaUtil maUtil;
@InitBinder @InitBinder
public void InitBinder(WebDataBinder dataBinder) { public void InitBinder(WebDataBinder dataBinder) {
dataBinder.registerCustomEditor(Date.class, new PropertyEditorSupport() { dataBinder.registerCustomEditor(Date.class, new PropertyEditorSupport() {
@@ -204,7 +207,7 @@ public class BaseController {
if (appinfo == null) { if (appinfo == null) {
return null; return null;
} }
WxMaService service = MaUtil.getWeappService(appinfo);
WxMaService service = maUtil.getWeappService(appinfo);
return service; return service;
} }


@@ -212,7 +215,7 @@ public class BaseController {


public WxMaService getWeappServiceByAppInfo(WxAppinfo appinfo) { public WxMaService getWeappServiceByAppInfo(WxAppinfo appinfo) {
if(!isFmOpen) { if(!isFmOpen) {
WxMaService service = MaUtil.getWeappService(appinfo);
WxMaService service = maUtil.getWeappService(appinfo);
return service; return service;
} }
return null; return null;


+ 5
- 2
mallinkPosApi/src/main/java/com/iformall/controller/BaseController.java View File

@@ -30,6 +30,9 @@ public class BaseController {


@Autowired @Autowired
private FmOpenService openService; private FmOpenService openService;
@Autowired
MaUtil maUtil;


@InitBinder @InitBinder
public void InitBinder(WebDataBinder dataBinder) { public void InitBinder(WebDataBinder dataBinder) {
@@ -62,14 +65,14 @@ public class BaseController {
return openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); return openService.getWxOpenComponentService().getWxMaServiceByAppid(appId);
} else { } else {
WxAppinfo appinfo = wxAppinfoService.getByAppId(appId); WxAppinfo appinfo = wxAppinfoService.getByAppId(appId);
WxMaService service = MaUtil.getWeappService(appinfo);
WxMaService service = maUtil.getWeappService(appinfo);
return service; return service;
} }
} }


public WxMaService getWeappServiceByAppInfo(WxAppinfo appinfo) { public WxMaService getWeappServiceByAppInfo(WxAppinfo appinfo) {
if(!isFmOpen) { if(!isFmOpen) {
WxMaService service = MaUtil.getWeappService(appinfo);
WxMaService service = maUtil.getWeappService(appinfo);
return service; return service;
} }
return null; return null;


+ 4
- 1
mallinkSchedule/src/main/java/com/iformall/schedule/WeChatAccessTokenSchedule.java View File

@@ -24,6 +24,9 @@ public class WeChatAccessTokenSchedule {


@Autowired @Autowired
WxAppinfoMapper wxAppinfoMapper; WxAppinfoMapper wxAppinfoMapper;
@Autowired
MaUtil maUtil;




@Scheduled(cron = "0 1 * * * ?") // 每小时第一分钟执行 @Scheduled(cron = "0 1 * * * ?") // 每小时第一分钟执行
@@ -44,7 +47,7 @@ public class WeChatAccessTokenSchedule {
} }


public void resetAccessToken(WxAppinfo appinfo) { public void resetAccessToken(WxAppinfo appinfo) {
WxMaService wxMaService = MaUtil.getWeappService(appinfo);
WxMaService wxMaService = maUtil.getWeappService(appinfo);
try { try {
String accessToken = wxMaService.getAccessToken(true); String accessToken = wxMaService.getAccessToken(true);
WxAppinfo updateAppInfo = new WxAppinfo(); WxAppinfo updateAppInfo = new WxAppinfo();


+ 4
- 1
mallinkSchedule/src/main/java/com/iformall/schedule/WxAppVisitSchedule.java View File

@@ -44,6 +44,9 @@ public class WxAppVisitSchedule {


@Autowired @Autowired
private WxMallService wxMallService; private WxMallService wxMallService;
@Autowired
MaUtil maUtil;




@Scheduled(cron = "0 0 9/1 * * ? ") //早晨9点开始每小时取一次,获取前一日,微信时间为GMT @Scheduled(cron = "0 0 9/1 * * ? ") //早晨9点开始每小时取一次,获取前一日,微信时间为GMT
@@ -128,7 +131,7 @@ public class WxAppVisitSchedule {
if(isFmOpen) { if(isFmOpen) {
wxMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appInfo.getAppId()); wxMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appInfo.getAppId());
} else { } else {
wxMaService = MaUtil.getWeappService(appInfo);
wxMaService = maUtil.getWeappService(appInfo);
} }
try { try {
List<WxMaVisitTrend> vtList = wxMaService.getAnalysisService().getDailyVisitTrend(lastDate, lastDate); List<WxMaVisitTrend> vtList = wxMaService.getAnalysisService().getDailyVisitTrend(lastDate, lastDate);


+ 2
- 1
mallinkService/src/main/java/com/iformall/common/FmHttpClientBuilder.java View File

@@ -89,8 +89,9 @@ public class FmHttpClientBuilder implements ApacheHttpClientBuilder {
private FmHttpClientBuilder() { private FmHttpClientBuilder() {
} }


private static FmHttpClientBuilder instance = new FmHttpClientBuilder();
public static FmHttpClientBuilder get() { public static FmHttpClientBuilder get() {
return new FmHttpClientBuilder();
return instance;
} }


@Override @Override


+ 4
- 1
mallinkService/src/main/java/com/iformall/service/impl/WxPayAccountServiceImpl.java View File

@@ -27,6 +27,9 @@ public class WxPayAccountServiceImpl implements WxPayAccountService {


@Autowired @Autowired
WxAppinfoService wxAppinfoService; WxAppinfoService wxAppinfoService;
@Autowired
MaUtil maUtil;




@Override @Override
@@ -87,7 +90,7 @@ public class WxPayAccountServiceImpl implements WxPayAccountService {
WxAppinfo cAppInfo = wxAppinfoService.getCAppInfo(tenantEntity, EnumPayWay.PAY_WAY_WECHAT); WxAppinfo cAppInfo = wxAppinfoService.getCAppInfo(tenantEntity, EnumPayWay.PAY_WAY_WECHAT);
WxPayAccount payAccount = this.getByTenantId(tenantId); WxPayAccount payAccount = this.getByTenantId(tenantId);
if(cAppInfo != null && payAccount != null){ if(cAppInfo != null && payAccount != null){
return MaUtil.getWxPayService(cAppInfo,payAccount);
return maUtil.getWxPayService(cAppInfo,payAccount);
}else{ }else{
return null; return null;
} }


+ 4
- 1
mallinkService/src/main/java/com/iformall/service/impl/WxTemplateMsgServiceImpl.java View File

@@ -41,6 +41,9 @@ public class WxTemplateMsgServiceImpl implements WxTemplateMsgService {


@Autowired @Autowired
private FmOpenService openService; private FmOpenService openService;
@Autowired
MaUtil maUtil;




@Override @Override
@@ -121,7 +124,7 @@ public class WxTemplateMsgServiceImpl implements WxTemplateMsgService {
wxMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appinfo.getAppId()); wxMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appinfo.getAppId());
} else { } else {
WxAppinfo appInfo = wxAppinfoService.getByAppId(appinfo.getAppId()); WxAppinfo appInfo = wxAppinfoService.getByAppId(appinfo.getAppId());
wxMaService = MaUtil.getWeappService(appInfo);
wxMaService = maUtil.getWeappService(appInfo);
} }
String s = ""; String s = "";
if(byId.getType() == EnumTemplateType.ACTIVITY_REMIND.getCode()){ if(byId.getType() == EnumTemplateType.ACTIVITY_REMIND.getCode()){


+ 4
- 1
mallinkService/src/main/java/com/iformall/service/msg/impl/SendSmartAppMsgServiceImpl.java View File

@@ -48,6 +48,9 @@ public class SendSmartAppMsgServiceImpl implements MsgSendService {


@Autowired @Autowired
private WxCUserMapper wxCUserMapper; private WxCUserMapper wxCUserMapper;
@Autowired
MaUtil maUtil;


@Override @Override
public void send(BaseMsg baseMsg) throws Exception{ public void send(BaseMsg baseMsg) throws Exception{
@@ -66,7 +69,7 @@ public class SendSmartAppMsgServiceImpl implements MsgSendService {
wxMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(smartAppMsg.getAppId()); wxMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(smartAppMsg.getAppId());
} else { } else {
WxAppinfo appInfo = wxAppinfoService.getByAppId(smartAppMsg.getAppId()); WxAppinfo appInfo = wxAppinfoService.getByAppId(smartAppMsg.getAppId());
wxMaService = MaUtil.getWeappService(appInfo);
wxMaService = maUtil.getWeappService(appInfo);
} }


//查询信息模板 //查询信息模板


+ 4
- 1
mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/BaseWxPayAdapterService.java View File

@@ -232,13 +232,16 @@ public class BaseWxPayAdapterService {
@Autowired @Autowired
WxOpenService openService; WxOpenService openService;
@Autowired
MaUtil maUtil;
protected File getQrCode(WxAppinfo appinfo,String pageUrl,int type,String sceneParam) throws WxErrorException { protected File getQrCode(WxAppinfo appinfo,String pageUrl,int type,String sceneParam) throws WxErrorException {
boolean isFmOpen = false; boolean isFmOpen = false;
WxMaService wxMaService; WxMaService wxMaService;
if(isFmOpen) { if(isFmOpen) {
wxMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appinfo.getAppId()); wxMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appinfo.getAppId());
} else { } else {
wxMaService = MaUtil.getWeappService(appinfo);
wxMaService = maUtil.getWeappService(appinfo);
} }


boolean autoColor = false; boolean autoColor = false;


+ 77
- 10
mallinkService/src/main/java/com/iformall/utils/MaUtil.java View File

@@ -11,11 +11,27 @@ import com.iformall.domain.po.WxAppinfo;
import com.iformall.domain.po.WxPayAccount; import com.iformall.domain.po.WxPayAccount;
import com.iformall.douyin.miniapp.api.TtMaService; import com.iformall.douyin.miniapp.api.TtMaService;
import com.iformall.douyin.miniapp.api.impl.TtMaServiceImpl; import com.iformall.douyin.miniapp.api.impl.TtMaServiceImpl;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;



@Service
public class MaUtil { public class MaUtil {


static public WxMaService getWeappService(WxAppinfo appinfo) {
private static Map<String,TtMaService> serviceMap = new ConcurrentHashMap<String,TtMaService>();
private static Map<String,String> appServiceKeyMap = new ConcurrentHashMap<String,String>();
private static Map<String,WxPayService> payServiceMap = new ConcurrentHashMap<String,WxPayService>();
private static Map<String,WxMaService> wxMaServiceMap = new ConcurrentHashMap<String,WxMaService>();
private static Map<String,String> wxMaAppServiceKeyMap = new ConcurrentHashMap<String,String>();
public WxMaService getWeappService(WxAppinfo appinfo) {
WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl(); WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
config.setAppid(appinfo.getAppId()); config.setAppid(appinfo.getAppId());
config.setSecret(appinfo.getSecret()); config.setSecret(appinfo.getSecret());
@@ -27,12 +43,33 @@ public class MaUtil {
config.setExpiresTime(appinfo.getLastTokenTime().getTime()+appinfo.getExpiresIn()*1000); config.setExpiresTime(appinfo.getLastTokenTime().getTime()+appinfo.getExpiresIn()*1000);
} }
config.setApacheHttpClientBuilder(FmHttpClientBuilder.get()); config.setApacheHttpClientBuilder(FmHttpClientBuilder.get());
WxMaService service = new WxMaServiceImpl();
service.setWxMaConfig(config);
String key = appinfo.getAppId()+String.valueOf(config.getExpiresTime());
WxMaService service = wxMaServiceMap.get(key);
if ( null == service ) {
synchronized("getWxMaServcieBlock"+appinfo.getAppId()) {
service = wxMaServiceMap.get(key);
if (null == service) {
//删除掉之前的
String appServiceKey = wxMaAppServiceKeyMap.get(appinfo.getAppId());
if (!StringUtils.isBlank(appServiceKey)) {
if (wxMaServiceMap.containsKey(appServiceKey)) {
wxMaServiceMap.remove(appServiceKey);
}
wxMaAppServiceKeyMap.remove(appinfo.getAppId());
}
service = new WxMaServiceImpl();
service.setWxMaConfig(config);
wxMaServiceMap.put(key, service);
wxMaAppServiceKeyMap.put(appinfo.getAppId(),key);
}
}
}
return service; return service;
} }


static public WxPayService getWxPayService(WxAppinfo appinfo, WxPayAccount payAccount) {
public WxPayService getWxPayService(WxAppinfo appinfo, WxPayAccount payAccount) {
WxPayConfig config = new WxPayConfig(); WxPayConfig config = new WxPayConfig();
config.setAppId(appinfo.getAppId()); config.setAppId(appinfo.getAppId());
config.setMchId(payAccount.getMchId()); config.setMchId(payAccount.getMchId());
@@ -50,12 +87,21 @@ public class MaUtil {
config.setCertSerialNo(payAccount.getCertSerialNo());//证书序列号 config.setCertSerialNo(payAccount.getCertSerialNo());//证书序列号
config.setApiV3Key(payAccount.getApiV3Key());//apiV3秘钥 config.setApiV3Key(payAccount.getApiV3Key());//apiV3秘钥


WxPayService wxPayService = new WxPayServiceImpl();
wxPayService.setConfig(config);
return wxPayService;
WxPayService service = payServiceMap.get(appinfo.getAppId());
if ( null == service ) {
synchronized("getWxPayServiceBlock"+appinfo.getAppId()) {
service = payServiceMap.get(appinfo.getAppId());
if (null == service) {
service = new WxPayServiceImpl();
service.setConfig(config);
payServiceMap.put(appinfo.getAppId(), service);
}
}
}
return service;
} }


static public TtMaService getTtappService(WxAppinfo appinfo) {
public TtMaService getTtappService(WxAppinfo appinfo) {
WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl(); WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
config.setAppid(appinfo.getAppId()); config.setAppid(appinfo.getAppId());
config.setSecret(appinfo.getSecret()); config.setSecret(appinfo.getSecret());
@@ -67,8 +113,29 @@ public class MaUtil {
config.setExpiresTime(appinfo.getLastTokenTime().getTime()+appinfo.getExpiresIn()*1000); config.setExpiresTime(appinfo.getLastTokenTime().getTime()+appinfo.getExpiresIn()*1000);
} }
config.setApacheHttpClientBuilder(FmHttpClientBuilder.get()); config.setApacheHttpClientBuilder(FmHttpClientBuilder.get());
TtMaService service = new TtMaServiceImpl();
service.setWxMaConfig(config);
String key = appinfo.getAppId()+String.valueOf(config.getExpiresTime());
TtMaService service = serviceMap.get(key);
if ( null == service ) {
synchronized("getTtappServiceBlock"+appinfo.getAppId()) {
service = serviceMap.get(key);
if (null == service) {
//删除掉之前的
String appServiceKey = appServiceKeyMap.get(appinfo.getAppId());
if (!StringUtils.isBlank(appServiceKey)) {
if (serviceMap.containsKey(appServiceKey)) {
serviceMap.remove(appServiceKey);
}
appServiceKeyMap.remove(appinfo.getAppId());
}
service = new TtMaServiceImpl();
service.setWxMaConfig(config);
serviceMap.put(key, service);
appServiceKeyMap.put(appinfo.getAppId(),key);
}
}
}
return service; return service;
} }
} }

+ 4
- 1
mallinkTTAdmin/src/main/java/com/iformall/controller/base/BaseController.java View File

@@ -34,6 +34,9 @@ public class BaseController {


@Autowired @Autowired
private WxAppinfoService wxAppinfoService; private WxAppinfoService wxAppinfoService;
@Autowired
MaUtil maUtil;


@InitBinder @InitBinder
public void InitBinder(WebDataBinder dataBinder) { public void InitBinder(WebDataBinder dataBinder) {
@@ -73,7 +76,7 @@ public class BaseController {
// } // }


public TtMaService getWeappServiceByAppInfo(WxAppinfo appinfo) { public TtMaService getWeappServiceByAppInfo(WxAppinfo appinfo) {
TtMaService ttMaService = MaUtil.getTtappService(appinfo);
TtMaService ttMaService = maUtil.getTtappService(appinfo);
if (StringUtils.isBlank(appinfo.getAccessToken())) { if (StringUtils.isBlank(appinfo.getAccessToken())) {
// 如果没有accessToken,主动获取保存到数据库中,下次访问可以拿来使用 // 如果没有accessToken,主动获取保存到数据库中,下次访问可以拿来使用
updateAppAccessToken(appinfo, ttMaService); updateAppAccessToken(appinfo, ttMaService);


+ 4
- 1
mallinkTTCApi/src/main/java/com/iformall/controller/BaseController.java View File

@@ -53,6 +53,9 @@ public class BaseController {
@Qualifier("objectCommonRedisTemplate") @Qualifier("objectCommonRedisTemplate")
RedisTemplate<String, Object> objectCommonRedisTemplate; RedisTemplate<String, Object> objectCommonRedisTemplate;
@Autowired
MaUtil maUtil;
@InitBinder @InitBinder
public void InitBinder(WebDataBinder dataBinder) { public void InitBinder(WebDataBinder dataBinder) {
dataBinder.registerCustomEditor(Date.class, new PropertyEditorSupport() { dataBinder.registerCustomEditor(Date.class, new PropertyEditorSupport() {
@@ -109,7 +112,7 @@ public class BaseController {
} }


public TtMaService getWeappServiceByAppInfo(WxAppinfo appinfo) { public TtMaService getWeappServiceByAppInfo(WxAppinfo appinfo) {
TtMaService ttMaService = MaUtil.getTtappService(appinfo);
TtMaService ttMaService = maUtil.getTtappService(appinfo);
if (StringUtils.isBlank(appinfo.getAccessToken())) { if (StringUtils.isBlank(appinfo.getAccessToken())) {
// 如果没有accessToken,主动获取保存到数据库中,下次访问可以拿来使用 // 如果没有accessToken,主动获取保存到数据库中,下次访问可以拿来使用
updateAppAccessToken(appinfo, ttMaService); updateAppAccessToken(appinfo, ttMaService);


Loading…
Cancel
Save