Browse Source

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

master
zxc 5 years ago
parent
commit
ed46fa0bbe
  1. 20
      epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/OpenAppIdFormDTO.java
  2. 26
      epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/RemoveBindFormDTO.java
  3. 27
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/AppLetAuthorizationController.java
  4. 9
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/BindingAccountDao.java
  5. 10
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/CustomerMpDao.java
  6. 11
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/redis/RedisThird.java
  7. 18
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/AppLetAuthorizationService.java
  8. 78
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/AppLetAuthorizationServiceImpl.java
  9. 8
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java
  10. 10
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/wxapi/constant/WxMaCodeConstant.java
  11. 9
      epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/BindingAccountDao.xml
  12. 19
      epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/CustomerMpDao.xml

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;
}

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