Browse Source

Merge remote-tracking branch 'origin/dev_thirdplatform' into dev

master
zxc 5 years ago
parent
commit
d10165aaec
  1. 5
      epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/AuthorizationInfoFormDTO.java
  2. 2
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ThirdRunTimeInfoConstant.java
  3. 40
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java
  4. 3
      epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/AuthorizationInfoDao.xml

5
epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/AuthorizationInfoFormDTO.java

@ -44,6 +44,11 @@ public class AuthorizationInfoFormDTO implements Serializable {
*/ */
private String clientType; private String clientType;
/**
* 权限列表
*/
private String funcInfo;
private Integer delFlag = 0; private Integer delFlag = 0;
private String createdBy = "APP_USER"; private String createdBy = "APP_USER";

2
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ThirdRunTimeInfoConstant.java

@ -46,7 +46,7 @@ public interface ThirdRunTimeInfoConstant {
String END_GET_AUTH_INFO = "=====================结束获取【authorization_info】====================="; String END_GET_AUTH_INFO = "=====================结束获取【authorization_info】=====================";
String CREATE_AND_BIND_SUCCESS = "创建开放平台帐号并绑定公众号/小程序"; String CREATE_AND_BIND_SUCCESS = "开始创建开放平台帐号并绑定公众号/小程序";
String BIND_SUCCESS = "绑定公众号/小程序到开放平台"; String BIND_SUCCESS = "绑定公众号/小程序到开放平台";

40
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java

@ -111,20 +111,17 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
String nonce = request.getParameter(ModuleConstant.NONCE); String nonce = request.getParameter(ModuleConstant.NONCE);
String encryptType = request.getParameter(ModuleConstant.ENCRYPT_TYPE); String encryptType = request.getParameter(ModuleConstant.ENCRYPT_TYPE);
String signature = request.getParameter(ModuleConstant.SIGNATURE); String signature = request.getParameter(ModuleConstant.SIGNATURE);
log.info(String.format(ThirdRunTimeInfoConstant.VERIFY_TICKET,msgSignature,timeStamp,nonce,encryptType,signature));
// 从请求中读取整个post数据 // 从请求中读取整个post数据
InputStream inputStream; InputStream inputStream;
String postData = null; String postData = null;
inputStream = request.getInputStream(); inputStream = request.getInputStream();
postData= IOUtils.toString(inputStream,ModuleConstant.UTF8); postData= IOUtils.toString(inputStream,ModuleConstant.UTF8);
log.info("postData = "+postData);
WXBizMsgCrypt wxBizMsgCrypt = new WXBizMsgCrypt(token,aesKey,componentAppId); WXBizMsgCrypt wxBizMsgCrypt = new WXBizMsgCrypt(token,aesKey,componentAppId);
String msg = wxBizMsgCrypt.decryptMsg(msgSignature, timeStamp, nonce, postData); String msg = wxBizMsgCrypt.decryptMsg(msgSignature, timeStamp, nonce, postData);
log.info(String.format(ThirdRunTimeInfoConstant.MSG,msg)); log.info(String.format(ThirdRunTimeInfoConstant.MSG,msg));
// 将xml转为map // 将xml转为map
Map<String, String> result = WXXmlToMapUtil.xmlToMap(msg); Map<String, String> result = WXXmlToMapUtil.xmlToMap(msg);
String infotype = result.get(ModuleConstant.INFO_TYPE); String infotype = result.get(ModuleConstant.INFO_TYPE);
log.info(infotype);
switch (infotype){ switch (infotype){
case ModuleConstant.TICKET_UNDERLINE_KEY: //接收票据 【component_verify_ticket】 case ModuleConstant.TICKET_UNDERLINE_KEY: //接收票据 【component_verify_ticket】
String ComponentVerifyTicket = result.get(ModuleConstant.TICKET_KEY); String ComponentVerifyTicket = result.get(ModuleConstant.TICKET_KEY);
@ -296,28 +293,13 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
authInfoDTO.setExpiresInTime(expiresInTime); authInfoDTO.setExpiresInTime(expiresInTime);
authInfoDTO.setCustomerId(customerId); authInfoDTO.setCustomerId(customerId);
authInfoDTO.setClientType(clientType); authInfoDTO.setClientType(clientType);
List<Map> func_info = authorizationInfoResultDTO.getFunc_info();
log.info("权限列表信息:"+func_info);
String funcInfo = JSON.toJSONString(func_info);
authInfoDTO.setFuncInfo(funcInfo);
//先逻辑删除,在插入 //先逻辑删除,在插入
authorizationInfoDao.updateOldAuthorizationInfo(authAppId); authorizationInfoDao.updateOldAuthorizationInfo(authAppId);
authorizationInfoDao.insertAuthorizationInfo(authInfoDTO); authorizationInfoDao.insertAuthorizationInfo(authInfoDTO);
// 2. 权限列表
log.info(START_INSERT_FUNC_INFO);
List<FuncInfoFormDTO> funcInfos = new ArrayList<>();
List<Map> func_info = authorizationInfoResultDTO.getFunc_info();
log.info("权限列表信息:"+func_info);
/*func_info.forEach(func -> {
func.forEach((key,value) -> {
FuncInfoFormDTO fu = new FuncInfoFormDTO();
fu.setFuncscopeCategory((String) key);
Map funcScope = (Map) value;
fu.setFuncscopeId(funcScope.get(ModuleConstant.ID).toString());
fu.setAuthorizationInfoAppid(authAppId);
fu.setCustomerId(customerId);
funcInfos.add(fu);
});
});*/
// todo 先逻辑删除,在插入
/*funcInfoDao.updateOldFuncInfo(customerId,authAppId);
funcInfoDao.insertFuncInfo(funcInfos);*/
// 授权信息放入缓存 // 授权信息放入缓存
redisThird.setAuthInfo(authorizationInfoResultDTO,customerId,clientType); redisThird.setAuthInfo(authorizationInfoResultDTO,customerId,clientType);
//authorizer_refresh_token 放入缓存 //authorizer_refresh_token 放入缓存
@ -353,7 +335,6 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
Map map = JSON.parseObject(data, HashMap.class); Map map = JSON.parseObject(data, HashMap.class);
if (!map.containsKey(ModuleConstant.ERR_CODE)) { if (!map.containsKey(ModuleConstant.ERR_CODE)) {
log.info(REFRESH_AUTH_ACCESS_TOKEN); log.info(REFRESH_AUTH_ACCESS_TOKEN);
//authorizer_access_token
String authorizerAccessToken = map.get(ModuleConstant.AUTHORIZER_ACCESS_TOKEN).toString(); String authorizerAccessToken = map.get(ModuleConstant.AUTHORIZER_ACCESS_TOKEN).toString();
String expiresIn = map.get(ModuleConstant.EXPIRES_IN).toString(); String expiresIn = map.get(ModuleConstant.EXPIRES_IN).toString();
String authorizerRefreshToken = map.get(ModuleConstant.AUTHORIZER_REFRESH_TOKEN).toString(); String authorizerRefreshToken = map.get(ModuleConstant.AUTHORIZER_REFRESH_TOKEN).toString();
@ -372,7 +353,6 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
//先逻辑删除,在插入 //先逻辑删除,在插入
authorizationInfoDao.updateOldAuthorizerAccessToken(customerId, clientType); authorizationInfoDao.updateOldAuthorizerAccessToken(customerId, clientType);
authorizationInfoDao.insertAuthorizerAccessToken(formDTO); authorizationInfoDao.insertAuthorizerAccessToken(formDTO);
//缓存 refreshAuthorizerAccessToken //缓存 refreshAuthorizerAccessToken
redisThird.setAuthorizerRefreshToken(authorizationInfo); redisThird.setAuthorizerRefreshToken(authorizationInfo);
} }
@ -396,28 +376,26 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
String expiresIn = authCodeAndTime.getExpiresIn(); String expiresIn = authCodeAndTime.getExpiresIn();
String customerId = this.getLoginUserCustomerId(tokenDto); String customerId = this.getLoginUserCustomerId(tokenDto);
Date expiresInTime = this.countExpirationTime(expiresIn); Date expiresInTime = this.countExpirationTime(expiresIn);
if (StringUtils.isBlank(customerId)||StringUtils.isBlank(clientType)||StringUtils.isBlank(authCode)||StringUtils.isBlank(expiresIn)){
log.info("客户ID = "+customerId+", 客户端类型为 = "+clientType+", 授权码为 = "+authCode+", 有效期 = "+expiresIn);
}
//authCode存数据库 //authCode存数据库
AuthCodeFormDTO formDTO = new AuthCodeFormDTO(); AuthCodeFormDTO formDTO = new AuthCodeFormDTO();
formDTO.setAuthCode(authCode); formDTO.setAuthCode(authCode);
formDTO.setExpiresInTime(expiresInTime); formDTO.setExpiresInTime(expiresInTime);
formDTO.setClientType(clientType); formDTO.setClientType(clientType);
//授权方AppId
formDTO.setCustomerId(customerId); formDTO.setCustomerId(customerId);
log.info(formDTO.toString()); log.info(formDTO.toString());
authCodeDao.deleteCustomerAuthCode(customerId,clientType); authCodeDao.deleteCustomerAuthCode(customerId,clientType);
authCodeDao.insertRedirectAuthCode(formDTO); authCodeDao.insertRedirectAuthCode(formDTO);
//authCode存缓存 //authCode存缓存
redisThird.setAuthCode(formDTO); redisThird.setAuthCode(formDTO);
// 1. 开始获取授权信息(使用授权码)
AuthorizationInfoResultDTO authorizationInfoResultDTO = this.authInfoByAuthCode(authCode, customerId, clientType); AuthorizationInfoResultDTO authorizationInfoResultDTO = this.authInfoByAuthCode(authCode, customerId, clientType);
String authAppId = authorizationInfoResultDTO.getAuthorizer_appid(); String authAppId = authorizationInfoResultDTO.getAuthorizer_appid();
// todo ================================================ // 2. 创建开放平台账号并绑定 或者 直接绑定开放平台
AuthCodeResultDTO authCodeResultDTO = authorizationInfoDao.selectCustomerIdByAuthAppId(authAppId);
this.createAndBindOpenAccount(customerId,authAppId,clientType); this.createAndBindOpenAccount(customerId,authAppId,clientType);
// 3. 更新 customer_mp 表授权状态和AuthAppId
this.updateCustomerMpAppId(customerId,authAppId,clientType); this.updateCustomerMpAppId(customerId,authAppId,clientType);
authCodeDao.updateAppId(customerId,clientType,authAppId); authCodeDao.updateAppId(customerId,clientType,authAppId);
// 4. 保存授权方账户信息
this.saveAuthAccountInfo(customerId,authAppId,clientType); this.saveAuthAccountInfo(customerId,authAppId,clientType);
log.info("回调结束"); log.info("回调结束");
} }
@ -546,7 +524,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
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); boolean bindStatus = bindInfo.containsKey(ModuleConstant.OPEN_APP_ID);
if (bindStatus != true) { if (bindStatus != true) {
log.info("开始创建开放平台账号并绑定"); log.info(CREATE_AND_BIND_SUCCESS);
List<String> authCount = customerMpDao.selectAuthCount(customerId); List<String> authCount = customerMpDao.selectAuthCount(customerId);
String openPlatformId = null; String openPlatformId = null;
if (authCount.size() > 0) { if (authCount.size() > 0) {

3
epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/AuthorizationInfoDao.xml

@ -5,7 +5,7 @@
<!-- 插入 授权信息 --> <!-- 插入 授权信息 -->
<insert id="insertAuthorizationInfo" parameterType="com.epmet.dto.form.AuthorizationInfoFormDTO"> <insert id="insertAuthorizationInfo" parameterType="com.epmet.dto.form.AuthorizationInfoFormDTO">
INSERT INTO authorization_info ( ID, CUSTOMER_ID, AUTHORIZER_APPID, AUTHORIZER_ACCESS_TOKEN, EXPIRES_IN_TIME, AUTHORIZER_REFRESH_TOKEN, CLIENT_TYPE, DEL_FLAG, CREATED_BY, CREATED_TIME, UPDATED_BY, UPDATED_TIME ) INSERT INTO authorization_info ( ID, CUSTOMER_ID, AUTHORIZER_APPID, AUTHORIZER_ACCESS_TOKEN, EXPIRES_IN_TIME, AUTHORIZER_REFRESH_TOKEN, FUNC_INFO, CLIENT_TYPE, DEL_FLAG, CREATED_BY, CREATED_TIME, UPDATED_BY, UPDATED_TIME )
VALUES VALUES
( (
REPLACE ( UUID(), '-', '' ), REPLACE ( UUID(), '-', '' ),
@ -14,6 +14,7 @@
#{authorizerAccessToken}, #{authorizerAccessToken},
#{expiresInTime}, #{expiresInTime},
#{authorizerRefreshToken}, #{authorizerRefreshToken},
#{funcInfo},
#{clientType}, #{clientType},
#{delFlag}, #{delFlag},
#{createdBy}, #{createdBy},

Loading…
Cancel
Save