Browse Source

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

dev_shibei_match
wxz 5 years ago
parent
commit
89dd99ab2e
  1. 2
      epmet-auth/deploy/docker-compose-dev.yml
  2. 2
      epmet-auth/pom.xml
  3. 6
      epmet-auth/src/main/java/com/epmet/dto/form/GovWxmpEnteOrgFormDTO.java
  4. 30
      epmet-auth/src/main/java/com/epmet/service/impl/GovLoginServiceImpl.java
  5. 20
      epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/OpenAppIdFormDTO.java
  6. 26
      epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/RemoveBindFormDTO.java
  7. 2
      epmet-module/epmet-third/epmet-third-server/deploy/docker-compose-dev.yml
  8. 2
      epmet-module/epmet-third/epmet-third-server/pom.xml
  9. 27
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/AppLetAuthorizationController.java
  10. 9
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/BindingAccountDao.java
  11. 10
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/CustomerMpDao.java
  12. 11
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/redis/RedisThird.java
  13. 18
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/AppLetAuthorizationService.java
  14. 78
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/AppLetAuthorizationServiceImpl.java
  15. 8
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java
  16. 10
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/wxapi/constant/WxMaCodeConstant.java
  17. 9
      epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/BindingAccountDao.xml
  18. 19
      epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/CustomerMpDao.xml

2
epmet-auth/deploy/docker-compose-dev.yml

@ -2,7 +2,7 @@ version: "3.7"
services:
epmet-auth-server:
container_name: epmet-auth-server-dev
image: 192.168.1.130:10080/epmet-cloud-dev/epmet-auth:0.3.47
image: 192.168.1.130:10080/epmet-cloud-dev/epmet-auth:0.3.48
ports:
- "8081:8081"
network_mode: host # 使用现有网络

2
epmet-auth/pom.xml

@ -2,7 +2,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<version>0.3.47</version>
<version>0.3.48</version>
<parent>
<groupId>com.epmet</groupId>
<artifactId>epmet-cloud</artifactId>

6
epmet-auth/src/main/java/com/epmet/dto/form/GovWxmpEnteOrgFormDTO.java

@ -38,5 +38,11 @@ public class GovWxmpEnteOrgFormDTO implements Serializable {
*/
@NotBlank(message = "组织id不能为空",groups = {AddUserInternalGroup.class})
private String rootAgencyId;
/**
* 客户appIdexJson文件中获取
*/
@NotBlank(message = "appId不能为空",groups = {AddUserInternalGroup.class})
private String appId;
}

30
epmet-auth/src/main/java/com/epmet/service/impl/GovLoginServiceImpl.java

@ -19,12 +19,10 @@ import com.epmet.constant.SmsTemplateConstant;
import com.epmet.dto.CustomerAgencyDTO;
import com.epmet.dto.CustomerStaffDTO;
import com.epmet.dto.GovStaffRoleDTO;
import com.epmet.dto.UserWechatDTO;
import com.epmet.dto.form.*;
import com.epmet.dto.result.*;
import com.epmet.feign.EpmetMessageOpenFeignClient;
import com.epmet.feign.EpmetUserFeignClient;
import com.epmet.feign.EpmetUserOpenFeignClient;
import com.epmet.feign.GovOrgFeignClient;
import com.epmet.feign.*;
import com.epmet.jwt.JwtTokenProperties;
import com.epmet.jwt.JwtTokenUtils;
import com.epmet.redis.CaptchaRedis;
@ -67,6 +65,8 @@ public class GovLoginServiceImpl implements GovLoginService {
private EpmetMessageOpenFeignClient epmetMessageOpenFeignClient;
@Autowired
private EpmetUserOpenFeignClient userOpenFeignClient;
@Autowired
private EpmetThirdFeignClient epmetThirdFeignClient;
/**
* @param formDTO
@ -272,8 +272,24 @@ public class GovLoginServiceImpl implements GovLoginService {
throw new RenException(customerStaffDTOResult.getCode());
}
CustomerStaffDTO customerStaff = customerStaffDTOResult.getData();
//2、解析微信用户
WxMaJscode2SessionResult wxMaJscode2SessionResult = loginService.getWxMaUser(LoginConstant.APP_GOV, formDTO.getWxCode());
/*//2、解析微信用户
WxMaJscode2SessionResult wxMaJscode2SessionResult = loginService.getWxMaUser(LoginConstant.APP_GOV, formDTO.getWxCode());*/
//2020.7.24 获取微信信息接口调整,改调用微信api的方式 sun
//2.调用epmet_third服务,校验appId是否有效以及是否授权,校验通过的调用微信API获取用户基本信息
WxLoginFormDTO resiLoginFormDTO = new WxLoginFormDTO();
resiLoginFormDTO.setAppId(formDTO.getAppId());
resiLoginFormDTO.setWxCode(formDTO.getWxCode());
Result<UserWechatDTO> result = epmetThirdFeignClient.resiAndWorkLogin(resiLoginFormDTO);
if (!result.success()) {
logger.error("工作端小程序登陆,调用epmet_third服务获取数据失败");
throw new RenException(result.getCode());
}
UserWechatDTO userWechatDTO = result.getData();
WxMaJscode2SessionResult wxMaJscode2SessionResult = new WxMaJscode2SessionResult();
wxMaJscode2SessionResult.setOpenid(userWechatDTO.getWxOpenId());
wxMaJscode2SessionResult.setSessionKey(userWechatDTO.getSessionKey());
wxMaJscode2SessionResult.setUnionid("");
//3、记录staff_wechat,并记录用户激活状态,激活时间
this.savestaffwechat(customerStaff.getUserId(), wxMaJscode2SessionResult.getOpenid());
//4、记录登录日志
@ -437,7 +453,7 @@ public class GovLoginServiceImpl implements GovLoginService {
govTokenDto.setUserId(staffId);
govTokenDto.setOpenId(wxMaJscode2SessionResult.getOpenid());
govTokenDto.setSessionKey(wxMaJscode2SessionResult.getSessionKey());
govTokenDto.setUnionId(wxMaJscode2SessionResult.getUnionid());
govTokenDto.setUnionId(null == wxMaJscode2SessionResult.getUnionid() ? "" : wxMaJscode2SessionResult.getUnionid());
govTokenDto.setToken(token);
govTokenDto.setUpdateTime(System.currentTimeMillis());
govTokenDto.setExpireTime(jwtTokenUtils.getExpiration(token).getTime());

20
epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/OpenAppIdFormDTO.java

@ -0,0 +1,20 @@
package com.epmet.dto.form;
import lombok.Data;
import java.io.Serializable;
/**
* @Author zxc
* @CreateTime 2020/7/24 16:31
*/
@Data
public class OpenAppIdFormDTO implements Serializable {
private static final long serialVersionUID = 4181403694668558506L;
/**
* 客户端类型
*/
private String clientType;
}

26
epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/RemoveBindFormDTO.java

@ -0,0 +1,26 @@
package com.epmet.dto.form;
import com.epmet.commons.tools.validator.group.CustomerClientShowGroup;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
/**
* @Author zxc
* @CreateTime 2020/7/23 9:09
*/
@Data
public class RemoveBindFormDTO implements Serializable {
private static final long serialVersionUID = 1920195626466407047L;
public interface RemoveBind extends CustomerClientShowGroup {}
/**
* 客户端类型 resi居民端 work工作端
*/
@NotBlank(message = "客户端类型不能为空",groups = {RemoveBindFormDTO.RemoveBind.class})
private String clientType;
}

2
epmet-module/epmet-third/epmet-third-server/deploy/docker-compose-dev.yml

@ -2,7 +2,7 @@ version: "3.7"
services:
epmet-third-server:
container_name: epmet-third-server-dev
image: 192.168.1.130:10080/epmet-cloud-dev/epmet-third-server:0.0.56
image: 192.168.1.130:10080/epmet-cloud-dev/epmet-third-server:0.0.57
ports:
- "8110:8110"
network_mode: host # 使用现有网络

2
epmet-module/epmet-third/epmet-third-server/pom.xml

@ -2,7 +2,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<version>0.0.56</version>
<version>0.0.57</version>
<parent>
<groupId>com.epmet</groupId>

27
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/AppLetAuthorizationController.java

@ -5,6 +5,8 @@ import com.epmet.commons.tools.security.dto.TokenDto;
import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.dto.form.GoToAuthFormDTO;
import com.epmet.dto.form.OpenAppIdFormDTO;
import com.epmet.dto.form.RemoveBindFormDTO;
import com.epmet.dto.result.GoToAuthResultDTO;
import com.epmet.service.AppLetAuthorizationService;
import org.springframework.beans.factory.annotation.Autowired;
@ -36,4 +38,29 @@ public class AppLetAuthorizationController {
return new Result().ok(goToAuthResultDTO);
}
/**
* @Description 将公众号/小程序从开放平台帐号下解绑
* @param tokenDto
* @param formDTO
* @author zxc
*/
@PostMapping("removeBind")
public Result removeBind(@LoginUser TokenDto tokenDto , @RequestBody RemoveBindFormDTO formDTO){
ValidatorUtils.validateEntity(formDTO,RemoveBindFormDTO.RemoveBind.class);
appLetAuthorizationService.removeBind(tokenDto,formDTO);
return new Result();
}
/**
* @Description 查看小程序绑定的开放平台账号
* @param tokenDto
* @param formDTO
* @author zxc
*/
@PostMapping("getopenappidbyauthappid")
public Result<String> getOpenAppId(@LoginUser TokenDto tokenDto , @RequestBody OpenAppIdFormDTO formDTO){
String openAppId = appLetAuthorizationService.getOpenAppId(tokenDto, formDTO);
return new Result<String>().ok(openAppId);
}
}

9
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/BindingAccountDao.java

@ -21,6 +21,7 @@ import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.dto.form.BindingAccountFormDTO;
import com.epmet.entity.BindingAccountEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* 公众号/小程序绑定开放平台帐号表
@ -37,5 +38,13 @@ public interface BindingAccountDao extends BaseDao<BindingAccountEntity> {
* @author zxc
*/
void insertBindingAccount(BindingAccountFormDTO formDTO);
/**
* @Description 更新绑定状态
* @param customerId
* @param authAppId
* @author zxc
*/
void updateBindStatus(@Param("customerId")String customerId,@Param("authAppId")String authAppId);
}

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

@ -58,7 +58,7 @@ public interface CustomerMpDao extends BaseDao<CustomerMpEntity> {
* @param customerId
* @author zxc
*/
List<String> selectAuthCount(@Param("customerId")String customerId);
Integer selectAuthCount(@Param("customerId")String customerId);
/**
* @Description 回填customer_mp的appId
@ -115,4 +115,12 @@ public interface CustomerMpDao extends BaseDao<CustomerMpEntity> {
* @author zxc
*/
Integer checkBind(String authAppId,String clientType);
/**
* @Description 根据客户Id和客户端类型查询AppId
* @param customerId
* @param clientType
* @author zxc
*/
String getAppId(@Param("customerId")String customerId,@Param("clientType")String clientType);
}

11
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/redis/RedisThird.java

@ -126,4 +126,15 @@ public class RedisThird {
redisUtils.hMSet(key, map,NOT_EXPIRE);
}
/**
* @Description 获取授权信息
* @param customerId
* @param clientType
* @author zxc
*/
public Map<String,Object> getAuthInfo(String customerId,String clientType){
String key = ThirdRedisKeyConstant.AUTH_INFO_REDIS_KEY + customerId + ThirdRedisKeyConstant.COLON + clientType;
return redisUtils.hGetAll(key);
}
}

18
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/AppLetAuthorizationService.java

@ -2,6 +2,8 @@ package com.epmet.service;
import com.epmet.commons.tools.security.dto.TokenDto;
import com.epmet.dto.form.GoToAuthFormDTO;
import com.epmet.dto.form.OpenAppIdFormDTO;
import com.epmet.dto.form.RemoveBindFormDTO;
import com.epmet.dto.result.GoToAuthResultDTO;
/**
@ -17,4 +19,20 @@ public interface AppLetAuthorizationService {
*/
GoToAuthResultDTO goToAuth(TokenDto tokenDto, GoToAuthFormDTO formDTO);
/**
* @Description 将公众号/小程序从开放平台帐号下解绑
* @param tokenDto
* @param formDTO
* @author zxc
*/
void removeBind(TokenDto tokenDto, RemoveBindFormDTO formDTO);
/**
* @Description 查看小程序绑定的开放平台账号
* @param tokenDto
* @param formDTO
* @author zxc
*/
String getOpenAppId(TokenDto tokenDto, OpenAppIdFormDTO formDTO);
}

78
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/AppLetAuthorizationServiceImpl.java

@ -1,9 +1,22 @@
package com.epmet.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.security.dto.TokenDto;
import com.epmet.commons.tools.utils.HttpClientManager;
import com.epmet.constant.ModuleConstant;
import com.epmet.dao.BindingAccountDao;
import com.epmet.dao.CustomerMpDao;
import com.epmet.dao.OpenPlatformAccountDao;
import com.epmet.dao.PaCustomerAgencyDao;
import com.epmet.dto.form.GoToAuthFormDTO;
import com.epmet.dto.form.OpenAppIdFormDTO;
import com.epmet.dto.form.RemoveBindFormDTO;
import com.epmet.dto.result.AuthorizationInfoResultDTO;
import com.epmet.dto.result.GoToAuthResultDTO;
import com.epmet.redis.RedisThird;
import com.epmet.service.AppLetAuthorizationService;
import com.epmet.service.ComponentVerifyTicketService;
import com.epmet.wxapi.constant.WxMaCodeConstant;
@ -12,6 +25,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.Map;
/**
* @Author zxc
* @CreateTime 2020/7/10 15:52
@ -24,6 +39,17 @@ public class AppLetAuthorizationServiceImpl implements AppLetAuthorizationServic
private PaCustomerAgencyDao paCustomerAgencyDao;
@Autowired
private ComponentVerifyTicketService componentVerifyTicketService;
@Autowired
private ComponentVerifyTicketServiceImpl componentVerifyTicketServiceImpl;
@Autowired
private OpenPlatformAccountDao openPlatformAccountDao;
@Autowired
private CustomerMpDao customerMpDao;
@Autowired
private RedisThird redisThird;
@Autowired
private BindingAccountDao bindingAccountDao;
@Value("${third.platform.appId}")
private String componentAppId;
@ -44,4 +70,56 @@ public class AppLetAuthorizationServiceImpl implements AppLetAuthorizationServic
result.setUrl(authUrl);
return result;
}
/**
* @Description 将公众号/小程序从开放平台帐号下解绑
* @param tokenDto
* @param formDTO
* @author zxc
*/
@Override
public void removeBind(TokenDto tokenDto, RemoveBindFormDTO formDTO) {
String customerId = componentVerifyTicketServiceImpl.getLoginUserCustomerId(tokenDto);
String clientType = formDTO.getClientType();
//查询openAppId
String openAppId = openPlatformAccountDao.selectOpenAppIdByCustomerId(customerId);
//查询appId
String authAppId = customerMpDao.getAppId(customerId, clientType);
Map<String, Object> authInfo = redisThird.getAuthInfo(customerId, clientType);
AuthorizationInfoResultDTO authorizationInfo = componentVerifyTicketServiceImpl.mapToEntity(authInfo, AuthorizationInfoResultDTO.class);
JSONObject jsonObject = new JSONObject();
jsonObject.put(ModuleConstant.LOW_APP_ID,authAppId);
jsonObject.put(ModuleConstant.OPEN_APP_ID,openAppId);
String data = HttpClientManager.getInstance().sendPostByJSON(WxMaCodeConstant.UN_BIND + authorizationInfo.getAuthorizer_access_token(), JSON.toJSONString(jsonObject)).getData();
Map<String,String> map = JSON.parseObject(data, Map.class);
if (!map.get(ModuleConstant.ERR_CODE).equals(NumConstant.ZERO_STR)){
log.error("解绑失败" + data);
throw new RenException("解绑失败" + data);
}
bindingAccountDao.updateBindStatus(customerId,authAppId);
}
/**
* @Description 查看小程序绑定的开放平台账号
* @param tokenDto
* @param formDTO
* @author zxc
*/
@Override
public String getOpenAppId(TokenDto tokenDto, OpenAppIdFormDTO formDTO) {
String customerId = componentVerifyTicketServiceImpl.getLoginUserCustomerId(tokenDto);
String clientType = formDTO.getClientType();
String authAppId = customerMpDao.getAppId(customerId, clientType);
Map<String, Object> authInfo = redisThird.getAuthInfo(customerId, clientType);
AuthorizationInfoResultDTO authorizationInfo = componentVerifyTicketServiceImpl.mapToEntity(authInfo, AuthorizationInfoResultDTO.class);
JSONObject jsonObject = new JSONObject();
jsonObject.put(ModuleConstant.LOW_APP_ID,authAppId);
String data = HttpClientManager.getInstance().sendPostByJSON(WxMaCodeConstant.UN_BIND + authorizationInfo.getAuthorizer_access_token(), JSON.toJSONString(jsonObject)).getData();
Map map = JSON.parseObject(data, Map.class);
if (map.containsKey(ModuleConstant.OPEN_APP_ID)){
return map.get(ModuleConstant.OPEN_APP_ID).toString();
}
return map.get(ModuleConstant.ERR_MSG).toString();
}
}

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

@ -525,12 +525,12 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
boolean bindStatus = bindInfo.containsKey(ModuleConstant.OPEN_APP_ID);
if (bindStatus != true) {
log.info(CREATE_AND_BIND_SUCCESS);
List<String> authCount = customerMpDao.selectAuthCount(customerId);
Integer authCount = customerMpDao.selectAuthCount(customerId);
String openPlatformId = null;
if (authCount.size() > 0) {
if (authCount > 0) {
openPlatformId = openPlatformAccountDao.selectOpenAppIdByCustomerId(customerId);
}
if (authCount.size() == NumConstant.ZERO) {
if (authCount == NumConstant.ZERO) {
log.info("未查询到该客户授权信息,先创建开放平台账号,再绑定");
//没有任何一个小程序/公众号授权,【先创建,再绑定】
JSONObject jsonObject = new JSONObject();
@ -560,7 +560,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
case ModuleConstant.EIGHTY_NINE_THOUSAND:
throw new RenException(ACCOUNT_HAS_BOUND_OPEN);
}
} else if (authCount.size() > NumConstant.ZERO && !authCount.contains(authAppId)) {
} else if (authCount > NumConstant.ZERO) {
log.info("该客户已创建过开放平台账号,直接绑定");
JSONObject jsonObject = new JSONObject();
jsonObject.put(ModuleConstant.LOW_APP_ID, authAppId);

10
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/wxapi/constant/WxMaCodeConstant.java

@ -56,6 +56,16 @@ public interface WxMaCodeConstant {
*/
String API_BIND_OPEN = "https://api.weixin.qq.com/cgi-bin/open/bind?access_token=";
/**
*公众号/小程序从开放平台帐号下解绑
*/
String UN_BIND = "https://api.weixin.qq.com/cgi-bin/open/unbind?access_token=";
/**
* 获取公众号/小程序所绑定的开放平台帐号
*/
String OPEN_GET = "https://api.weixin.qq.com/cgi-bin/open/get?access_token=";
/**
* 获取授权方的帐号基本信息
*/

9
epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/BindingAccountDao.xml

@ -21,4 +21,13 @@
NOW()
)
</insert>
<!-- 更新绑定状态 -->
<update id="updateBindStatus">
UPDATE binding_account
SET del_flag = 1
WHERE
customer_id = #{customerId}
AND client_type = #{clientType}
</update>
</mapper>

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

@ -19,15 +19,14 @@
client ASC
</select>
<!-- 查询授权的数量 -->
<select id="selectAuthCount" resultType="java.lang.String">
<select id="selectAuthCount" resultType="java.lang.Integer">
SELECT
app_id AS authAppId
FROM
customer_mp
open_platform_account
WHERE
del_flag = '0'
del_flag = 0
AND customer_id = #{customerId}
AND authorization_flag = 1
</select>
<!-- 回填customer_mp的appId -->
@ -127,4 +126,16 @@
AND client != #{clientType}
</select>
<!-- 根据客户Id和客户端类型查询AppId -->
<select id="getAppId" resultType="java.lang.String">
SELECT
app_id AS appId
FROM
customer_mp
WHERE
del_flag = 0
AND customer_id = #{customerId}
AND client_type = #{clientType}
</select>
</mapper>
Loading…
Cancel
Save