Skip to content

Commit

Permalink
Merge pull request #50 from lianluoyi/dev
Browse files Browse the repository at this point in the history
V1.36.1.2版本更新
  • Loading branch information
lianluoyi committed Jun 4, 2024
2 parents 4556389 + 9a7d1ee commit da543d9
Show file tree
Hide file tree
Showing 31 changed files with 344 additions and 90 deletions.
5 changes: 5 additions & 0 deletions easyink-admin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@


<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--普罗米修斯 begin-->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
package com.easyink.web.controller.openapi;


import com.easyink.wecom.domain.WeCustomer;
import com.easyink.wecom.openapi.aop.ValidateSign;
import com.easyink.wecom.openapi.domain.resp.BaseOpenApiResp;
import com.easyink.wecom.openapi.domain.vo.GetWeCustomerByUnionIdVO;
import com.easyink.wecom.openapi.dto.GetWeCustomerByUnionIdDTO;
import com.easyink.wecom.openapi.service.AppIdInfoService;
import com.easyink.wecom.service.WeCustomerService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
* 类名: 对外开放的api接口
Expand All @@ -14,7 +23,31 @@
@RestController
@RequestMapping("/open_api")
@Api(tags = {"对外开放的api接口"})
@AllArgsConstructor
public class OpenApiController {

private final AppIdInfoService appIdInfoService;
private final WeCustomerService weChatCustomerService;


@GetMapping("/getTicket")
@ApiOperation("获取票据")
public BaseOpenApiResp<String> getTicket(String appId, String appSecret) {
return BaseOpenApiResp.success(appIdInfoService.getTicket(appId, appSecret));
}

@ValidateSign
@PostMapping("/externalcontact/unionid_to_external_userid")
@ApiOperation("根据unionId获取联系人externalUserid")
public BaseOpenApiResp<GetWeCustomerByUnionIdVO> unionIdToExternalUserid(@Validated @RequestBody GetWeCustomerByUnionIdDTO dto) {
WeCustomer weCustomer = weChatCustomerService.getCustomerByUnionId(dto);
GetWeCustomerByUnionIdVO vo = new GetWeCustomerByUnionIdVO();
if (weCustomer != null) {
vo.initByWeCustomer(weCustomer);
}
return BaseOpenApiResp.success(vo);
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,10 @@ public AjaxResult<List<WeEmplyCodeScopeUserVO>> getUserByEmplyCode(@PathVariable
public AjaxResult getCodeAppLink(@ApiParam("活码id")Long id ) {
return AjaxResult.success("success",weEmpleCodeService.getCodeAppLink(id));
}
@PostMapping("/refresh/code")
@ApiOperation("刷新活码")
public AjaxResult refreshCode(@RequestBody @ApiParam("活码id")List<Long> ids ) {
weEmpleCodeService.refreshCode(ids);
return AjaxResult.success("success");
}
}
1 change: 1 addition & 0 deletions easyink-admin/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ ruoyi:
- /url
- /wecom/transferData/**
- /actuator/**
- /open_api/**


# 开发环境配置
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.easyink.common.exception.openapi;

/**
* 类名: App_id生成异常
*
* @author : silver_chariot
* @date : 2022/3/14 11:31
*/
public class AppGenException extends RuntimeException {
private static final long serialVersionUID = 1L;

public AppGenException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.easyink.common.exception.openapi;

/**
* 类名: openApi异常
*
* @author : silver_chariot
* @date : 2022/3/15 10:54
*/
public class OpenApiException extends RuntimeException {

private static final long serialVersionUID = 1L;

public OpenApiException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.easyink.common.exception.openapi;

/**
* 类名: 校验签名异常
*
* @author : silver_chariot
* @date : 2022/3/14 18:05
*/
public class SignValidateException extends OpenApiException {
private static final long serialVersionUID = 1L;

public SignValidateException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.easyink.framework.web.exception;

import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONUtil;
import com.dtflys.forest.exceptions.ForestRuntimeException;
import com.easyink.common.constant.WeConstans;
Expand All @@ -10,6 +9,7 @@
import com.easyink.common.exception.BaseException;
import com.easyink.common.exception.CustomException;
import com.easyink.common.exception.file.NoFileException;
import com.easyink.common.exception.openapi.OpenApiException;
import com.easyink.common.utils.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.poi.ss.formula.functions.T;
Expand Down Expand Up @@ -71,6 +71,16 @@ public AjaxResult<T> businessException(CustomException e) {
return AjaxResult.error(errCode, errTipMsg);
}


@ExceptionHandler(OpenApiException.class)
public AjaxResult<T> businessException(OpenApiException e, HttpServletResponse response) {
String errTipMsg = e.getMessage();
Integer errCode = ResultTip.TIP_GENERAL_BAD_REQUEST.getCode();
return AjaxResult.error(errCode, errTipMsg);
}



@ExceptionHandler(NoHandlerFoundException.class)
public AjaxResult<T> handlerNoFoundException(Exception e) {
log.error(e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class WeCategory extends BaseEntity {


@ApiModelProperty(value = "是否启用到侧边栏(0否,1是)")
@TableField("using")
@TableField("use_flag")
private Boolean using;

@ApiModelProperty(value = "分类名称", required = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class WeEmpleCodeAnalyse {
private String externalUserId;

@ApiModelProperty(value = "添加时间")
@TableField("time")
@TableField("add_code_time")
private Date time;

@ApiModelProperty(value = "1:新增,0:流失")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class WeEmpleCodeStatistic implements Serializable {
private Integer lossCustomerCnt;

@ApiModelProperty("日期")
@TableField("time")
@TableField("statistics_time")
private String time;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,12 @@ public interface WeEmpleCodeMapper extends BaseMapper<WeEmpleCode> {
* @return 结果
*/
Integer removeAssistantByLinkId(@Param("linkId") String linkId, @Param("corpId") String corpId);

/**
* 查询需要处理的部门活码id列表
* @return id列表
*/
List<Long> selectDepartTypeEmpleCodeIdList();


}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.easyink.wecom.openapi.aop;


import com.easyink.common.exception.openapi.SignValidateException;
import com.easyink.common.utils.ServletUtils;
import com.easyink.wecom.openapi.constant.AppInfoConst;
import com.easyink.wecom.openapi.domain.entity.AppIdInfo;
import com.easyink.wecom.openapi.exception.SignValidateException;
import com.easyink.wecom.openapi.util.AppGenUtil;
import com.easyink.wecom.openapi.util.AppIdCache;
import com.easyink.wecom.openapi.util.AppInfoRedisClient;
Expand All @@ -17,7 +17,6 @@
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.ServletRequestUtils;

import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.NotNull;
Expand All @@ -33,9 +32,11 @@
@Component
public class ValidateSignAop {
private final AppInfoRedisClient appInfoRedisClient;
private final AppIdCache appIdCache;

public ValidateSignAop(@NotNull AppInfoRedisClient appInfoRedisClient) {
public ValidateSignAop(@NotNull AppInfoRedisClient appInfoRedisClient, AppIdCache appIdCache) {
this.appInfoRedisClient = appInfoRedisClient;
this.appIdCache = appIdCache;
}

@Pointcut("@annotation(com.easyink.wecom.openapi.aop.ValidateSign)")
Expand Down Expand Up @@ -162,7 +163,7 @@ private String validateAppId(String appId) {
if (StringUtils.isBlank(appId)) {
throw new SignValidateException("appId cannot be null");
}
AppIdInfo appIdInfo = AppIdCache.INSTANCE.get(appId);
AppIdInfo appIdInfo = appIdCache.get(appId);
if (appIdInfo == null || StringUtils.isBlank(appIdInfo.getAppSecret())) {
throw new SignValidateException("invalid appId");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.easyink.wecom.openapi.domain.vo;

import com.easyink.wecom.domain.WeCustomer;
import lombok.Data;

/**
* open_api根据unionId获取externalUserId的响应
*
* @author : limeizi
* @date : 2024/2/4 14:26
*/
@Data
public class GetWeCustomerByUnionIdVO {

/**
* 外部联系人id
*/
private String externalUserid;

/**
* 客户昵称
*/
private String name;

/**
* 客户头像
*/
private String avatar;

/**
* 客户性别
*/
private Integer gender;

public void initByWeCustomer(WeCustomer weCustomer) {
this.setExternalUserid(weCustomer.getExternalUserid());
this.setAvatar(weCustomer.getAvatar());
this.setName(weCustomer.getName());
this.setGender(Integer.valueOf(weCustomer.getGender()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.easyink.wecom.openapi.dto;

import lombok.Data;
import org.springframework.validation.annotation.Validated;

import javax.validation.constraints.NotBlank;

/**
* open_api根据unionId获取externalUserId的请求参数
*
* @author : limeizi
* @date : 2024/2/4 17:36
*/
@Data
@Validated
public class GetWeCustomerByUnionIdDTO {

/**
* 外部联系人在微信开放平台的唯一身份标识,通过此字段企业可将外部联系人与公众号/小程序用户关联起来。
*/
@NotBlank(message = "unionId不能为空")
private String unionId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@


import com.easyink.common.exception.CustomException;
import com.easyink.common.exception.openapi.OpenApiException;
import com.easyink.wecom.openapi.dao.AppIdInfoMapper;
import com.easyink.wecom.openapi.domain.entity.AppIdInfo;
import com.easyink.wecom.openapi.domain.vo.AppIdGenVO;
import com.easyink.wecom.openapi.exception.OpenApiException;
import com.easyink.wecom.openapi.service.AppIdInfoService;
import com.easyink.wecom.openapi.util.AppGenUtil;
import com.easyink.wecom.openapi.util.AppIdCache;
Expand All @@ -29,10 +29,12 @@ public class AppIdInfoServiceImpl implements AppIdInfoService {

private final AppIdInfoMapper appIdInfoMapper;
private final AppInfoRedisClient appInfoRedisClient;
private final AppIdCache appIdCache;

public AppIdInfoServiceImpl(@NotNull AppIdInfoMapper appIdInfoMapper, AppInfoRedisClient appInfoRedisClient) {
public AppIdInfoServiceImpl(@NotNull AppIdInfoMapper appIdInfoMapper, AppInfoRedisClient appInfoRedisClient, AppIdCache appIdCache) {
this.appIdInfoMapper = appIdInfoMapper;
this.appInfoRedisClient = appInfoRedisClient;
this.appIdCache = appIdCache;
}


Expand Down Expand Up @@ -73,7 +75,7 @@ public AppIdGenVO create(String corpId) {
if (res == 0) {
throw new CustomException("获取开发配置异常");
}
AppIdCache.INSTANCE.put(appId, appIdInfo);
appIdCache.put(appId, appIdInfo);
return new AppIdGenVO(appIdInfo);
}

Expand All @@ -95,7 +97,7 @@ public AppIdGenVO refreshSecret(String corpId) {
if (res == 0) {
throw new CustomException("重置失败");
}
AppIdCache.INSTANCE.put(appId, appIdInfo);
appIdCache.put(appId, appIdInfo);
return new AppIdGenVO(appIdInfo);
}

Expand All @@ -105,7 +107,7 @@ public String getTicket(String appId, String appSecret) {
throw new OpenApiException("param missing");
}
// 判断appId是否存在
AppIdInfo appIdInfo = AppIdCache.INSTANCE.get(appId);
AppIdInfo appIdInfo = appIdCache.get(appId);
if (appIdInfo == null) {
throw new OpenApiException("invalid appId");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.easyink.wecom.openapi.util;

import com.easyink.wecom.openapi.exception.AppGenException;
import com.easyink.common.exception.openapi.AppGenException;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.easyink.wecom.openapi.domain.entity.AppIdInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;
Expand All @@ -18,11 +19,9 @@
* @date : 2022/3/14 14:24
*/
@Slf4j
public enum AppIdCache {
/**
* 缓存单例
*/
INSTANCE;
@Component
public class AppIdCache {

/**
* app开发设置缓存
*/
Expand Down
Loading

0 comments on commit da543d9

Please sign in to comment.