| @@ -83,13 +83,13 @@ public class TtBUserServiceAdapter extends BasicCUserService implements CUserSer | |||
| @SneakyThrows | |||
| @Override | |||
| public WxMaJscode2SessionResult jsCode2SessionInfo(String code, WxAppinfo wxAppinfo, Boolean isFmOpen) { | |||
| TtMaService ttMaService = this.getTtMaService(wxAppinfo, isFmOpen); | |||
| TtMaService ttMaService = maUtil.getTtMaService(wxAppinfo); | |||
| return ttMaService.jsCode2SessionInfo(code); | |||
| } | |||
| @Override | |||
| public void decryptUserInfo(String encryptedData, String iv, CUser cuser, WxAppinfo wxAppinfo, Boolean isFmOpen) { | |||
| TtMaService ttMaService = this.getTtMaService(wxAppinfo, isFmOpen); | |||
| TtMaService ttMaService = maUtil.getTtMaService(wxAppinfo); | |||
| WxMaUserInfo userInfo = ttMaService.getUserService().getUserInfo(cuser.getSessionKey(), encryptedData, iv); | |||
| if (userInfo != null) { | |||
| logger.info("解密用户信息 {}" + userInfo.toString()); | |||
| @@ -114,7 +114,7 @@ public class TtBUserServiceAdapter extends BasicCUserService implements CUserSer | |||
| @Override | |||
| public String decryptPhoneNoInfo(String encryptedData, String iv, CUser cuser, WxAppinfo wxAppinfo, boolean isFmOpen) { | |||
| TtMaService ttMaService = this.getTtMaService(wxAppinfo, isFmOpen); | |||
| TtMaService ttMaService = maUtil.getTtMaService(wxAppinfo); | |||
| WxMaPhoneNumberInfo phoneNoInfo = ttMaService.getUserService().getPhoneNoInfo(cuser.getSessionKey(), encryptedData, iv); | |||
| if (null != phoneNoInfo) { | |||
| logger.info("解密用户手机号 {}" + phoneNoInfo.toString()); | |||
| @@ -270,42 +270,6 @@ public class TtBUserServiceAdapter extends BasicCUserService implements CUserSer | |||
| return null; | |||
| } | |||
| private TtMaService getTtMaService(WxAppinfo wxAppinfo, Boolean isFmOpen) { | |||
| TtMaService ttMaService = maUtil.getTtappService(wxAppinfo); | |||
| if (StringUtils.isBlank(wxAppinfo.getAccessToken())) { | |||
| // 如果没有accessToken,主动获取保存到数据库中,下次访问可以拿来使用 | |||
| updateAppAccessToken(wxAppinfo, ttMaService); | |||
| } else { | |||
| // 检查token是否已过期, 1小时就重新获取 | |||
| Date curDate = new Date(); | |||
| if (curDate.getTime() > wxAppinfo.getLastTokenTime().getTime() + Constant.H_EXPIRE) { | |||
| updateAppAccessToken(wxAppinfo, ttMaService); | |||
| } | |||
| } | |||
| return ttMaService; | |||
| } | |||
| private void updateAppAccessToken(WxAppinfo wxAppinfo, TtMaService ttMaService) { | |||
| try { | |||
| String accessToken = ttMaService.getAccessToken(true); | |||
| WxAppinfo updateApp = new WxAppinfo(); | |||
| updateApp.setId(wxAppinfo.getId()); | |||
| updateApp.setAccessToken(accessToken); | |||
| updateApp.setLastTokenTime(new Date()); | |||
| updateApp.setExpiresIn(7200); | |||
| wxAppinfo.setAccessToken(updateApp.getAccessToken()); | |||
| wxAppinfo.setLastTokenTime(updateApp.getLastTokenTime()); | |||
| wxAppinfo.setExpiresIn(updateApp.getExpiresIn()); | |||
| wxAppinfoService.saveOrUpdate(updateApp); | |||
| } catch (WxErrorException e) { | |||
| logger.error(e.getMessage()); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| } | |||
| private void updateTokenCache(String token,Object cuser) { | |||
| BaseCUserEntity baseUser = this.getByObj(cuser); | |||
| setCache(token,baseUser); | |||
| @@ -100,13 +100,13 @@ public class TtCUserServiceAdapter extends BasicCUserService implements CUserSer | |||
| @SneakyThrows | |||
| @Override | |||
| public WxMaJscode2SessionResult jsCode2SessionInfo(String code, WxAppinfo wxAppinfo, Boolean isFmOpen) { | |||
| TtMaService ttMaService = this.getTtMaService(wxAppinfo, isFmOpen); | |||
| TtMaService ttMaService = maUtil.getTtMaService(wxAppinfo); | |||
| return ttMaService.jsCode2SessionInfo(code); | |||
| } | |||
| @Override | |||
| public void decryptUserInfo(String encryptedData, String iv, CUser cuser, WxAppinfo wxAppinfo, Boolean isFmOpen) { | |||
| TtMaService ttMaService = this.getTtMaService(wxAppinfo, isFmOpen); | |||
| TtMaService ttMaService = maUtil.getTtMaService(wxAppinfo); | |||
| WxMaUserInfo userInfo = ttMaService.getUserService().getUserInfo(cuser.getSessionKey(), encryptedData, iv); | |||
| if (userInfo != null) { | |||
| TtCUser updateUser = new TtCUser(); | |||
| @@ -139,7 +139,7 @@ public class TtCUserServiceAdapter extends BasicCUserService implements CUserSer | |||
| @Override | |||
| public String decryptPhoneNoInfo(String encryptedData, String iv, CUser cuser, WxAppinfo wxAppinfo, boolean isFmOpen) { | |||
| TtMaService ttMaService = this.getTtMaService(wxAppinfo, isFmOpen); | |||
| TtMaService ttMaService = maUtil.getTtMaService(wxAppinfo); | |||
| WxMaPhoneNumberInfo phoneNoInfo = ttMaService.getUserService().getPhoneNoInfo(cuser.getSessionKey(), encryptedData, iv); | |||
| if (null != phoneNoInfo) { | |||
| if(phoneNoInfo.getPhoneNumber().contains("*")){ | |||
| @@ -358,41 +358,6 @@ public class TtCUserServiceAdapter extends BasicCUserService implements CUserSer | |||
| return ttCUserMapper.findCountData(dto); | |||
| } | |||
| private TtMaService getTtMaService(WxAppinfo wxAppinfo, Boolean isFmOpen) { | |||
| TtMaService ttMaService = maUtil.getTtappService(wxAppinfo); | |||
| if (StringUtils.isBlank(wxAppinfo.getAccessToken())) { | |||
| // 如果没有accessToken,主动获取保存到数据库中,下次访问可以拿来使用 | |||
| updateAppAccessToken(wxAppinfo, ttMaService); | |||
| } else { | |||
| // 检查token是否已过期, 1小时就重新获取 | |||
| Date curDate = new Date(); | |||
| if (curDate.getTime() > wxAppinfo.getLastTokenTime().getTime() + Constant.H_EXPIRE) { | |||
| updateAppAccessToken(wxAppinfo, ttMaService); | |||
| } | |||
| } | |||
| return ttMaService; | |||
| } | |||
| private void updateAppAccessToken(WxAppinfo wxAppinfo, TtMaService ttMaService) { | |||
| try { | |||
| String accessToken = ttMaService.getAccessToken(true); | |||
| WxAppinfo updateApp = new WxAppinfo(); | |||
| updateApp.setId(wxAppinfo.getId()); | |||
| updateApp.setAccessToken(accessToken); | |||
| updateApp.setLastTokenTime(new Date()); | |||
| updateApp.setExpiresIn(7200); | |||
| wxAppinfo.setAccessToken(updateApp.getAccessToken()); | |||
| wxAppinfo.setLastTokenTime(updateApp.getLastTokenTime()); | |||
| wxAppinfo.setExpiresIn(updateApp.getExpiresIn()); | |||
| wxAppinfoService.saveOrUpdate(updateApp); | |||
| } catch (WxErrorException e) { | |||
| logger.error(e.getMessage()); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| } | |||
| private void delForUserIdOnly(Long id, Long userId, String tenantId) { | |||
| List<String> tokenList = ttCUserMapper.findTokenList(id,userId, tenantId); | |||
| @@ -91,11 +91,13 @@ public class FmInsideOrderPushMsgServiceImpl implements MsgSendService { | |||
| StringBuilder sb = new StringBuilder(); | |||
| sb.append(DateUtils.date2String(new Date())); | |||
| sb.append("\n"); | |||
| sb.append("tenantId="+batchOrder.getTenantId()); | |||
| sb.append("\n"); | |||
| sb.append(e.getMessage()); | |||
| sb.append("\n"); | |||
| sb.append("batchOrderId="+batchOrder.getId()); | |||
| //发送邮件 | |||
| mailService.sendSimpleMail(receivers, "订单同步异常", sb.toString()); | |||
| mailService.sendSimpleMail(receivers, batchOrder.getTenantId()+"订单同步异常", sb.toString()); | |||
| TtOrderPushError pushError = new TtOrderPushError(); | |||
| pushError.setId(batchOrder.getId()); | |||
| @@ -79,7 +79,7 @@ public class SendSmartAppMsgServiceImpl implements MsgSendService { | |||
| WxAppinfo appInfo = wxAppinfoService.getByAppId(smartAppMsg.getAppId()); | |||
| if(EnumTemplateType.TT_SEND_COUPON_REMIND.getCode().equals(msg.getType())){ | |||
| //发抖音 | |||
| TtMaService ttappService = maUtil.getTtappService(appInfo); | |||
| TtMaService ttappService = maUtil.getTtMaService(appInfo); | |||
| TtMaSubscribeMessage subscribeMessage; | |||
| String[] split = smartAppMsg.getTo().split(","); | |||
| for (String to:split) { | |||
| @@ -50,7 +50,7 @@ public class BaseTtPayAdapterService { | |||
| protected MaUtil maUtil; | |||
| protected File getQrCode(WxAppinfo appinfo,String pageUrl,int type,String sceneParam) throws WxErrorException { | |||
| TtMaService ttappService = maUtil.getTtappService(appinfo); | |||
| TtMaService ttappService = maUtil.getTtMaService(appinfo); | |||
| String pathStr = ""; | |||
| if (StringUtils.isNotBlank(sceneParam)) { | |||
| pathStr = pageUrl + "?scene="+sceneParam; | |||
| @@ -93,7 +93,7 @@ public class TtMiniAppPayAdapterService extends BaseTtPayAdapterService implemen | |||
| @Override | |||
| public PayAdapterResult payOrderPush(String openId,WxAppinfo appInfo, WxBatchOrder batchOrder,WxPayOrder payOrder) throws Exception { | |||
| TtMaService ttappService = maUtil.getTtappService(appInfo); | |||
| TtMaService ttappService = maUtil.getTtMaService(appInfo); | |||
| Map<String,Object> map = new HashMap<>(); | |||
| // map.put("client_key","");//第三方在开放平台申请的 ClientKey(生活服务订单必传) | |||
| // map.put("access_token",appInfo.getAccessToken()); | |||
| @@ -12,6 +12,7 @@ import com.iformall.domain.po.WxPayAccount; | |||
| import com.iformall.douyin.miniapp.api.TtMaService; | |||
| import com.iformall.douyin.miniapp.api.impl.TtMaServiceImpl; | |||
| import java.util.Date; | |||
| import java.util.Map; | |||
| import java.util.concurrent.ConcurrentHashMap; | |||
| @@ -19,13 +20,23 @@ import com.iformall.douyin.web.api.TtWebService; | |||
| import com.iformall.douyin.web.api.impl.TtWebServiceImpl; | |||
| import com.iformall.douyin.web.config.TtWebDefaultConfigImpl; | |||
| import com.iformall.douyin.web.enums.TtWebApiBeginEnum; | |||
| import com.iformall.service.WxAppinfoService; | |||
| import lombok.extern.flogger.Flogger; | |||
| import me.chanjar.weixin.common.error.WxErrorException; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| @Service | |||
| public class MaUtil { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| private WxAppinfoService wxAppinfoService; | |||
| private static Map<String,TtMaService> serviceMap = new ConcurrentHashMap<String,TtMaService>(); | |||
| private static Map<String,String> appServiceKeyMap = new ConcurrentHashMap<String,String>(); | |||
| @@ -108,7 +119,7 @@ public class MaUtil { | |||
| return service; | |||
| } | |||
| public TtMaService getTtappService(WxAppinfo appinfo) { | |||
| private TtMaService getTtappService(WxAppinfo appinfo) { | |||
| WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl(); | |||
| config.setAppid(appinfo.getAppId()); | |||
| config.setSecret(appinfo.getSecret()); | |||
| @@ -146,6 +157,42 @@ public class MaUtil { | |||
| return service; | |||
| } | |||
| public TtMaService getTtMaService(WxAppinfo wxAppinfo) { | |||
| TtMaService ttMaService = getTtappService(wxAppinfo); | |||
| if (StringUtils.isBlank(wxAppinfo.getAccessToken())) { | |||
| // 如果没有accessToken,主动获取保存到数据库中,下次访问可以拿来使用 | |||
| updateAppAccessToken(wxAppinfo, ttMaService); | |||
| } else { | |||
| // 检查token是否已过期, 1小时就重新获取 | |||
| Date curDate = new Date(); | |||
| if (curDate.getTime() > wxAppinfo.getLastTokenTime().getTime() + Constant.H_EXPIRE) { | |||
| updateAppAccessToken(wxAppinfo, ttMaService); | |||
| } | |||
| } | |||
| return ttMaService; | |||
| } | |||
| private void updateAppAccessToken(WxAppinfo wxAppinfo, TtMaService ttMaService) { | |||
| try { | |||
| String accessToken = ttMaService.getAccessToken(true); | |||
| WxAppinfo updateApp = new WxAppinfo(); | |||
| updateApp.setId(wxAppinfo.getId()); | |||
| updateApp.setAccessToken(accessToken); | |||
| updateApp.setLastTokenTime(new Date()); | |||
| updateApp.setExpiresIn(7200); | |||
| wxAppinfo.setAccessToken(updateApp.getAccessToken()); | |||
| wxAppinfo.setLastTokenTime(updateApp.getLastTokenTime()); | |||
| wxAppinfo.setExpiresIn(updateApp.getExpiresIn()); | |||
| wxAppinfoService.saveOrUpdate(updateApp); | |||
| } catch (WxErrorException e) { | |||
| logger.error(e.getMessage()); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| } | |||
| public TtWebService getTtWebService(WxAppinfo appinfo) { | |||
| TtWebDefaultConfigImpl config = new TtWebDefaultConfigImpl(); | |||
| config.setAppid(appinfo.getAppId()); | |||
| @@ -75,21 +75,6 @@ public class BaseController { | |||
| // return tenantId; | |||
| // } | |||
| public TtMaService getWeappServiceByAppInfo(WxAppinfo appinfo) { | |||
| TtMaService ttMaService = maUtil.getTtappService(appinfo); | |||
| if (StringUtils.isBlank(appinfo.getAccessToken())) { | |||
| // 如果没有accessToken,主动获取保存到数据库中,下次访问可以拿来使用 | |||
| updateAppAccessToken(appinfo, ttMaService); | |||
| } else { | |||
| // 检查token是否已过期, 1小时就重新获取 | |||
| Date curDate = new Date(); | |||
| if (curDate.getTime() > appinfo.getLastTokenTime().getTime() + Constant.H_EXPIRE) { | |||
| updateAppAccessToken(appinfo, ttMaService); | |||
| } | |||
| } | |||
| return ttMaService; | |||
| } | |||
| /** | |||
| * 返回租户信息 | |||
| @@ -153,32 +138,6 @@ public class BaseController { | |||
| throw new MallinkException(ErrorCode.USER_NO_PERMISSION); | |||
| } | |||
| /** | |||
| * WxAppInfo更新accessToken | |||
| * | |||
| * @param wxAppinfo | |||
| * @param TtMaService | |||
| */ | |||
| private void updateAppAccessToken(WxAppinfo wxAppinfo, TtMaService TtMaService) { | |||
| try { | |||
| String accessToken = TtMaService.getAccessToken(true); | |||
| WxAppinfo updateApp = new WxAppinfo(); | |||
| updateApp.setId(wxAppinfo.getId()); | |||
| updateApp.setAccessToken(accessToken); | |||
| updateApp.setLastTokenTime(new Date()); | |||
| updateApp.setExpiresIn(7200); | |||
| wxAppinfo.setAccessToken(updateApp.getAccessToken()); | |||
| wxAppinfo.setLastTokenTime(updateApp.getLastTokenTime()); | |||
| wxAppinfo.setExpiresIn(updateApp.getExpiresIn()); | |||
| wxAppinfoService.saveOrUpdate(updateApp); | |||
| } catch (WxErrorException e) { | |||
| e.printStackTrace(); | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| public String getIpAddr() { | |||
| HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); | |||
| String ipaddress = IPUtil.getIpAddr(request); | |||
| @@ -111,47 +111,6 @@ public class BaseController { | |||
| return tenantEntity; | |||
| } | |||
| public TtMaService getWeappServiceByAppInfo(WxAppinfo appinfo) { | |||
| TtMaService ttMaService = maUtil.getTtappService(appinfo); | |||
| if (StringUtils.isBlank(appinfo.getAccessToken())) { | |||
| // 如果没有accessToken,主动获取保存到数据库中,下次访问可以拿来使用 | |||
| updateAppAccessToken(appinfo, ttMaService); | |||
| } else { | |||
| // 检查token是否已过期, 1小时就重新获取 | |||
| Date curDate = new Date(); | |||
| if (curDate.getTime() > appinfo.getLastTokenTime().getTime() + Constant.H_EXPIRE) { | |||
| updateAppAccessToken(appinfo, ttMaService); | |||
| } | |||
| } | |||
| return ttMaService; | |||
| } | |||
| /** | |||
| * WxAppInfo更新accessToken | |||
| * | |||
| * @param wxAppinfo | |||
| * @param TtMaService | |||
| */ | |||
| private void updateAppAccessToken(WxAppinfo wxAppinfo, TtMaService TtMaService) { | |||
| try { | |||
| String accessToken = TtMaService.getAccessToken(true); | |||
| WxAppinfo updateApp = new WxAppinfo(); | |||
| updateApp.setId(wxAppinfo.getId()); | |||
| updateApp.setAccessToken(accessToken); | |||
| updateApp.setLastTokenTime(new Date()); | |||
| updateApp.setExpiresIn(7200); | |||
| wxAppinfo.setAccessToken(updateApp.getAccessToken()); | |||
| wxAppinfo.setLastTokenTime(updateApp.getLastTokenTime()); | |||
| wxAppinfo.setExpiresIn(updateApp.getExpiresIn()); | |||
| wxAppinfoService.saveOrUpdate(updateApp); | |||
| } catch (WxErrorException e) { | |||
| logger.error(e.getMessage()); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| } | |||
| /** | |||
| * 微信端获取当前用户 wx_c_user,非会员 | |||
| @@ -96,7 +96,7 @@ public class TtUserGrantController extends BaseController { | |||
| RedisCacheUtils.removeCache(objectCommonRedisTemplate, key); | |||
| } | |||
| TtMaService ttMaService = getWeappServiceByAppInfo(wxAppinfo); | |||
| TtMaService ttMaService = maUtil.getTtMaService(wxAppinfo); | |||
| String token = null; | |||
| String session_key = null; | |||
| @@ -264,7 +264,7 @@ public class TtUserGrantController extends BaseController { | |||
| if (user != null) { | |||
| logger.debug(user.toString()); | |||
| WxAppinfo wxAppinfo = wxAppinfoService.getByAppId(user.getAppId()); | |||
| TtMaService ttMaService = getWeappServiceByAppInfo(wxAppinfo); | |||
| TtMaService ttMaService = maUtil.getTtMaService(wxAppinfo); | |||
| String session_key = user.getSessionKey(); | |||
| try { | |||
| @@ -351,7 +351,7 @@ public class TtUserGrantController extends BaseController { | |||
| } | |||
| WxAppinfo wxAppinfo = wxAppinfoService.getByAppId(user.getAppId()); | |||
| TtMaService ttMaService = getWeappServiceByAppInfo(wxAppinfo); | |||
| TtMaService ttMaService = maUtil.getTtMaService(wxAppinfo); | |||
| String session_key = user.getSessionKey(); | |||
| try { | |||