提交 5eeba376 编写于 作者: 1 1539136324@qq.com

优化提取企业微信回调接口所需参数,由配置文件调整至数据库中;

上级 a102c340
package com.linkwechat.web.controller.wecom;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.linkwechat.common.constant.Constants;
import com.linkwechat.common.core.domain.entity.WeCorpAccount;
import com.linkwechat.common.core.domain.model.LoginUser;
import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.common.utils.Threads;
import com.linkwechat.common.utils.wecom.WxCryptUtil;
import com.linkwechat.framework.web.service.SysLoginService;
import com.linkwechat.web.controller.common.CommonController;
import com.linkwechat.wecom.domain.vo.WxCpXmlMessageVO;
import com.linkwechat.wecom.factory.WeCallBackEventFactory;
import com.linkwechat.wecom.factory.WeEventHandle;
import com.linkwechat.wecom.service.IWeCorpAccountService;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.security.AnyTypePermission;
import lombok.extern.slf4j.Slf4j;
......@@ -14,6 +23,7 @@ import me.chanjar.weixin.common.util.xml.XStreamInitializer;
import me.chanjar.weixin.cp.bean.WxCpXmlMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
......@@ -28,56 +38,86 @@ import javax.servlet.http.HttpServletRequest;
@RequestMapping("/wecom/callback")
public class WeCallBackController extends CommonController {
@Autowired
private WeEventHandle weEventHandle;
WeEventHandle weEventHandle;
@Autowired
IWeCorpAccountService iWeCorpAccountService;
@Autowired
SysLoginService sysLoginService;
@Value("${wecome.callBack.appIdOrCorpId}")
private String appIdOrCorpId;
@Value("${wecome.callBack.token}")
private String token;
@Value("${wecome.callBack.encodingAesKey}")
private String encodingAesKey;
@PostMapping(value = "/recive")
public String recive(@RequestBody String msg, @RequestParam(name = "msg_signature") String signature,
String timestamp, String nonce) {
WxCryptUtil wxCryptUtil = new WxCryptUtil(token, encodingAesKey, appIdOrCorpId);
try {
String decrypt = wxCryptUtil.decrypt(signature, timestamp, nonce, msg);
WxCpXmlMessageVO wxCpXmlMessage = StrXmlToBean(decrypt);
log.info("企微回调通知接口 wxCpXmlMessage:{}", JSONObject.toJSONString(wxCpXmlMessage));
public String recivePost(@RequestBody String msg, @RequestParam(name = "msg_signature") String signature,
String timestamp, String nonce,String corpId) {
if(StrUtil.isEmpty(corpId)){
return "error";
}
WeCorpAccount weCorpAccount = iWeCorpAccountService.getOne(new LambdaQueryWrapper<WeCorpAccount>()
.eq(WeCorpAccount::getCorpId, corpId)
.eq(WeCorpAccount::getStatus, Constants.NORMAL_CODE)
.eq(WeCorpAccount::getDelFlag, Constants.NORMAL_CODE));
if(null != weCorpAccount){
// //校验当前租户账号是否授权登录了,如果未登录,则无密钥登录
// LoginUser loginUser
// = SecurityUtils.getLoginUser();
// if(null == loginUser){
// sysLoginService.noPwdLogin(weCorpAccount.getCorpAccount());
// }
WxCryptUtil wxCryptUtil = new WxCryptUtil(weCorpAccount.getToken(), weCorpAccount.getEncodingAesKey(), weCorpAccount.getCorpId());
try {
WeCallBackEventFactory factory = weEventHandle.factory(wxCpXmlMessage.getEvent());
if (factory !=null){
Threads.SINGLE_THREAD_POOL.submit(() -> factory.eventHandle(wxCpXmlMessage));
String decrypt = wxCryptUtil.decrypt(signature, timestamp, nonce, msg);
WxCpXmlMessageVO wxCpXmlMessage = StrXmlToBean(decrypt);
log.info("企微回调通知接口 wxCpXmlMessage:{}", JSONObject.toJSONString(wxCpXmlMessage));
try {
WeCallBackEventFactory factory = weEventHandle.factory(wxCpXmlMessage.getEvent());
if (factory !=null){
Threads.SINGLE_THREAD_POOL.submit(() -> factory.eventHandle(wxCpXmlMessage));
}
} catch (Exception e) {
e.printStackTrace();
}
return decrypt;
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace();;
String sRespData = WxCryptUtil.getTextRespData("success");
return wxCryptUtil.encrypt(sRespData);
}
return decrypt;
} catch (Exception e) {
e.printStackTrace();;
String sRespData = WxCryptUtil.getTextRespData("success");
return wxCryptUtil.encrypt(sRespData);
}
return "error";
}
@GetMapping(value = "/recive")
public String recive(HttpServletRequest request) {
// 微信加密签名
String sVerifyMsgSig = request.getParameter("msg_signature");
// 时间戳
String sVerifyTimeStamp = request.getParameter("timestamp");
// 随机数
String sVerifyNonce = request.getParameter("nonce");
// 随机字符串
String sVerifyEchoStr = request.getParameter("echostr");
WxCryptUtil wxCryptUtil = new WxCryptUtil(token, encodingAesKey, appIdOrCorpId);
try {
return wxCryptUtil.verifyURL(sVerifyMsgSig, sVerifyTimeStamp, sVerifyNonce, sVerifyEchoStr);
} catch (Exception e) {
public String reciveGet(String msg_signature,String timestamp,String nonce,String echostr, String corpId) {
if(StrUtil.isEmpty(corpId)){
return "error";
}
WeCorpAccount weCorpAccount = iWeCorpAccountService.getOne(new LambdaQueryWrapper<WeCorpAccount>()
.eq(WeCorpAccount::getCorpId, corpId)
.eq(WeCorpAccount::getStatus, Constants.NORMAL_CODE)
.eq(WeCorpAccount::getDelFlag, Constants.NORMAL_CODE));
if(null != weCorpAccount){
WxCryptUtil wxCryptUtil = new WxCryptUtil(weCorpAccount.getToken(), weCorpAccount.getEncodingAesKey(), weCorpAccount.getCorpId());
try {
return wxCryptUtil.verifyURL(msg_signature, timestamp, nonce, echostr);
} catch (Exception e) {
return "error";
}
}
return "error";
}
private WxCpXmlMessageVO StrXmlToBean(String xmlStr){
......
......@@ -229,7 +229,7 @@ public class WeTaskFissionController extends BaseController {
public AjaxResult<JSONObject> upload(@RequestParam(value = "file") MultipartFile file) throws IOException {
String url = FileUploadUtils.upload2Cos(file, cosConfig);
JSONObject json = new JSONObject();
json.put("rewardImageUrl", cosConfig.getImgUrlPrefix()+url);
json.put("rewardImageUrl", cosConfig.getCosImgUrlPrefix()+url);
return AjaxResult.success(json);
}
......
......@@ -12,15 +12,20 @@ ruoyi:
# 是否开启文件云上传(使用的是腾讯云,如果开启了,则需要配置腾讯云存储相关信息;如果关闭了则文件存储再本地,需要配置本地路径)
file:
startCosUpload: true
#图片在系统中的访问前缀,图片无论是上传云端还是服务器本地,都通过本地读取资源,然后返回前端
imgUrlPrefix:
#腾讯云对象存储
cos:
#id
secretId:
#密钥
secretKey:
#地区
region:
#区块空间
bucketName:
# 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /app/project/pic)
#profile: /data/jenkins_home/app/project/
#访问前缀
cosImgUrlPrefix:
# 获取ip地址开关
addressEnabled: false
# 验证码类型 math 数组计算 char 字符验证
......@@ -59,7 +64,7 @@ ruoyi:
- /wecom/community/h5/**
- /weixin/auth/**
- /wecom/material/temporaryMaterialMediaId
- /common/findImage
# 开发环境配置
server:
# 服务器的HTTP端口,默认为8090
......@@ -80,15 +85,15 @@ logging:
level:
com.ruoyi: debug
org.springframework: warn
path: ./logs
path:
log: ./logs
#H5地址路径
H5:
url:
fissionUrl:
fissionGroupUrl:
url: http://h5.linkwechat.cn/index.html
fissionUrl: http://h5.linkwechat.cn/index.html
fissionGroupUrl: http://h5.linkwechat.cn/fission.html
# Spring配置
spring:
# 资源信息
......@@ -101,7 +106,7 @@ spring:
druid:
# 主库数据源
master:
url: jdbc:mysql://127.0.0.1:10179/lw-test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
url: jdbc:mysql://127.0.0.1:10179/link-wechat?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root
password: root
# 从库数据源
......@@ -210,14 +215,6 @@ mybatis-plus:
logic-delete-value: 1
logic-not-delete-value: 0
## MyBatis配置
#mybatis:
# # 搜索指定包别名
# typeAliasesPackage: com.linkwechat.**.domain
# # 配置mapper的扫描,找到所有的mapper.xml映射文件
# mapperLocations: classpath*:mapper/**/*Mapper.xml
# # 加载全局的配置文件
# configLocation: classpath:mybatis/mybatis-config.xml
# PageHelper分页插件
pagehelper:
......@@ -246,8 +243,8 @@ xss:
elasticsearch:
schema: http
address:
userName:
password:
userName: "elastic"
password: "0p-0p-0p-"
connectTimeout: 10000
socketTimeout: 10000
connectionRequestTimeout: 10000
......@@ -320,16 +317,11 @@ wecome:
- we_user
- we_customer
- we_tag_group
#企微回调通知配置
callBack:
appIdOrCorpId:
token:
encodingAesKey:
# JS SDK 身份校验url
authorizeUrl:
# JS SDK身份校验成功后的redirect url
authorizeRedirectUrl:
weixin:
appid:
secret:
\ No newline at end of file
appid: wxa57479bcd3f15461
secret: f23f4becdcac9819f292a3754fd8f84e
\ No newline at end of file
spring.cloud.nacos.config.server-addr=${NACOS_SERVER:119.45.28.29:10848}
spring.cloud.nacos.config.namespace=01cf833f-249e-4483-a286-46d37f018fe7
spring.cloud.nacos.config.namespace=627a666a-76b2-42ad-a1b0-70a12d2c73fd
spring.application.name=link-wechat
spring.cloud.nacos.config.file-extension=yaml
spring.cloud.nacos.config.enabled=false
\ No newline at end of file
spring.cloud.nacos.config.enabled=true
\ No newline at end of file
......@@ -20,6 +20,6 @@ public class CosConfig {
private String bucketName;
private String imgUrlPrefix;
private String cosImgUrlPrefix;
}
......@@ -34,7 +34,7 @@ public class BaseEntity implements Serializable
/** 创建时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(hidden = true)
private Date createTime=new Date();
private Date createTime;
/** 更新者 */
@ApiModelProperty(hidden = true)
......@@ -43,7 +43,7 @@ public class BaseEntity implements Serializable
/** 更新时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(hidden = true)
private Date updateTime=new Date();
private Date updateTime;
/** 备注 */
@TableField(exist = false)
......
......@@ -56,7 +56,7 @@ public class WeCorpAccount extends BaseEntity
/** 删除标志(0代表存在 2代表删除) */
@ApiModelProperty("删除标志(0代表存在 2代表删除)")
private String delFlag=new String("0");
private String delFlag;
@ApiModelProperty("外部联系人密钥")
......@@ -85,4 +85,17 @@ public class WeCorpAccount extends BaseEntity
@ApiModelProperty("企业管理员账号")
private String corpAccount;
@ApiModelProperty("应用回调token密钥")
private String token;
@ApiModelProperty("应用回调消息体加密密钥")
private String encodingAesKey;
}
......@@ -87,4 +87,8 @@ public class SecurityUtils
{
return userId != null && 1L == userId;
}
}
......@@ -261,13 +261,13 @@ public class WxCryptUtil {
SecretKeySpec keySpec = new SecretKeySpec(this.aesKey, "AES");
IvParameterSpec iv = new IvParameterSpec(Arrays.copyOfRange(this.aesKey, 0, 16));
cipher.init(Cipher.DECRYPT_MODE, keySpec, iv);
// 使用BASE64对密文进行解码
byte[] encrypted = Base64.decodeBase64(cipherText);
// 解密
original = cipher.doFinal(encrypted);
} catch (Exception e) {
e.printStackTrace();
throw new WeComException(e.getMessage());
}
......
......@@ -286,7 +286,7 @@ public class FinanceUtils {
getMediaData(sdkfileid, "", "", filePath, fileName);
CosConfig cosConfig = SpringUtils.getBean(CosConfig.class);
String suffix = fileName.substring(fileName.lastIndexOf(".") + 1);
StringBuilder cosUrl = new StringBuilder(cosConfig.getImgUrlPrefix());
StringBuilder cosUrl = new StringBuilder(cosConfig.getCosImgUrlPrefix());
String cosFilePath = FileUploadUtils.upload2Cos(new FileInputStream(new File(filePath, fileName)), suffix, cosConfig);
cosUrl.append(cosFilePath);
data.put("attachment", cosUrl.toString());
......
......@@ -7,6 +7,7 @@ import com.github.pagehelper.PageInterceptor;
import com.linkwechat.common.config.RuoYiConfig;
import com.linkwechat.common.config.WeComeConfig;
import com.linkwechat.common.core.domain.entity.WeCorpAccount;
import com.linkwechat.common.core.domain.model.LoginUser;
import com.linkwechat.common.utils.SecurityUtils;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.StringValue;
......@@ -44,11 +45,15 @@ public class MyBatisPlusConfig {
public Expression getTenantId() {
try {
WeCorpAccount weCorpAccount
= SecurityUtils.getLoginUser().getUser().getWeCorpAccount();
if(null != weCorpAccount){
return new StringValue(weCorpAccount.getCorpId());
LoginUser loginUser = SecurityUtils.getLoginUser();
if(null != loginUser){
WeCorpAccount weCorpAccount
= loginUser.getUser().getWeCorpAccount();
if(null != weCorpAccount){
return new StringValue(weCorpAccount.getCorpId());
}
}
}catch (Exception e){
return null;
}
......
......@@ -103,18 +103,18 @@ public class RyTask {
}
public void WeCustomers() {
//查询系统所有客户
List<WeCustomer> cacheList = redisCache.getCacheList(WeConstans.WECUSTOMERS_KEY);
if (CollectionUtils.isEmpty(cacheList)) {
List<WeCustomer> customers = weCustomerService.selectWeCustomerList(null);
redisCache.setCacheList(WeConstans.WECUSTOMERS_KEY, customers);
} else {
List<WeCustomer> customers = weCustomerService.selectWeCustomerList(null);
List<WeCustomer> weCustomers = redisCache.getCacheList(WeConstans.WECUSTOMERS_KEY);
if (CollectionUtils.isNotEmpty(weCustomers) && weCustomers.size() < customers.size()) {
redisCache.setCacheList(WeConstans.WECUSTOMERS_KEY, customers);
}
}
// //查询系统所有客户
// List<WeCustomer> cacheList = redisCache.getCacheList(WeConstans.WECUSTOMERS_KEY);
// if (CollectionUtils.isEmpty(cacheList)) {
// List<WeCustomer> customers = weCustomerService.selectWeCustomerList(null);
// redisCache.setCacheList(WeConstans.WECUSTOMERS_KEY, customers);
// } else {
// List<WeCustomer> customers = weCustomerService.selectWeCustomerList(null);
// List<WeCustomer> weCustomers = redisCache.getCacheList(WeConstans.WECUSTOMERS_KEY);
// if (CollectionUtils.isNotEmpty(weCustomers) && weCustomers.size() < customers.size()) {
// redisCache.setCacheList(WeConstans.WECUSTOMERS_KEY, customers);
// }
// }
}
private void setRedisCacheSeqValue(AtomicLong index) {
......
......@@ -14,6 +14,7 @@ import java.util.concurrent.ConcurrentHashMap;
**/
@Service
public class WeStrategyBeanFactory {
@Autowired
private final Map<String, WeEventStrategy> eventStrategyMap = new ConcurrentHashMap<>();
......
......@@ -166,7 +166,7 @@ public class WeCallBackAddExternalContactImpl extends WeEventStrategy {
// 新客拉群创建的员工活码欢迎语图片(群活码图片)
String codeUrl = weGroupCodeService.selectGroupCodeUrlByEmplCodeState(state);
if (StringUtils.isNotNull(codeUrl)) {
buildWelcomeMsgImg(weWelcomeMsgBuilder, codeUrl, codeUrl.replaceAll(cosConfig.getImgUrlPrefix(), ""));
buildWelcomeMsgImg(weWelcomeMsgBuilder, codeUrl, codeUrl.replaceAll(cosConfig.getCosImgUrlPrefix(), ""));
}
// 普通员工活码欢迎语图片
else if (StringUtils.isNotEmpty(messageMap.getCategoryId())) {
......
package com.linkwechat.wecom.factory.impl.party;
import com.linkwechat.wecom.domain.WeDepartment;
import com.linkwechat.wecom.domain.vo.WxCpXmlMessageVO;
import com.linkwechat.wecom.factory.WeEventStrategy;
import com.linkwechat.wecom.service.IWeDepartmentService;
......@@ -22,7 +21,7 @@ public class WeCallBackCreatePartyImpl extends WeEventStrategy {
@Override
public void eventHandle(WxCpXmlMessageVO message) {
try {
weDepartmentService.insertWeDepartmentNoToWeCom(setWeDepartMent(message));
weDepartmentService.save(setWeDepartMent(message));
} catch (Exception e) {
e.printStackTrace();
log.error(e.getMessage());
......
......@@ -30,7 +30,7 @@ public interface IWeDepartmentService extends IService<WeDepartment>
*/
public void insertWeDepartment(WeDepartment weDepartment);
public int insertWeDepartmentNoToWeCom(WeDepartment weDepartment);
// public int insertWeDepartmentNoToWeCom(WeDepartment weDepartment);
/**
* 修改企业微信组织架构相关
......
......@@ -103,14 +103,15 @@ public class WeDepartmentServiceImpl extends ServiceImpl<WeDepartmentMapper,WeDe
}
@Override
public int insertWeDepartmentNoToWeCom(WeDepartment weDepartment) {
WeDepartment department = this.baseMapper.selectWeDepartmentById(weDepartment.getId());
if (department !=null){
return 0;
}
return this.baseMapper.insertWeDepartment(weDepartment);
}
// @Override
// public int insertWeDepartmentNoToWeCom(WeDepartment weDepartment) {
// WeDepartment department = this.baseMapper.selectWeDepartmentById(weDepartment.getId());
// if (department !=null){
// return 0;
// }
//
// return saveOrUpdate(weDepartment);
// }
/**
* 修改企业微信组织架构相关
......
......@@ -453,7 +453,7 @@ public class WeTaskFissionServiceImpl extends ServiceImpl<WeTaskFissionMapper, W
throw new WeComException("生成二维码异常");
}
}
return cosConfig.getImgUrlPrefix() + qrCode;
return cosConfig.getCosImgUrlPrefix() + qrCode;
} else {
throw new WeComException("生成二维码异常,用户信息不存在");
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册