@ -4,12 +4,15 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject ;
import com.alibaba.nacos.client.config.utils.IOUtils ;
import com.dingtalk.api.request.OapiRobotSendRequest ;
import com.epmet.apiservice.ApiService ;
import com.epmet.commons.tools.constant.NumConstant ;
import com.epmet.commons.tools.exception.ExceptionUtils ;
import com.epmet.commons.tools.exception.RenException ;
import com.epmet.commons.tools.security.dto.TokenDto ;
import com.epmet.commons.tools.utils.ConvertUtils ;
import com.epmet.commons.tools.utils.HttpClientManager ;
import com.epmet.constant.ModuleConstant ;
import com.epmet.constant.ThirdPlatformActions ;
import com.epmet.constant.ThirdRedisKeyConstant ;
import com.epmet.constant.ThirdRunTimeInfoConstant ;
import com.epmet.dao.* ;
@ -21,7 +24,9 @@ import com.epmet.feign.OperCrmOpenFeignClient;
import com.epmet.mpaes.WXBizMsgCrypt ;
import com.epmet.mpaes.WXXmlToMapUtil ;
import com.epmet.redis.RedisThird ;
import com.epmet.service.ApiServiceSelector ;
import com.epmet.service.ComponentVerifyTicketService ;
import com.epmet.service.ThirdPlatformService ;
import com.epmet.wxapi.constant.WxMaCodeConstant ;
import lombok.extern.slf4j.Slf4j ;
import org.apache.commons.lang3.StringUtils ;
@ -47,7 +52,7 @@ import static com.epmet.constant.ThirdRunTimeInfoConstant.*;
* /
@Slf4j
@Service
public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketService {
public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketService , ApiServiceSelector {
@Autowired
private RedisThird redisThird ;
@ -94,6 +99,9 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
@Autowired
private PaCustomerDao paCustomerDao ;
@Autowired
private ThirdPlatformService thirdPlatformService ;
@Value ( "${third.platform.appId}" )
private String componentAppId ;
@Value ( "${third.platform.appSecret}" )
@ -104,8 +112,8 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
private String token ;
/ * *
* @Description 获得授权事件的票据
* @param
* @Description 获得授权事件的票据
* @author zxc
* /
@Transactional ( rollbackFor = Exception . class )
@ -123,23 +131,23 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
String nonce = request . getParameter ( ModuleConstant . NONCE ) ;
String encryptType = request . getParameter ( ModuleConstant . ENCRYPT_TYPE ) ;
String signature = request . getParameter ( ModuleConstant . SIGNATURE ) ;
log . info ( String . format ( ThirdRunTimeInfoConstant . VERIFY_TICKET , msgSignature , timeStamp , nonce , encryptType , signature ) ) ;
log . info ( String . format ( ThirdRunTimeInfoConstant . VERIFY_TICKET , msgSignature , timeStamp , nonce , encryptType , signature ) ) ;
// 从请求中读取整个post数据
InputStream inputStream ;
String postData = null ;
inputStream = request . getInputStream ( ) ;
postData = IOUtils . toString ( inputStream , ModuleConstant . UTF8 ) ;
WXBizMsgCrypt wxBizMsgCrypt = new WXBizMsgCrypt ( token , aesKey , componentAppId ) ;
postData = IOUtils . toString ( inputStream , ModuleConstant . UTF8 ) ;
WXBizMsgCrypt wxBizMsgCrypt = new WXBizMsgCrypt ( token , aesKey , componentAppId ) ;
String msg = wxBizMsgCrypt . decryptMsg ( msgSignature , timeStamp , nonce , postData ) ;
log . info ( String . format ( ThirdRunTimeInfoConstant . MSG , msg ) ) ;
log . info ( String . format ( ThirdRunTimeInfoConstant . MSG , msg ) ) ;
// 将xml转为map
Map < String , String > result = WXXmlToMapUtil . xmlToMap ( msg ) ;
String infotype = result . get ( ModuleConstant . INFO_TYPE ) ;
log . info ( String . format ( ThirdRunTimeInfoConstant . INFO_TYPE , infotype ) ) ;
switch ( infotype ) {
log . info ( String . format ( ThirdRunTimeInfoConstant . INFO_TYPE , infotype ) ) ;
switch ( infotype ) {
case ModuleConstant . TICKET_UNDERLINE_KEY : //接收票据 【component_verify_ticket】
String ComponentVerifyTicket = result . get ( ModuleConstant . TICKET_KEY ) ;
log . info ( String . format ( COMPONENT_VERIFY_TICKET , ComponentVerifyTicket ) ) ;
log . info ( String . format ( COMPONENT_VERIFY_TICKET , ComponentVerifyTicket ) ) ;
// 缓存 ticket
redisThird . setComponentVerifyTicket ( ComponentVerifyTicket ) ;
// 存数据库
@ -149,7 +157,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
//先逻辑删
ticketDao . deleteOldComponentVerifyTicket ( ) ;
ticketDao . insertComponentVerifyTicket ( ticketFormDTO ) ;
log . info ( ModuleConstant . TICKET_UNDERLINE_KEY + ":" + ComponentVerifyTicket ) ;
log . info ( ModuleConstant . TICKET_UNDERLINE_KEY + ":" + ComponentVerifyTicket ) ;
break ;
case ModuleConstant . AUTHORIZED : //授权成功
this . disposeAuthResult ( result ) ;
@ -173,7 +181,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
}
log . info ( ThirdRunTimeInfoConstant . END_TICKET ) ;
Integer tokenCount = componentAccessTokenDao . selectAccessTokenCount ( ) ;
if ( tokenCount = = NumConstant . ZERO ) {
if ( tokenCount = = NumConstant . ZERO ) {
String accessTokenCountFlag = ModuleConstant . ACCOUNT_TOKEN_FLAG_ONE ;
this . getComponentAccessToken ( accessTokenCountFlag ) ;
}
@ -181,14 +189,14 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
}
/ * *
* @Description 授权结果插入
* @param result
* @Description 授权结果插入
* @author zxc
* /
@Transactional ( rollbackFor = Exception . class )
public void disposeAuthResult ( Map < String , String > result ) {
public void disposeAuthResult ( Map < String , String > result ) {
Map tempMap = result ;
Map < String , Object > data = tempMap ;
Map < String , Object > data = tempMap ;
AuthResultRecordFormDTO authResultRecord = ConvertUtils . mapToEntity ( data , AuthResultRecordFormDTO . class ) ;
authResultRecord . setWechatCreateTime ( this . sToDate ( result . get ( ModuleConstant . CREATE_TIME ) ) ) ;
if ( result . containsKey ( ModuleConstant . AUTHORIZATION_CODE_EXPIRED_TIME ) ) {
@ -199,9 +207,9 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
}
/ * *
* @Description 定时获取 ( 令牌 , component_access_token ) 第三方与微信交互使用的component_access_token
* 每十分钟执行一次 , 判断是否有马上超时的 ( 15分钟以内算马上超时 )
* @param accessTokenCountFlag 表里的 component_access_token的数量
* @Description 定时获取 ( 令牌 , component_access_token ) 第三方与微信交互使用的component_access_token
* 每十分钟执行一次 , 判断是否有马上超时的 ( 15分钟以内算马上超时 )
* @author zxc
* /
@Transactional ( rollbackFor = Exception . class )
@ -218,7 +226,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
jsonObject . put ( ModuleConstant . COMPONENT_APPID , componentAppId ) ;
jsonObject . put ( ModuleConstant . COMPONENT_APPSECRET , appSecret ) ;
jsonObject . put ( ModuleConstant . TICKET_UNDERLINE_KEY , componentVerifyTicket ) ;
log . info ( String . format ( ThirdRunTimeInfoConstant . COMPONENT_ACCESS_TOKEN , componentVerifyTicket ) ) ;
log . info ( String . format ( ThirdRunTimeInfoConstant . COMPONENT_ACCESS_TOKEN , componentVerifyTicket ) ) ;
String post = HttpClientManager . getInstance ( ) . sendPostByJSON ( WxMaCodeConstant . API_COMPONENT_TOKEN_URL , JSON . toJSONString ( jsonObject ) ) . getData ( ) ;
Map hashMap = JSON . parseObject ( post , Map . class ) ;
if ( ! hashMap . containsKey ( ModuleConstant . ERR_MSG ) ) {
@ -236,6 +244,13 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
componentAccessTokenDao . insertComponentAccessToken ( formDTO ) ;
//存缓存
redisThird . setComponentAccessToken ( componentAccessToken ) ;
//推送到私有化平台们
try {
pushComponentAccessToken2PrivateEpmetPlatforms ( formDTO ) ;
} catch ( Exception e ) {
String detail = ExceptionUtils . getErrorStackTrace ( e ) ;
log . error ( detail ) ;
}
} else {
throw new RenException ( ThirdRunTimeInfoConstant . FAILURE_ACCESS_TOKEN ) ;
}
@ -245,8 +260,29 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
}
/ * *
* @Description 获取预授权码
* @param input
* @return void
* @Description 推送component access token到私有化平台
* @author wxz
* @date 2021 . 08 . 30 17 : 12 : 15
* /
public void pushComponentAccessToken2PrivateEpmetPlatforms ( ComponentAccessTokenFormDTO input ) {
List < ThirdPlatformActionsResultDTO > platforms = thirdPlatformService . listPlatformsByActionKey ( ThirdPlatformActions . PUSH_COMPONENT_ACCESS_TOKEN ) ;
platforms . stream ( ) . forEach ( p - > {
log . info ( "推送component-access-token到私有化平台:platformId:{}, platformKey:{}, platformName:{}, apiUrl:{}" , p . getPlatformId ( ) , p . getPlatformKey ( ) , p . getPlatformName ( ) , p . getApiUrl ( ) ) ;
ApiService apiService = selectApiService ( p . getPlatformId ( ) ) ;
try {
apiService . pushComponentAccessToken ( input , p . getPlatformId ( ) , p . getPlatformKey ( ) ) ;
} catch ( Exception e ) {
String detail = ExceptionUtils . getErrorStackTrace ( e ) ;
log . error ( detail ) ;
}
} ) ;
}
/ * *
* @param
* @Description 获取预授权码
* @author zxc
* /
@Transactional ( rollbackFor = Exception . class )
@ -258,7 +294,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
JSONObject jsonObject = new JSONObject ( ) ;
jsonObject . put ( ModuleConstant . COMPONENT_APPID , componentAppId ) ;
String post = HttpClientManager . getInstance ( ) . sendPostByJSON ( WxMaCodeConstant . API_CREATE_PREAUTHCODE_URL + accessToken , JSON . toJSONString ( jsonObject ) ) . getData ( ) ;
log . info ( String . format ( POST_RESULT , post ) ) ;
log . info ( String . format ( POST_RESULT , post ) ) ;
Map hashMap = JSON . parseObject ( post , Map . class ) ;
if ( ! hashMap . containsKey ( ModuleConstant . ERR_MSG ) ) {
preAuthCode = hashMap . get ( ModuleConstant . PRE_AUTH_CODE ) . toString ( ) ;
@ -283,11 +319,11 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
}
/ * *
* @Description 使用授权码获取授权信息 请求参数 : 【 component_access_token 、 component_appid 、 authorization_code 】
* @Description 使用授权码获取授权信息 请求参数 : 【 component_access_token 、 component_appid 、 authorization_code 】
* @author zxc
* /
@Transactional ( rollbackFor = Exception . class )
public AuthorizationInfoResultDTO authInfoByAuthCode ( String authCode , String customerId , String clientType ) {
public AuthorizationInfoResultDTO authInfoByAuthCode ( String authCode , String customerId , String clientType ) {
log . info ( START_GET_AUTH_INFO ) ;
AuthorizationInfoResultDTO authorizationInfoResultDTO = new AuthorizationInfoResultDTO ( ) ;
// 获取令牌【component_access_token】
@ -297,11 +333,11 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
jsonObject . put ( ModuleConstant . COMPONENT_APPID , componentAppId ) ;
jsonObject . put ( ModuleConstant . AUTHORIZATION_CODE , authCode ) ;
String authInfo = HttpClientManager . getInstance ( ) . sendPostByJSON ( WxMaCodeConstant . API_QUERY_AUTH_URL + accessToken , JSON . toJSONString ( jsonObject ) ) . getData ( ) ;
HashMap < String , Map > hashMap = JSON . parseObject ( authInfo , HashMap . class ) ;
HashMap < String , Map > hashMap = JSON . parseObject ( authInfo , HashMap . class ) ;
Map map = hashMap . get ( ModuleConstant . AUTHORIZATION_INFO ) ;
authorizationInfoResultDTO = ConvertUtils . mapToEntity ( map , AuthorizationInfoResultDTO . class ) ;
String authAppId = authorizationInfoResultDTO . getAuthorizer_appid ( ) ;
log . info ( "授权信息:" + map ) ;
log . info ( "授权信息:" + map ) ;
String expiresIn = authorizationInfoResultDTO . getExpires_in ( ) . toString ( ) ;
Date expiresInTime = this . countExpirationTime ( expiresIn ) ;
//授权信息分为两张表,基础信息authorization_info,授权列表func_info
@ -314,14 +350,14 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
authInfoDTO . setCustomerId ( customerId ) ;
authInfoDTO . setClientType ( clientType ) ;
List < Map > func_info = authorizationInfoResultDTO . getFunc_info ( ) ;
log . info ( "权限列表信息:" + func_info ) ;
log . info ( "权限列表信息:" + func_info ) ;
String funcInfo = JSON . toJSONString ( func_info ) ;
authInfoDTO . setFuncInfo ( funcInfo ) ;
//先逻辑删除,在插入
authorizationInfoDao . updateOldAuthorizationInfo ( authAppId ) ;
authorizationInfoDao . insertAuthorizationInfo ( authInfoDTO ) ;
// 授权信息放入缓存
redisThird . setAuthInfo ( authorizationInfoResultDTO , customerId , clientType ) ;
redisThird . setAuthInfo ( authorizationInfoResultDTO , customerId , clientType ) ;
//authorizer_refresh_token 放入缓存
redisThird . setAuthorizerRefreshToken ( authInfoDTO ) ;
log . info ( END_GET_AUTH_INFO ) ;
@ -329,8 +365,8 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
}
/ * *
* @Description 获取 / 刷新接口调用令牌
* @param
* @Description 获取 / 刷新接口调用令牌
* @author zxc
* /
@Transactional ( rollbackFor = Exception . class )
@ -338,7 +374,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
public void refreshToken ( ) {
//查询 即将过期的 authorizer_access_token
List < WillOverDueResultDTO > willOverDueResultDTOS = authorizationInfoDao . checkWillOverDue ( ) ;
if ( willOverDueResultDTOS . size ( ) ! = NumConstant . ZERO & & null ! = willOverDueResultDTOS ) {
if ( willOverDueResultDTOS . size ( ) ! = NumConstant . ZERO & & null ! = willOverDueResultDTOS ) {
log . info ( "查询到即将过期的authorizer_access_token" ) ;
willOverDueResultDTOS . forEach ( willOverDueDTO - > {
String authAppId = willOverDueDTO . getAuthAppId ( ) ;
@ -346,10 +382,10 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
String clientType = willOverDueDTO . getClientType ( ) ;
JSONObject jsonObject = new JSONObject ( ) ;
//授权方AppId
jsonObject . put ( ModuleConstant . AUTHORIZER_APPID , authAppId ) ;
jsonObject . put ( ModuleConstant . AUTHORIZER_APPID , authAppId ) ;
//第三方平台AppId
jsonObject . put ( ModuleConstant . COMPONENT_APPID , componentAppId ) ;
jsonObject . put ( ModuleConstant . AUTHORIZER_REFRESH_TOKEN , willOverDueDTO . getAuthorizerRefreshToken ( ) ) ;
jsonObject . put ( ModuleConstant . COMPONENT_APPID , componentAppId ) ;
jsonObject . put ( ModuleConstant . AUTHORIZER_REFRESH_TOKEN , willOverDueDTO . getAuthorizerRefreshToken ( ) ) ;
String componentAccessToken = redisThird . getComponentAccessToken ( ) ;
String data = HttpClientManager . getInstance ( ) . sendPostByJSON ( WxMaCodeConstant . API_AUTHORIZER_TOKEN_URL + componentAccessToken , JSON . toJSONString ( jsonObject ) ) . getData ( ) ;
Map map = JSON . parseObject ( data , HashMap . class ) ;
@ -368,7 +404,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
formDTO . setAuthAppid ( authAppId ) ;
formDTO . setClientType ( clientType ) ;
AuthorizationInfoFormDTO authorizationInfo = new AuthorizationInfoFormDTO ( ) ;
BeanUtils . copyProperties ( formDTO , authorizationInfo ) ;
BeanUtils . copyProperties ( formDTO , authorizationInfo ) ;
authorizationInfo . setAuthorizerAppid ( authAppId ) ;
//先逻辑删除,在插入
authorizationInfoDao . deleteOldAuthorizerAccessToken ( customerId , clientType ) ;
@ -380,7 +416,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
resultDTO . setAuthorizer_refresh_token ( authorizerRefreshToken ) ;
resultDTO . setAuthorizer_appid ( authAppId ) ;
resultDTO . setExpires_in ( 7200 ) ;
redisThird . setAuthInfo ( resultDTO , customerId , clientType ) ;
redisThird . setAuthInfo ( resultDTO , customerId , clientType ) ;
}
} ) ;
log . info ( "更新authorizer_access_token成功" ) ;
@ -389,13 +425,13 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
}
/ * *
* @Description 授权回调URL , 回调时并获取授权信息
* @param
* @Description 授权回调URL , 回调时并获取授权信息
* @author zxc
* /
@Transactional ( rollbackFor = Exception . class )
@Override
public void redirectUri ( TokenDto tokenDto , @RequestBody AuthCodeAndTimeFromDTO authCodeAndTime ) {
public void redirectUri ( TokenDto tokenDto , @RequestBody AuthCodeAndTimeFromDTO authCodeAndTime ) {
log . info ( "开始执行回调URL" ) ;
String authCode = authCodeAndTime . getAuthCode ( ) ;
String clientType = authCodeAndTime . getClientType ( ) ;
@ -413,7 +449,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
formDTO . setClientType ( clientType ) ;
formDTO . setCustomerId ( customerId ) ;
log . info ( ThirdRunTimeInfoConstant . BEGIN_DELETE_INSERT_AUTH_CODE ) ;
authCodeDao . deleteCustomerAuthCode ( customerId , clientType ) ;
authCodeDao . deleteCustomerAuthCode ( customerId , clientType ) ;
authCodeDao . insertRedirectAuthCode ( formDTO ) ;
//authCode存缓存
redisThird . setAuthCode ( formDTO ) ;
@ -423,12 +459,12 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
List < FixationAppIdResultDTO > fixationAppIdResultDTOS = fixationAppIdDao . selectFixationInfos ( ) ;
String finalCustomerId = customerId ; //
fixationAppIdResultDTOS . forEach ( fixationAppId - > {
if ( fixationAppId . getAppId ( ) . equals ( authAppId ) ) {
if ( fixationAppId . getAppId ( ) . equals ( authAppId ) ) {
// TODO 是城阳项目或者党群e事通
// crm表中的customerId【原customerId】
String masterCustomerId = fixationAppId . getMasterCustomerId ( ) ;
formDTO . setCustomerId ( masterCustomerId ) ;
authCodeDao . deleteCustomerAuthCode ( finalCustomerId , clientType ) ;
authCodeDao . deleteCustomerAuthCode ( finalCustomerId , clientType ) ;
authCodeDao . insertRedirectAuthCode ( formDTO ) ;
//authCode存缓存
redisThird . setAuthCode ( formDTO ) ;
@ -447,37 +483,37 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
//替换 新customerId为旧customerId
customerId = formDTO . getCustomerId ( ) ;
// 2. 创建开放平台账号并绑定 或者 直接绑定开放平台
this . createAndBindOpenAccount ( customerId , authAppId , clientType ) ;
this . createAndBindOpenAccount ( customerId , authAppId , clientType ) ;
// 3. 更新 customer_mp 表授权状态和AuthAppId
this . updateCustomerMpAppId ( customerId , authAppId , clientType ) ;
authCodeDao . updateAppId ( customerId , clientType , authAppId ) ;
this . updateCustomerMpAppId ( customerId , authAppId , clientType ) ;
authCodeDao . updateAppId ( customerId , clientType , authAppId ) ;
// 4. 保存授权方账户信息
this . saveAuthAccountInfo ( customerId , authAppId , clientType ) ;
this . saveAuthAccountInfo ( customerId , authAppId , clientType ) ;
// 5. 校验客户居民端、工作端小程序是否全部授权,全部授权完成的推送钉钉消息 sun
this . checkAuthorization ( customerId ) ;
log . info ( "回调结束" ) ;
}
/ * *
* @Description 获取授权方的帐号基本信息并保存
* @param customerId
* @param authAppId
* @Description 获取授权方的帐号基本信息并保存
* @author zxc
* /
@Transactional ( rollbackFor = Exception . class )
public void saveAuthAccountInfo ( String customerId , String authAppId , String clientType ) {
public void saveAuthAccountInfo ( String customerId , String authAppId , String clientType ) {
log . info ( "开始执行保存授权账户基本信息" ) ;
JSONObject jsonObject = new JSONObject ( ) ;
jsonObject . put ( ModuleConstant . COMPONENT_APP_ID , componentAppId ) ;
jsonObject . put ( ModuleConstant . AUTHORIZER_APP_ID , authAppId ) ;
jsonObject . put ( ModuleConstant . COMPONENT_APP_ID , componentAppId ) ;
jsonObject . put ( ModuleConstant . AUTHORIZER_APP_ID , authAppId ) ;
String componentAccessToken = redisThird . getComponentAccessToken ( ) ;
String data = HttpClientManager . getInstance ( ) . sendPostByJSON ( WxMaCodeConstant . API_GET_AUTHORIZER_INFO + componentAccessToken , JSON . toJSONString ( jsonObject ) ) . getData ( ) ;
Map < String , Map > map = JSON . parseObject ( data , Map . class ) ;
String data = HttpClientManager . getInstance ( ) . sendPostByJSON ( WxMaCodeConstant . API_GET_AUTHORIZER_INFO + componentAccessToken , JSON . toJSONString ( jsonObject ) ) . getData ( ) ;
Map < String , Map > map = JSON . parseObject ( data , Map . class ) ;
Map authorizerInfo = map . get ( ModuleConstant . AUTHORIZER_INFO ) ;
log . info ( "授权信息:" + authorizerInfo ) ;
log . info ( "授权信息:" + authorizerInfo ) ;
// 存在 “miniprograminfo” 字段为小程序,不存在为公众号
boolean keyExist = authorizerInfo . containsKey ( ModuleConstant . MINI_PROGRAM_INFO ) ;
if ( keyExist = = true ) {
if ( keyExist = = true ) {
log . info ( "授权方为小程序 并 开始插入信息" ) ;
MiniInfoFormDTO miniInfoFormDTO = ConvertUtils . mapToEntity ( authorizerInfo , MiniInfoFormDTO . class ) ;
miniInfoFormDTO . setCustomerId ( customerId ) ;
@ -498,22 +534,22 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
businessInfoForm . setPrimaryId ( primaryId ) ;
businessInfoList . add ( businessInfoForm ) ;
} ) ;
businessInfoDao . deleteBusinessInfo ( customerId , clientType ) ;
businessInfoDao . deleteBusinessInfo ( customerId , clientType ) ;
businessInfoDao . insertBusinessInfo ( businessInfoList ) ;
//todo 小程序配置的合法域名信息插入
Map miniProgramInfo = ( Map ) authorizerInfo . get ( ModuleConstant . MINI_PROGRAM_INFO ) ;
List < MiniNetworkInfoFormDTO > networkInfoList = new ArrayList < > ( ) ;
Map networkInfo = ( Map ) miniProgramInfo . get ( ModuleConstant . NETWORK ) ;
networkInfo . forEach ( ( key , value ) - > {
networkInfo . forEach ( ( key , value ) - > {
MiniNetworkInfoFormDTO miniNetworkInfoForm = new MiniNetworkInfoFormDTO ( ) ;
miniNetworkInfoForm . setCustomerId ( customerId ) ;
miniNetworkInfoForm . setCustomerId ( customerId ) ;
miniNetworkInfoForm . setClientType ( clientType ) ;
miniNetworkInfoForm . setNetworkType ( key . toString ( ) ) ;
miniNetworkInfoForm . setUrl ( value . toString ( ) ) ;
miniNetworkInfoForm . setPrimaryId ( primaryId ) ;
networkInfoList . add ( miniNetworkInfoForm ) ;
} ) ;
miniNetworkInfoDao . deleteNetworkInfo ( customerId , clientType ) ;
miniNetworkInfoDao . deleteNetworkInfo ( customerId , clientType ) ;
miniNetworkInfoDao . insertNetworkInfo ( networkInfoList ) ;
//todo 小程序配置的类目信息插入
List < MiniCategoryInfoFormDTO > categoryInfoList = new ArrayList < > ( ) ;
@ -533,7 +569,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
miniCategoryInfoDao . deleteCategoryInfo ( customerId , clientType ) ;
miniCategoryInfoDao . insertCategoryInfo ( categoryInfoList ) ;
}
} else {
} else {
log . info ( "授权方为公众号 并 开始插入信息" ) ;
PaInfoFormDTO paInfoFormDTO = ConvertUtils . mapToEntity ( authorizerInfo , PaInfoFormDTO . class ) ;
//公众号基本信息插入
@ -551,7 +587,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
businessInfoForm . setPrimaryId ( primaryId ) ;
businessInfoList . add ( businessInfoForm ) ;
} ) ;
businessInfoDao . deleteBusinessInfo ( customerId , clientType ) ;
businessInfoDao . deleteBusinessInfo ( customerId , clientType ) ;
businessInfoDao . insertBusinessInfo ( businessInfoList ) ;
}
log . info ( "保存授权方基本信息结束" ) ;
@ -559,12 +595,12 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
}
/ * *
* @Description 回填 customer_mp appId , 更改授权状态
* @param
* @Description 回填 customer_mp appId , 更改授权状态
* @author zxc
* /
@Transactional ( rollbackFor = Exception . class )
public void updateCustomerMpAppId ( String customerId , String authAppId , String clientType ) {
public void updateCustomerMpAppId ( String customerId , String authAppId , String clientType ) {
log . info ( "==========回填customer_mp开始==========" ) ;
Integer checkBindCount = customerMpDao . checkBind ( authAppId , clientType ) ;
if ( checkBindCount = = NumConstant . ZERO ) {
@ -578,14 +614,14 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
log . info ( "==========回填customer_mp结束==========" ) ;
}
public void createAndBindOpenAccount ( String customerId , String authAppId , String clientType ) {
public void createAndBindOpenAccount ( String customerId , String authAppId , String clientType ) {
log . info ( ThirdRunTimeInfoConstant . BEGIN_CREATE_OPEN ) ;
Map < String , Object > authorizerRefreshToken = redisThird . getAuthorizerRefreshToken ( customerId + ThirdRedisKeyConstant . COLON + clientType ) ;
String authorizerAccessToken = authorizerRefreshToken . get ( "authorizerAccessToken" ) . toString ( ) ;
JSONObject bindInfoForm = new JSONObject ( ) ;
bindInfoForm . put ( ModuleConstant . LOW_APP_ID , authAppId ) ;
bindInfoForm . put ( ModuleConstant . LOW_APP_ID , authAppId ) ;
String bindResult = HttpClientManager . getInstance ( ) . sendPostByJSON ( WxMaCodeConstant . API_OPEN_GET + authorizerAccessToken , JSON . toJSONString ( bindInfoForm ) ) . getData ( ) ;
Map < String , Object > bindInfo = JSON . parseObject ( bindResult , Map . class ) ;
Map < String , Object > bindInfo = JSON . parseObject ( bindResult , Map . class ) ;
boolean bindStatus = bindInfo . containsKey ( ModuleConstant . OPEN_APP_ID ) ;
if ( bindStatus ! = true ) {
Integer authCount = customerMpDao . selectAuthCount ( customerId ) ;
@ -663,11 +699,11 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
}
/ * *
* @Description 转换过期时间
* @param expiresIn
* @Description 转换过期时间
* @author zxc
* /
public Date countExpirationTime ( String expiresIn ) {
public Date countExpirationTime ( String expiresIn ) {
expiresIn = expiresIn + "000" ;
Date date = new Date ( ) ;
long l = date . getTime ( ) + Long . valueOf ( expiresIn ) ;
@ -676,21 +712,21 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
}
/ * *
* @Description 查询客户Id
* @param tokenDto
* @Description 查询客户Id
* @author zxc
* /
public String getLoginUserCustomerId ( TokenDto tokenDto ) {
public String getLoginUserCustomerId ( TokenDto tokenDto ) {
PaCustomerUserAgencyDTO result = paCustomerUserAgencyDao . selectCustomerIdByUserId ( tokenDto . getUserId ( ) ) ;
return result . getCustomerId ( ) ;
}
/ * *
* @Description 时间戳 ( 秒级 ) 转换 Date
* @param t
* @Description 时间戳 ( 秒级 ) 转换 Date
* @author zxc
* /
public Date sToDate ( String t ) {
public Date sToDate ( String t ) {
Long aLong = Long . valueOf ( t + "000" ) ;
Date date = new Date ( ) ;
date . setTime ( aLong ) ;
@ -699,24 +735,24 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
/ * *
* @author sun
* @Description 校验客户两哥小程序是否完成授权
* @Description 校验客户两哥小程序是否完成授权
* /
private void checkAuthorization ( String customerId ) {
private void checkAuthorization ( String customerId ) {
List < CustomerMpDTO > list = customerMpDao . selectByCustomerId ( customerId ) ;
AtomicBoolean bl = new AtomicBoolean ( false ) ;
list . forEach ( mp - > {
if ( mp . getAuthorizationFlag ( ) ! = NumConstant . ONE ) {
list . forEach ( mp - > {
if ( mp . getAuthorizationFlag ( ) ! = NumConstant . ONE ) {
bl . set ( true ) ;
}
} ) ;
if ( ! bl . get ( ) ) {
if ( ! bl . get ( ) ) {
dDingNews ( customerId ) ;
}
}
/ * *
* @author sun
* @Description 发送钉钉消息 , 通知运营人员有新客户完成授权
* @Description 发送钉钉消息 , 通知运营人员有新客户完成授权
* /
private String dDingNews ( String customerId ) {
//1.查询客户及管理员信息,用于发送消息使用
@ -739,8 +775,29 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
"> 管理员称谓: " + result . getAppellation ( ) + "\n\n" +
"> 联系方式: " + result . getPhone ( ) + "\n" ) ;
request . setMarkdown ( markdown ) ;
HttpClientManager . getInstance ( ) . sendDingMsg ( JSON . toJSONString ( request ) , url , secret ) ;
HttpClientManager . getInstance ( ) . sendDingMsg ( JSON . toJSONString ( request ) , url , secret ) ;
return null ;
}
/ * *
* @Description 推送AuthorizerAccessToken到私有化平台们
* @param form
* @return void
* @author wxz
* @date 2021 . 08 . 31 17 : 22 : 04
* /
public void pushAuthorizerAccessToken2PrivateEpmets ( AuthorizerAccessTokenFormDTO form ) {
List < ThirdPlatformActionsResultDTO > platforms = thirdPlatformService . listPlatformsByActionKey ( ThirdPlatformActions . PUSH_AUTHORIZER_ACCESS_TOKEN ) ;
platforms . stream ( ) . forEach ( p - > {
log . info ( "推送authorizer-access-token到私有化平台:platformId:{}, platformKey:{}, platformName:{}, apiUrl:{}" , p . getPlatformId ( ) , p . getPlatformKey ( ) , p . getPlatformName ( ) , p . getApiUrl ( ) ) ;
ApiService apiService = selectApiService ( p . getPlatformId ( ) ) ;
try {
apiService . pushAuthorizerAccessToken ( form , p . getPlatformId ( ) , p . getPlatformKey ( ) ) ;
} catch ( Exception e ) {
String detail = ExceptionUtils . getErrorStackTrace ( e ) ;
log . error ( detail ) ;
}
} ) ;
}
}