Browse Source

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

dev_shibei_match
zxc 5 years ago
parent
commit
e60cfdf67f
  1. 86
      epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/AuthResultRecordFormDTO.java
  2. 3
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ModuleConstant.java
  3. 2
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ThirdRunTimeInfoConstant.java
  4. 8
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/AuthResultRecordDao.java
  5. 8
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/CustomerMpDao.java
  6. 110
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java
  7. 21
      epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/AuthResultRecordDao.xml
  8. 12
      epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/CustomerMpDao.xml

86
epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/AuthResultRecordFormDTO.java

@ -0,0 +1,86 @@
package com.epmet.dto.form;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* @Author zxc
* @CreateTime 2020/7/24 9:22
*/
@Data
public class AuthResultRecordFormDTO implements Serializable {
private static final long serialVersionUID = -5359209459022630868L;
/**
* ID
*/
private String id;
/**
* 客户ID
*/
private String customerId;
/**
* resi居民端work工作端
*/
private String clientType;
/**
* 第三方平台AppId 第三方平台AppId
*/
private String componentAppId;
/**
* 微信返回创建时间 微信返回创建时间
*/
private Date wechatCreateTime;
/**
* 通知类型
*/
private String InfoType;
/**
* 授权方AppId
*/
private String AuthorizerAppid;
/**
* 授权码auth_code
*/
private String AuthorizationCode;
/**
* 授权码过期时间
*/
private Date ExpiredTime;
/**
* 预授权码
*/
private String PreAuthCode;
/**
* 删除状态
*/
private Integer delFlag = 0;
/**
* 乐观锁
*/
private Integer revision = 0;
/**
* 创建人
*/
private String createdBy = "APP_USER";
/**
* 更新人
*/
private String updatedBy = "APP_USER";
}

3
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ModuleConstant.java

@ -22,9 +22,12 @@ public interface ModuleConstant {
String AUTHORIZATION_CODE_HUMP = "AuthorizationCode";
String UNAUTHORIZED = "unauthorized";
String AUTHORIZED = "authorized";
String UPDATE_AUTHORIZED = "updateauthorized";
String NULL_CHAR = "";
String SUCCESS = "success";
String AUTHORIZER_APP_ID_HUMP = "AuthorizerAppid";
String PRE_AUTH_CODE_HUMP = "PreAuthCode";
String AUTHORIZATION_CODE_EXPIRED_TIME = "AuthorizationCodeExpiredTime";
// 获取 component_access_token 如下
String COMPONENT_APPID = "component_appid";

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

@ -82,4 +82,6 @@ public interface ThirdRunTimeInfoConstant {
String VERIFY_TICKET = "msgSignature = %s, timeStamp = %s, nonce = %s, encryptType = %s, signature = %s";
String REFRESH_AUTH_ACCESS_TOKEN = "查询到新的 授权方【access_token】";
}

8
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/AuthResultRecordDao.java

@ -18,6 +18,7 @@
package com.epmet.dao;
import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.dto.form.AuthResultRecordFormDTO;
import com.epmet.entity.AuthResultRecordEntity;
import org.apache.ibatis.annotations.Mapper;
@ -29,5 +30,12 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface AuthResultRecordDao extends BaseDao<AuthResultRecordEntity> {
/**
* @Description 插入授权结果记录
* @param formDTO
* @author zxc
*/
void insertAuthResultRecord(AuthResultRecordFormDTO formDTO);
}

8
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/CustomerMpDao.java

@ -107,4 +107,12 @@ public interface CustomerMpDao extends BaseDao<CustomerMpEntity> {
* @Description 根据appId查询客户信息
**/
PaCustomerDTO selectCustomerByAppId(@Param("appId") String appId);
/**
* @Description 校验此小程序是不是绑定别的客户端
* @param authAppId
* @param clientType
* @author zxc
*/
Integer checkBind(String authAppId,String clientType);
}

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

@ -1,7 +1,9 @@
package com.epmet.service.impl;
import cn.hutool.core.convert.Convert;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.nacos.client.config.utils.IOUtils;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.exception.RenException;
@ -77,6 +79,8 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
private BusinessInfoDao businessInfoDao;
@Autowired
private EpmetUserOpenFeignClient epmetUserOpenFeignClient;
@Autowired
private AuthResultRecordDao authResultRecordDao;
@Value("${third.platform.appId}")
private String componentAppId;
@ -136,16 +140,16 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
log.info(ModuleConstant.TICKET_UNDERLINE_KEY+":"+ComponentVerifyTicket);
break;
case ModuleConstant.AUTHORIZED: //授权成功
// 更改customer_mp 授权信息,appId,并绑定
String authCode = result.get(ModuleConstant.AUTHORIZATION_CODE_HUMP);
String authAppId = result.get(ModuleConstant.AUTHORIZER_APP_ID_HUMP);
log.info("=============================="+authCode);
this.disposeAuthResult(result);
break;
case ModuleConstant.UNAUTHORIZED://用户取消授权
//todo 取消授权
String authorizerAppId = result.get(ModuleConstant.AUTHORIZER_APP_ID_HUMP);
customerMpDao.updateAuthorizationFlag(authorizerAppId);
this.disposeAuthResult(result);
break;
case ModuleConstant.UPDATE_AUTHORIZED://授权变更
this.disposeAuthResult(result);
break;
}
} catch (Exception e) {
@ -161,6 +165,24 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
return ModuleConstant.SUCCESS;
}
/**
* @Description 授权结果插入
* @param result
* @author zxc
*/
@Transactional(rollbackFor = Exception.class)
public void disposeAuthResult(Map<String,String> result){
Map tempMap = result;
Map<String,Object> data = tempMap;
AuthResultRecordFormDTO authResultRecord = mapToEntity(data, AuthResultRecordFormDTO.class);
authResultRecord.setWechatCreateTime(this.sToDate(result.get(ModuleConstant.CREATE_TIME)));
if (result.containsKey(ModuleConstant.AUTHORIZATION_CODE_EXPIRED_TIME)) {
authResultRecord.setExpiredTime(this.sToDate(result.get(ModuleConstant.AUTHORIZATION_CODE_EXPIRED_TIME)));
}
authResultRecord.setComponentAppId(componentAppId);
authResultRecordDao.insertAuthResultRecord(authResultRecord);
}
/**
* @Description 定时获取 (令牌component_access_token) 第三方与微信交互使用的component_access_token
* 每十分钟执行一次,判断是否有马上超时的15分钟以内算马上超时
@ -329,28 +351,31 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
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);
//authorizer_access_token
String authorizerAccessToken = map.get(ModuleConstant.AUTHORIZER_ACCESS_TOKEN).toString();
String expiresIn = map.get(ModuleConstant.EXPIRES_IN).toString();
String authorizerRefreshToken = map.get(ModuleConstant.AUTHORIZER_REFRESH_TOKEN).toString();
Date expiresInTime = this.countExpirationTime(expiresIn);
//更新DB
AuthorizerAccessTokenFormDTO formDTO = new AuthorizerAccessTokenFormDTO();
AuthorizationInfoFormDTO authorizationInfo = new AuthorizationInfoFormDTO();
BeanUtils.copyProperties(formDTO,authorizationInfo);
authorizationInfo.setAuthorizerAppid(authAppId);
formDTO.setAuthorizerAccessToken(authorizerAccessToken);
formDTO.setAuthorizerRefreshToken(authorizerRefreshToken);
formDTO.setExpiresInTime(expiresInTime);
formDTO.setCustomerId(customerId);
formDTO.setAuthAppid(authAppId);
formDTO.setClientType(clientType);
//先逻辑删除,在插入
authorizationInfoDao.updateOldAuthorizerAccessToken(customerId,clientType);
authorizationInfoDao.insertAuthorizerAccessToken(formDTO);
if (!map.containsKey(ModuleConstant.ERR_CODE)) {
log.info(REFRESH_AUTH_ACCESS_TOKEN);
//authorizer_access_token
String authorizerAccessToken = map.get(ModuleConstant.AUTHORIZER_ACCESS_TOKEN).toString();
String expiresIn = map.get(ModuleConstant.EXPIRES_IN).toString();
String authorizerRefreshToken = map.get(ModuleConstant.AUTHORIZER_REFRESH_TOKEN).toString();
Date expiresInTime = this.countExpirationTime(expiresIn);
//更新DB
AuthorizerAccessTokenFormDTO formDTO = new AuthorizerAccessTokenFormDTO();
AuthorizationInfoFormDTO authorizationInfo = new AuthorizationInfoFormDTO();
BeanUtils.copyProperties(formDTO, authorizationInfo);
authorizationInfo.setAuthorizerAppid(authAppId);
formDTO.setAuthorizerAccessToken(authorizerAccessToken);
formDTO.setAuthorizerRefreshToken(authorizerRefreshToken);
formDTO.setExpiresInTime(expiresInTime);
formDTO.setCustomerId(customerId);
formDTO.setAuthAppid(authAppId);
formDTO.setClientType(clientType);
//先逻辑删除,在插入
authorizationInfoDao.updateOldAuthorizerAccessToken(customerId, clientType);
authorizationInfoDao.insertAuthorizerAccessToken(formDTO);
//缓存 refreshAuthorizerAccessToken
redisThird.setAuthorizerRefreshToken(authorizationInfo);
//缓存 refreshAuthorizerAccessToken
redisThird.setAuthorizerRefreshToken(authorizationInfo);
}
});
log.info("更新authorizer_access_token成功");
}
@ -388,6 +413,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
redisThird.setAuthCode(formDTO);
AuthorizationInfoResultDTO authorizationInfoResultDTO = this.authInfoByAuthCode(authCode, customerId, clientType);
String authAppId = authorizationInfoResultDTO.getAuthorizer_appid();
// todo ================================================
AuthCodeResultDTO authCodeResultDTO = authorizationInfoDao.selectCustomerIdByAuthAppId(authAppId);
this.createAndBindOpenAccount(customerId,authAppId,clientType);
this.updateCustomerMpAppId(customerId,authAppId,clientType);
@ -499,12 +525,15 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
@Transactional(rollbackFor = Exception.class)
public void updateCustomerMpAppId(String customerId,String authAppId,String clientType){
log.info("==========回填customer_mp开始==========");
AuthCodeFormDTO formDTO = new AuthCodeFormDTO();
formDTO.setClientType(clientType);
formDTO.setAuthAppId(authAppId);
formDTO.setCustomerId(customerId);
//回填customer_mp的appId 只需以上三个字段
customerMpDao.updateAppIDByCustomerIdAndClient(formDTO);
Integer checkBindCount = customerMpDao.checkBind(authAppId, clientType);
if (checkBindCount == NumConstant.ZERO) {
AuthCodeFormDTO formDTO = new AuthCodeFormDTO();
formDTO.setClientType(clientType);
formDTO.setAuthAppId(authAppId);
formDTO.setCustomerId(customerId);
//回填customer_mp的appId 只需以上三个字段
customerMpDao.updateAppIDByCustomerIdAndClient(formDTO);
}
log.info("==========回填customer_mp结束==========");
}
@ -635,10 +664,27 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
return date;
}
/**
* @Description 查询客户Id
* @param tokenDto
* @author zxc
*/
public String getLoginUserCustomerId(TokenDto tokenDto){
LoginUserDetailsFormDTO dto = new LoginUserDetailsFormDTO();
BeanUtils.copyProperties(tokenDto,dto);
LoginUserDetailsResultDTO data = epmetUserOpenFeignClient.getLoginUserDetails(dto).getData();
return data.getCustomerId();
}
/**
* @Description 时间戳秒级转换 Date
* @param t
* @author zxc
*/
public Date sToDate(String t){
Long aLong = Long.valueOf(t + "000");
Date date = new Date();
date.setTime(aLong);
return date;
}
}

21
epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/AuthResultRecordDao.xml

@ -3,4 +3,25 @@
<mapper namespace="com.epmet.dao.AuthResultRecordDao">
<!-- 插入授权结果记录 -->
<insert id="insertAuthResultRecord">
INSERT INTO auth_result_record ( ID, COMPONENT_APP_ID, WECHAT_CREATE_TIME, INFO_TYPE, AUTHORIZER_APP_ID, AUTHORIZATION_CODE, EXPIRES_IN_TIME, PRE_AUTH_CODE, DEL_FLAG, REVISION, CREATED_BY, CREATED_TIME, UPDATED_BY, UPDATED_TIME )
VALUES
(
REPLACE(UUID(),'-',''),
#{componentAppId},
#{wechatCreateTime},
#{InfoType},
#{AuthorizerAppid},
#{AuthorizationCode},
#{ExpiredTime},
#{PreAuthCode},
#{delFlag},
#{revision},
#{createdBy},
NOW(),
#{updatedBy},
NOW()
)
</insert>
</mapper>

12
epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/CustomerMpDao.xml

@ -115,4 +115,16 @@
AND cm.app_id = #{appId}
</select>
<!-- 校验此小程序是不是绑定别的客户端 -->
<select id="checkBind" resultType="java.lang.Integer">
SELECT
COUNT(*)
FROM
customer_mp
WHERE
del_flag = 0
AND app_id = #{authAppId}
AND client != #{clientType}
</select>
</mapper>
Loading…
Cancel
Save