企微配置相关接口提交

1 parent c0624ada
......@@ -89,6 +89,8 @@
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
......
......@@ -135,76 +135,76 @@ public class SysLoginController
return AjaxResult.success(menuService.buildMenus(menus));
}
/**
* 获取企业扫码登录相关参数
* @return
*/
@GetMapping("/findWxQrLoginInfo")
public AjaxResult findQrLoginParm(){
WeCorpAccount validWeCorpAccount
= iWxCorpAccountService.findValidWeCorpAccount();
if(null != validWeCorpAccount){
validWeCorpAccount.setContactSecret(null);
validWeCorpAccount.setCorpSecret(null);
validWeCorpAccount.setProviderSecret(null);
}
return AjaxResult.success(validWeCorpAccount);
}
/**
* 扫码登录微信端回调
* @param auth_code 授权code
* @param agentId 应用id
* @return
*/
@GetMapping("/wxQrLogin")
public AjaxResult wxQrLogin(String auth_code, String agentId){
AjaxResult ajax = AjaxResult.success();
WeUserInfoDto userInfo = weUserClient.getUserInfo(auth_code, agentId);
if( null != userInfo){
SysUser sysUser = sysUserService.selectUserByCorpUserId(userInfo.getUserId());
if (null != sysUser){
String token = loginService.noPwdLogin(sysUser.getUserName());
ajax.put(Constants.TOKEN, token);
}else {
return AjaxResult.error("请绑定后再登录");
}
}
return ajax;
}
/**
* 通过企业id和企业密钥登录
* @param corpId
* @param corpSecret
* @return
*/
@GetMapping("/corpLogin")
public AjaxResult corpLogin(String corpId,String corpSecret){
WeCorpAccount weCorpAccount = iWxCorpAccountService.getOne(new LambdaQueryWrapper<WeCorpAccount>()
.eq(WeCorpAccount::getCorpId, corpId)
.eq(WeCorpAccount::getCorpSecret, corpSecret)
.eq(WeCorpAccount::getDelFlag, Constants.NORMAL_CODE));
if(weCorpAccount == null){
return AjaxResult.error("当前企业id与企业密码不匹配或不存在");
}
return AjaxResult.success(
loginService.noPwdLogin(weCorpAccount.getCorpAccount())
);
}
// /**
// * 获取企业扫码登录相关参数
// * @return
// */
// @GetMapping("/findWxQrLoginInfo")
// public AjaxResult findQrLoginParm(){
//
// WeCorpAccount validWeCorpAccount
// = iWxCorpAccountService.findValidWeCorpAccount();
// if(null != validWeCorpAccount){
// validWeCorpAccount.setContactSecret(null);
// validWeCorpAccount.setCorpSecret(null);
// validWeCorpAccount.setProviderSecret(null);
// }
//
// return AjaxResult.success(validWeCorpAccount);
// }
// /**
// * 扫码登录微信端回调
// * @param auth_code 授权code
// * @param agentId 应用id
// * @return
// */
// @GetMapping("/wxQrLogin")
// public AjaxResult wxQrLogin(String auth_code, String agentId){
//
// AjaxResult ajax = AjaxResult.success();
//
// WeUserInfoDto userInfo = weUserClient.getUserInfo(auth_code, agentId);
// if( null != userInfo){
// SysUser sysUser = sysUserService.selectUserByCorpUserId(userInfo.getUserId());
// if (null != sysUser){
// String token = loginService.noPwdLogin(sysUser.getUserName());
// ajax.put(Constants.TOKEN, token);
// }else {
// return AjaxResult.error("请绑定后再登录");
// }
// }
// return ajax;
// }
// /**
// * 通过企业id和企业密钥登录
// * @param corpId
// * @param corpSecret
// * @return
// */
// @GetMapping("/corpLogin")
// public AjaxResult corpLogin(String corpId,String corpSecret){
//
// WeCorpAccount weCorpAccount = iWxCorpAccountService.getOne(new LambdaQueryWrapper<WeCorpAccount>()
// .eq(WeCorpAccount::getCorpId, corpId)
// .eq(WeCorpAccount::getCorpSecret, corpSecret)
// .eq(WeCorpAccount::getDelFlag, Constants.NORMAL_CODE));
//
//
// if(weCorpAccount == null){
//
// return AjaxResult.error("当前企业id与企业密码不匹配或不存在");
// }
//
// return AjaxResult.success(
// loginService.noPwdLogin(weCorpAccount.getCorpAccount())
// );
// }
}
package com.linkwechat.web.controller.wecom;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.wecom.domain.WeApp;
import com.linkwechat.wecom.service.IWeAppService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/wecom/weapp")
public class WeAppController extends BaseController {
@Autowired
IWeAppService iWeAppService;
@GetMapping("/list")
public AjaxResult list() {
return AjaxResult.success(
iWeAppService.list()
);
}
@PostMapping("/addWeApp")
public AjaxResult addWeApp(@RequestBody WeApp weApp){
iWeAppService.addWeApp(weApp);
return AjaxResult.success();
}
@PutMapping("/updateWeApp")
public AjaxResult updateWeApp(@RequestBody WeApp weApp){
iWeAppService.updateWeApp(weApp);
return AjaxResult.success();
}
}
package com.linkwechat.web.controller.wecom;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.constant.Constants;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.domain.entity.WeCorpAccount;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.wecom.service.IWeCorpAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 企业id相关配置Controller
*
* @author ruoyi
* @date 2020-08-24
*/
@RestController
@RequestMapping("/wecom/corp")
@Api("企业id配置接口")
public class WeCorpAccountController extends BaseController
{
@RequestMapping(value = "/wecom/corp")
public class WeCorpAccountController {
@Autowired
private IWeCorpAccountService weCorpAccountService;
private IWeCorpAccountService iWeCorpAccountService;
// @PreAuthorize("@ss.hasPermi('wechat:corp:list')")
@GetMapping("/list")
@ApiOperation("查询企业id相关配置列表")
public TableDataInfo list(WeCorpAccount weCorpAccount)
{
startPage();
List<WeCorpAccount> list = weCorpAccountService.list(new LambdaQueryWrapper<WeCorpAccount>()
.eq(WeCorpAccount::getDelFlag,Constants.NORMAL_CODE)
.like(WeCorpAccount::getCompanyName,weCorpAccount.getCompanyName()));
return getDataTable(list);
}
/**
* 获取当前企业可用密钥
* @return
*/
@GetMapping("/findCurrentCorpAccount")
public AjaxResult findCurrentCorpAccount(){
// @PreAuthorize("@ss.hasPermi('wechat:corp:add')")
@Log(title = "新增企业id相关配置", businessType = BusinessType.INSERT)
@PostMapping
@ApiOperation("新增企业id相关配置")
public AjaxResult add(@Validated @RequestBody WeCorpAccount weCorpAccount)
{
weCorpAccountService.save(weCorpAccount);
return AjaxResult.success();
}
// @PreAuthorize("@ss.hasPermi('wechat:corp:edit')")
@Log(title = "修改企业id相关配置", businessType = BusinessType.UPDATE)
@PutMapping
@ApiOperation("修改企业id相关配置")
public AjaxResult edit(@Validated @RequestBody WeCorpAccount weCorpAccount)
{
weCorpAccountService.updateById(weCorpAccount);
return AjaxResult.success();
return AjaxResult.success(
iWeCorpAccountService.findValidWeCorpAccount()
);
}
// @PreAuthorize("@ss.hasPermi('wechat:corp:startVailWeCorpAccount')")
@Log(title = "启用有效企业微信账号", businessType = BusinessType.DELETE)
@PutMapping("/startVailWeCorpAccount/{corpId}")
@ApiOperation("启用有效企业微信账号")
public AjaxResult startWeCorpAccount(@PathVariable String corpId)
/**
* 新增或更新企业配置相关
* @param weCorpAccount
* @return
*/
@Log(title = "新增或更新企业配置相关", businessType = BusinessType.INSERT)
@PostMapping("/addOrUpdate")
public AjaxResult addOrUpdate(@RequestBody WeCorpAccount weCorpAccount)
{
return toAjax(weCorpAccountService.startVailWeCorpAccount(corpId));
iWeCorpAccountService.saveOrUpdate(weCorpAccount);
return AjaxResult.success();
}
// @PreAuthorize("@ss.hasPermi('wechat:corp:startCustomerChurnNoticeSwitch')")
/**
* 客户流失通知开关
* @param status
* @return
*/
@Log(title = "客户流失通知开关", businessType = BusinessType.UPDATE)
@PutMapping("/startCustomerChurnNoticeSwitch/{status}")
@ApiOperation("客户流失通知开关")
public AjaxResult startCustomerChurnNoticeSwitch(@PathVariable String status)
{
weCorpAccountService.startCustomerChurnNoticeSwitch(status);
iWeCorpAccountService.startCustomerChurnNoticeSwitch(status);
return AjaxResult.success();
}
// @PreAuthorize("@ss.hasPermi('wechat:corp:getCustomerChurnNoticeSwitch')")
/**
* 客户流失通知开关查询
* @return
*/
@Log(title = "客户流失通知开关查询", businessType = BusinessType.OTHER)
@GetMapping("/getCustomerChurnNoticeSwitch")
@ApiOperation("客户流失通知开关查询")
public AjaxResult getCustomerChurnNoticeSwitch()
{
return AjaxResult.success("操作成功",weCorpAccountService.getCustomerChurnNoticeSwitch());
return AjaxResult.success("操作成功",iWeCorpAccountService.getCustomerChurnNoticeSwitch());
}
}
......@@ -24,7 +24,6 @@ import javax.validation.constraints.NotBlank;
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
@ApiModel("企业id配置相关实体")
@TableName("we_corp_account")
public class WeCorpAccount extends BaseEntity
{
......@@ -32,59 +31,109 @@ public class WeCorpAccount extends BaseEntity
/** $column.columnComment */
@TableId
@ApiModelProperty("主键")
private Long id= SnowFlakeUtil.nextId();
private Long id;
/** 企业名称 */
@ApiModelProperty("企业名称")
@NotBlank(message = "企业名称不能为空")
private String companyName;
/***********************************************
*******************企业配置start****************
**********************************************/
/** 企业ID */
@ApiModelProperty("企业corpId")
@NotBlank(message = "企业ID不能为空")
private String corpId;
/** 应用的密钥凭证 */
@ApiModelProperty("企业为corpSecret")
@NotBlank(message = "应用的密钥凭证不能为空")
/** 企业名称 */
@NotBlank(message = "企业名称不能为空")
private String companyName;
/***********************************************
*******************企业配置end****************
**********************************************/
/***********************************************
*******************通讯录配置start**************
**********************************************/
/** 通讯录Secret */
@NotBlank(message = "通讯录Secret不可为空")
private String corpSecret;
/** 帐号状态(0正常 1停用) */
@ApiModelProperty("帐号状态(0正常 1停用)")
private String status;
/***********************************************
*******************通讯录配置end****************
**********************************************/
/***********************************************
*******************客户联系配置start*************
**********************************************/
@NotBlank(message = "客户联系Secret不可为空")
private String contactSecret;
/***********************************************
*******************客户联系配置end***************
**********************************************/
/***********************************************
*******************应用配置start****************
**********************************************/
/**消息应用ID*/
@NotBlank(message = "消息应用ID不可为空")
private String agentId;
/**消息应用Secret*/
@NotBlank(message = "消息应用Secret不可为空")
private String agentSecret;
/**会话私钥Secret*/
private String chatSecret;
/**会话存档密钥*/
private String financePrivateKey;
/***********************************************
*******************应用配置end****************
**********************************************/
/***********************************************
*******************接收事件服务器start***********
**********************************************/
/**回调url*/
private String backOffUrl;
/** 删除标志(0代表存在 2代表删除) */
@ApiModelProperty("删除标志(0代表存在 2代表删除)")
private String delFlag=new String("0");
/**回调token*/
private String token;
/**回调EncodingAESKey*/
private String encodingAesKey;
@ApiModelProperty("外部联系人密钥")
@NotBlank(message = "外部联系人密钥凭证不能为空")
private String contactSecret;
@ApiModelProperty("应用id")
private String agentId;
/***********************************************
*******************接收事件服务器end*************
**********************************************/
@ApiModelProperty("应用密钥")
private String agentSecret;
@ApiModelProperty("服务商密钥")
private String providerSecret;
@ApiModelProperty("会话存档密钥")
private String chatSecret;
/**客服密钥*/
private String kfSecret;
/** 删除标志(0代表存在 1代表删除) */
private Integer delFlag;
@ApiModelProperty("企业微信扫码登陆回调地址")
private String wxQrLoginRedirectUri;
@ApiModelProperty("客户流失通知开关 0:关闭 1:开启")
private String customerChurnNoticeSwitch = Constants.NORMAL_CODE;
/**客户流失通知开关 0:关闭 1:开启*/
private String customerChurnNoticeSwitch = Constants.NORMAL_CODE;
@ApiModelProperty("会话存档私钥")
private String financePrivateKey;
@ApiModelProperty("企业管理员账号")
private String corpAccount;
}
package com.linkwechat.framework.web.service;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.linkwechat.common.config.RuoYiConfig;
import com.linkwechat.common.constant.Constants;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.core.domain.entity.SysRole;
import com.linkwechat.common.core.domain.entity.SysUser;
import com.linkwechat.common.core.domain.entity.WeCorpAccount;
import com.linkwechat.common.core.domain.model.LoginUser;
import com.linkwechat.common.enums.UserStatus;
import com.linkwechat.common.exception.BaseException;
import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.system.service.ISysRoleService;
import com.linkwechat.system.service.ISysUserService;
......@@ -27,9 +23,6 @@ import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
/**
* 用户验证处理
*
......@@ -73,54 +66,65 @@ public class UserDetailsServiceImpl implements UserDetailsService
if (StringUtils.isNull(user))
{
//查询企业管理相关账号
WeCorpAccount weCorpByAccount = iWeCorpAccountService.getOne(new LambdaQueryWrapper<WeCorpAccount>().eq(WeCorpAccount::getCorpAccount, username)
.eq(WeCorpAccount::getDelFlag, Constants.NORMAL_CODE));
if(null != weCorpByAccount){
//注册到we_user表中
user=SysUser.builder()
.userName(weCorpByAccount.getCorpAccount())
.nickName(weCorpByAccount.getCompanyName())
.userType(Constants.USER_TYOE_CORP_ADMIN)
.roleIds(ArrayUtil.toArray(iSysRoleService.selectRoleList(SysRole.builder()
.roleKey(Constants.DEFAULT_WECOME_CORP_ADMIN)
.build()).stream().map(SysRole::getRoleId).collect(Collectors.toList()), Long.class))
.password(SecurityUtils.encryptPassword(ruoYiConfig.getWeUserDefaultPwd()))
.build();
} else{
//we_user表中去查询,如果该表为空则提示用户不存在,如果不为空,则将用户记录注册到系统用户表中
WeUser weUser=iWeUserService.getOne(new LambdaQueryWrapper<WeUser>()
.eq(WeUser::getMobile,username)
.ne(WeUser::getIsActivate,new Integer(6)));
if(null == weUser){
throw new BaseException("对不起,您的账号:" + username + " 不存在");
}
if(StrUtil.isBlank(weUser.getMobile())){
throw new BaseException("请填写当前企业员工的手机号:" + username + " 然后再登录");
}
//注册到we_user表中
user=SysUser.builder()
.userName(username)
.nickName(weUser.getName())
.userType(Constants.USER_TYPE_WECOME)
.email(weUser.getEmail())
.phonenumber(weUser.getMobile())
.sex(weUser.getGender() ==0 ? "1": weUser.getGender() .toString())
.avatar(weUser.getHeadImageUrl())
.weUserId(weUser.getUserId())
.roleIds(ArrayUtil.toArray(iSysRoleService.selectRoleList(SysRole.builder()
.roleKey(Constants.DEFAULT_WECOME_ROLE_KEY)
.build()).stream().map(SysRole::getRoleId).collect(Collectors.toList()), Long.class))
.password(SecurityUtils.encryptPassword(ruoYiConfig.getWeUserDefaultPwd()))
.build();
}
if(user != null){
userService.insertUser(
user
);
//we_user表中去查询,如果该表为空则提示用户不存在,如果不为空,则将用户记录注册到系统用户表中
WeUser weUser=iWeUserService.getOne(new LambdaQueryWrapper<WeUser>()
.eq(WeUser::getMobile,username)
.ne(WeUser::getIsActivate,new Integer(6)));
if(null == weUser){
throw new BaseException("对不起,您的账号:" + username + " 不存在");
}
// if(StrUtil.isBlank(weUser.getMobile())){
// throw new BaseException("请填写当前企业员工的手机号:" + username + " 然后再登录");
// }
// //查询企业管理相关账号
// WeCorpAccount weCorpByAccount = iWeCorpAccountService.getOne(new LambdaQueryWrapper<WeCorpAccount>().eq(WeCorpAccount::getCorpAccount, username)
// .eq(WeCorpAccount::getDelFlag, Constants.NORMAL_CODE));
// if(null != weCorpByAccount){
// //注册到we_user表中
// user=SysUser.builder()
// .userName(weCorpByAccount.getCorpAccount())
// .nickName(weCorpByAccount.getCompanyName())
// .userType(Constants.USER_TYOE_CORP_ADMIN)
// .roleIds(ArrayUtil.toArray(iSysRoleService.selectRoleList(SysRole.builder()
// .roleKey(Constants.DEFAULT_WECOME_CORP_ADMIN)
// .build()).stream().map(SysRole::getRoleId).collect(Collectors.toList()), Long.class))
// .password(SecurityUtils.encryptPassword(ruoYiConfig.getWeUserDefaultPwd()))
// .build();
// } else{
// //we_user表中去查询,如果该表为空则提示用户不存在,如果不为空,则将用户记录注册到系统用户表中
// WeUser weUser=iWeUserService.getOne(new LambdaQueryWrapper<WeUser>()
// .eq(WeUser::getMobile,username)
// .ne(WeUser::getIsActivate,new Integer(6)));
// if(null == weUser){
// throw new BaseException("对不起,您的账号:" + username + " 不存在");
// }
// if(StrUtil.isBlank(weUser.getMobile())){
// throw new BaseException("请填写当前企业员工的手机号:" + username + " 然后再登录");
// }
// //注册到we_user表中
// user=SysUser.builder()
// .userName(username)
// .nickName(weUser.getName())
// .userType(Constants.USER_TYPE_WECOME)
// .email(weUser.getEmail())
// .phonenumber(weUser.getMobile())
// .sex(weUser.getGender() ==0 ? "1": weUser.getGender() .toString())
// .avatar(weUser.getHeadImageUrl())
// .weUserId(weUser.getUserId())
// .roleIds(ArrayUtil.toArray(iSysRoleService.selectRoleList(SysRole.builder()
// .roleKey(Constants.DEFAULT_WECOME_ROLE_KEY)
// .build()).stream().map(SysRole::getRoleId).collect(Collectors.toList()), Long.class))
// .password(SecurityUtils.encryptPassword(ruoYiConfig.getWeUserDefaultPwd()))
// .build();
//
// }
//
// if(user != null){
// userService.insertUser(
// user
// );
// }
}
else if (UserStatus.DELETED.getCode().equals(user.getDelFlag()))
{
......@@ -134,13 +138,13 @@ public class UserDetailsServiceImpl implements UserDetailsService
}
//当前登录用户为企业管理,设置corpId和密钥相关
if(Constants.USER_TYOE_CORP_ADMIN.equals(user.getUserType())){
user.setWeCorpAccount(
iWeCorpAccountService.getOne(new LambdaQueryWrapper<WeCorpAccount>().eq(WeCorpAccount::getCorpAccount, username)
.eq(WeCorpAccount::getDelFlag, Constants.NORMAL_CODE))
);
}
// //当前登录用户为企业管理,设置corpId和密钥相关
// if(Constants.USER_TYOE_CORP_ADMIN.equals(user.getUserType())){
// user.setWeCorpAccount(
// iWeCorpAccountService.getOne(new LambdaQueryWrapper<WeCorpAccount>().eq(WeCorpAccount::getCorpAccount, username)
// .eq(WeCorpAccount::getDelFlag, Constants.NORMAL_CODE))
// );
// }
return createLoginUser(user);
......
package com.linkwechat.wecom.domain;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.linkwechat.common.utils.SnowFlakeUtil;
import lombok.AllArgsConstructor;
import lombok.experimental.SuperBuilder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
import java.util.List;
/**
* @description: 自建应用相关
* @author: HaoN
* @create: 2021-01-26 18:38
**/
@Data
@TableName("we_app")
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
public class WeApp {
private static final long serialVersionUID = 1L;
/** $column.columnComment */
private Long id= SnowFlakeUtil.nextId();
/**应用id**/
private String agentId;
/**应用密钥**/
private String agentSecret;
/**应用类型(1:自建应用;2:小程序)**/
private Integer appType;
/**应用创建时间**/
private Date createTime;
/**删除标志(0代表存在 2代表删除)**/
private String delFlag;
/**帐号状态(0正常 1停用)**/
private String status;
/**可见范围部门id,使用逗号隔开**/
private String allowPartys;
/**可见范围人员id,使用逗号隔开**/
private String allowUserinfos;
/**应用名称**/
private String agentName;
/**企业应用描述**/
private String description;
/**应用头像**/
private String squareLogoUrl;
@TableField(exist = false)
private String logoMediaid;
}
package com.linkwechat.wecom.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.linkwechat.wecom.domain.WeApp;
/**
* @description: 自建应用相关
* @author: HaoN
* @create: 2021-01-26 18:43
**/
public interface WeAppMapper extends BaseMapper<WeApp> {
}
\ No newline at end of file
......@@ -14,12 +14,6 @@ public interface WeCorpAccountMapper extends BaseMapper<WeCorpAccount>
{
/**
* 启用有效的企业微信账号
* @param corpId
* @return
*/
int startVailWeCorpAccount(@Param("corpId") String corpId);
}
package com.linkwechat.wecom.service;
import com.linkwechat.common.core.domain.entity.WeCorpAccount;
import com.linkwechat.wecom.domain.WeApp;
/**
* @description: 微信token相关接口
......
package com.linkwechat.wecom.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.linkwechat.wecom.domain.WeApp;
/**
* @description:
* @author: HaoN
* @create: 2021-01-26 18:44
**/
public interface IWeAppService extends IService<WeApp> {
void addWeApp(WeApp weApp);
void updateWeApp(WeApp weApp);
}
......@@ -13,13 +13,7 @@ public interface IWeCorpAccountService extends IService<WeCorpAccount>
{
/**
* 修改企业id相关配置
*
* @param wxCorpAccount 企业id相关配置
* @return 结果
*/
void updateWeCorpAccount(WeCorpAccount wxCorpAccount);
......@@ -31,11 +25,7 @@ public interface IWeCorpAccountService extends IService<WeCorpAccount>
WeCorpAccount findValidWeCorpAccount();
/**
* 启用有效的企业微信账号
* @param corpId
*/
int startVailWeCorpAccount(String corpId);
/**
* 客户流失通知开关
......
package com.linkwechat.wecom.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.linkwechat.common.config.RuoYiConfig;
import com.linkwechat.common.constant.Constants;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.core.redis.RedisCache;
import com.linkwechat.common.exception.wecom.WeComException;
import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.wecom.client.WeAccessTokenClient;
import com.linkwechat.wecom.domain.WeApp;
import com.linkwechat.common.core.domain.entity.WeCorpAccount;
import com.linkwechat.wecom.domain.dto.WeAccessTokenDto;
import com.linkwechat.wecom.service.IWeAccessTokenService;
import com.linkwechat.wecom.service.IWeAppService;
import com.linkwechat.wecom.service.IWeCorpAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.concurrent.TimeUnit;
/**
......@@ -40,8 +35,7 @@ public class WeAccessTokenServiceImpl implements IWeAccessTokenService {
private RedisCache redisCache;
@Autowired
private IWeAppService iWeAppService;
@Autowired
......@@ -97,57 +91,33 @@ public class WeAccessTokenServiceImpl implements IWeAccessTokenService {
public String findThirdAppAccessToken() {
WeApp weApp=null;
//首先表中查询提醒的appid
WeCorpAccount weCorpAccount = iWxCorpAccountService.findValidWeCorpAccount();
if(weCorpAccount != null && StringUtils.isNotEmpty(weCorpAccount.getAgentId())){
String token=redisCache.getCacheObject(WeConstans.WE_THIRD_APP_TOKEN+"::"+weCorpAccount.getAgentId());
if(StringUtils.isNotEmpty(token)){
return token;
}else{
weApp=WeApp.builder()
.agentId(weCorpAccount.getAgentId())
.agentSecret(weCorpAccount.getAgentSecret())
.build();
}
if(null == weCorpAccount){
throw new WeComException("无可用的corpid和secret");
}
// if(weCorpAccount.getAgentId().equals(agentId)){
//
// }
if(StringUtils.isEmpty(weCorpAccount.getAgentId())&&StringUtils.isEmpty(weCorpAccount.getAgentSecret())){
throw new WeComException("请确保应用id与应用密钥可用");
}
// if(weApp==null){
// weApp = iWeAppService.getOne(new LambdaQueryWrapper<WeApp>()
// .eq(WeApp::getAgentId, agentId)
// .eq(WeApp::getDelFlag, Constants.NORMAL_CODE)
// .eq(WeApp::getStatus, Constants.NORMAL_CODE));
// }
String token=redisCache.getCacheObject(WeConstans.WE_THIRD_APP_TOKEN+"::"+weCorpAccount.getAgentId());
return findThirdAppAccessToken(weApp);
return StringUtils.isNotEmpty(token)
?token:findThirdAppAccessToken(weCorpAccount);
}
private String findThirdAppAccessToken(WeApp weApp){
if(weApp == null){
throw new WeComException("当前agentId不可用或不存在");
}
private String findThirdAppAccessToken(WeCorpAccount weCorpAccount){
WeCorpAccount wxCorpAccount
= iWxCorpAccountService.findValidWeCorpAccount();
if(wxCorpAccount == null){
throw new WeComException("无可用的corpid和secret");
}
WeAccessTokenDto weAccessTokenDto
= accessTokenClient.getToken(wxCorpAccount.getCorpId(),weApp.getAgentSecret());
= accessTokenClient.getToken(weCorpAccount.getCorpId(),weCorpAccount.getAgentSecret());
if(StringUtils.isNotEmpty(weAccessTokenDto.getAccessToken())){
redisCache.setCacheObject(WeConstans.WE_THIRD_APP_TOKEN+"::"+weApp.getAgentId(), weAccessTokenDto.getAccessToken(), weAccessTokenDto.getExpiresIn().intValue(), TimeUnit.SECONDS);
redisCache.setCacheObject(WeConstans.WE_THIRD_APP_TOKEN+"::"+weCorpAccount.getAgentId(), weAccessTokenDto.getAccessToken(), weAccessTokenDto.getExpiresIn().intValue(), TimeUnit.SECONDS);
}
......
package com.linkwechat.wecom.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linkwechat.common.constant.Constants;
import com.linkwechat.common.exception.wecom.WeComException;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.wecom.client.WeAppClient;
import com.linkwechat.wecom.domain.WeApp;
import com.linkwechat.wecom.domain.dto.WeAppDetailDto;
import com.linkwechat.wecom.mapper.WeAppMapper;
import com.linkwechat.wecom.service.IWeAccessTokenService;
import com.linkwechat.wecom.service.IWeAppService;
import com.linkwechat.wecom.service.IWeDepartmentService;
import com.linkwechat.wecom.service.IWeUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
/**
* @description:
* @author: HaoN
* @create: 2021-01-26 18:44
**/
@Service
public class WeAppServiceImpl extends ServiceImpl<WeAppMapper, WeApp> implements IWeAppService {
@Autowired
WeAppClient weAppClient;
@Autowired
IWeDepartmentService iWeDepartmentService;
@Autowired
IWeUserService iWeUserService;
@Autowired
IWeAccessTokenService iWeAccessTokenService;
/**
* 保存应用
* @param weApp
*/
@Override
@Transactional
public void addWeApp(WeApp weApp) {
if(null !=this.getOne(new LambdaQueryWrapper<WeApp>()
.eq(WeApp::getAgentId, weApp.getAgentId())
.eq(WeApp::getDelFlag, Constants.SUCCESS))){
throw new WeComException("AgentId已经存在");
}
weApp.setCreateTime(new Date());
if(this.save(weApp)){
WeAppDetailDto weAppDetailDto
= weAppClient.findAgentById(weApp.getAgentId());
if(null != weAppDetailDto){
weApp.setAgentName(weAppDetailDto.getName());
weApp.setCreateTime(new Date());
weApp.setSquareLogoUrl(weAppDetailDto.getSquare_logo_url());
weApp.setDescription(weAppDetailDto.getDescription());
weApp.setAllowPartys(StringUtils.join(weAppDetailDto.getAllow_partys().getPartyid(),","));
weApp.setAllowUserinfos(StringUtils.join(weAppDetailDto.getAllow_userinfos().getUser(),","));
this.updateById(weApp);
}
}
}
@Override
@Transactional
public void updateWeApp(WeApp weApp) {
if(this.updateById(weApp)){
weAppClient.updateAgentById(
WeAppDetailDto.builder()
.agentid(weApp.getAgentId())
.logo_mediaid(weApp.getLogoMediaid())
.description(weApp.getDescription())
.name(weApp.getAgentName())
.build(),weApp.getAgentId()
);
}
}
}
......@@ -2,16 +2,12 @@ package com.linkwechat.wecom.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linkwechat.common.config.RuoYiConfig;
import com.linkwechat.common.constant.Constants;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.core.domain.entity.WeCorpAccount;
import com.linkwechat.wecom.mapper.WeCorpAccountMapper;
import com.linkwechat.wecom.service.IWeAccessTokenService;
import com.linkwechat.wecom.service.IWeCorpAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Optional;
/**
......@@ -25,34 +21,11 @@ public class WeCorpAccountServiceImpl extends ServiceImpl<WeCorpAccountMapper,We
@Autowired
private IWeAccessTokenService iWeAccessTokenService;
@Autowired
private RuoYiConfig ruoYiConfig;
/**
* 修改企业id相关配置
*
* @param wxCorpAccount 企业id相关配置
* @return 结果
*/
@Override
public void updateWeCorpAccount(WeCorpAccount wxCorpAccount)
{
if(this.updateById(wxCorpAccount)){
iWeAccessTokenService.removeToken(wxCorpAccount);
}
public WeCorpAccountServiceImpl(){
System.out.println("nihaoya");
}
/**
* 获取有效的企业id
*
......@@ -61,36 +34,20 @@ public class WeCorpAccountServiceImpl extends ServiceImpl<WeCorpAccountMapper,We
@Override
public WeCorpAccount findValidWeCorpAccount() {
return ruoYiConfig.isStartTenant()? WeCorpAccount.builder().build():this.getOne(new LambdaQueryWrapper<WeCorpAccount>()
.eq(WeCorpAccount::getDelFlag,Constants.NORMAL_CODE)
.eq(WeCorpAccount::getStatus,Constants.NORMAL_CODE));
}
/**
* 启用有效的企业微信账号
* @param corpId
*/
@Override
public int startVailWeCorpAccount(String corpId) {
int returnCode = this.baseMapper.startVailWeCorpAccount(corpId);
WeCorpAccount weCorpAccount = this.getOne(new LambdaQueryWrapper<WeCorpAccount>()
.eq(WeCorpAccount::getDelFlag, Constants.NORMAL_CODE));
if(Constants.SERVICE_RETURN_SUCCESS_CODE<returnCode){
iWeAccessTokenService.removeToken(WeCorpAccount.builder().build());
return weCorpAccount!=null?weCorpAccount:WeCorpAccount.builder().build();
}
}
return returnCode;
}
@Override
public void startCustomerChurnNoticeSwitch(String status) {
WeCorpAccount validWeCorpAccount = findValidWeCorpAccount();
validWeCorpAccount.setCustomerChurnNoticeSwitch(status);
this.updateWeCorpAccount(validWeCorpAccount);
this.updateById(validWeCorpAccount);
}
@Override
......
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.linkwechat.wecom.mapper.WeAppMapper">
</mapper>
\ No newline at end of file
......@@ -6,11 +6,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<update id="startVailWeCorpAccount">
UPDATE we_corp_account
SET `status` = (CASE WHEN corp_id = #{corpId} THEN 0 ELSE 1 END)
</update>
......
......@@ -300,6 +300,7 @@
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!