提交 91032f33 编写于 作者: 1 1539136324@qq.com

优化提取任务宝与群裂变相关运行参数。

上级 5eeba376
......@@ -88,12 +88,6 @@ logging:
path:
log: ./logs
#H5地址路径
H5:
url: http://h5.linkwechat.cn/index.html
fissionUrl: http://h5.linkwechat.cn/index.html
fissionGroupUrl: http://h5.linkwechat.cn/fission.html
# Spring配置
spring:
# 资源信息
......
......@@ -98,4 +98,21 @@ public class WeCorpAccount extends BaseEntity
@ApiModelProperty("微信公众号APPID")
private String appid;
@ApiModelProperty("微信公众号密钥")
private String secret;
@ApiModelProperty("任务宝H5访问地址")
private String fissionUrl;
@ApiModelProperty("群裂变H5访问地址")
private String fissionGroupUrl;
}
package com.linkwechat.wecom.interceptor;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.dtflys.forest.exceptions.ForestRuntimeException;
......@@ -8,14 +9,16 @@ import com.dtflys.forest.http.ForestResponse;
import com.dtflys.forest.interceptor.Interceptor;
import com.dtflys.forest.utils.ForestDataType;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.core.domain.entity.WeCorpAccount;
import com.linkwechat.common.core.domain.model.LoginUser;
import com.linkwechat.common.core.redis.RedisCache;
import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.wecom.domain.weixin.dto.WxBaseResultDto;
import com.linkwechat.wecom.domain.weixin.dto.WxTokenDto;
import com.linkwechat.wecom.wxclient.WxCommonClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.concurrent.TimeUnit;
......@@ -28,11 +31,9 @@ import java.util.concurrent.TimeUnit;
@Slf4j
@Component
public class WeiXinAccessTokenInterceptor implements Interceptor {
//暂时写到配置文件,之后写入数据库
@Value("${weixin.appid}")
private String appId;
@Value("${weixin.secret}")
private String secret;
private final String grantType = "client_credential";
@Autowired
......@@ -51,16 +52,29 @@ public class WeiXinAccessTokenInterceptor implements Interceptor {
private String findAccessToken(){
//获取用户token
String accessToken =redisCache.getCacheObject(WeConstans.WX_ACCESS_TOKEN);
if (StringUtils.isEmpty(accessToken)){
//当用户token失效,重新获取token
WxTokenDto wxTokenDto = wxCommonClient.getToken(grantType, appId, secret);
if(wxTokenDto != null && StringUtils.isNotEmpty(wxTokenDto.getAccessToken())){
redisCache.setCacheObject(WeConstans.WX_AUTH_ACCESS_TOKEN, wxTokenDto.getAccessToken(), wxTokenDto.getExpiresIn(), TimeUnit.SECONDS);
accessToken = wxTokenDto.getAccessToken();
String accessToken=null;
LoginUser loginUser = SecurityUtils.getLoginUser();
if(null != loginUser && null != loginUser.getUser() && null != loginUser.getUser().getWeCorpAccount()){
WeCorpAccount weCorpAccount = loginUser.getUser().getWeCorpAccount();
if(StrUtil.isEmpty(weCorpAccount.getAppid()) && StrUtil.isEmpty(weCorpAccount.getSecret())){
//获取用户token
accessToken =redisCache.getCacheObject(WeConstans.WX_ACCESS_TOKEN);
if (StringUtils.isEmpty(accessToken)){
//当用户token失效,重新获取token
WxTokenDto wxTokenDto = wxCommonClient.getToken(grantType, weCorpAccount.getAppid(), weCorpAccount.getSecret());
if(wxTokenDto != null && StringUtils.isNotEmpty(wxTokenDto.getAccessToken())){
redisCache.setCacheObject(WeConstans.WX_AUTH_ACCESS_TOKEN, wxTokenDto.getAccessToken(), wxTokenDto.getExpiresIn(), TimeUnit.SECONDS);
accessToken = wxTokenDto.getAccessToken();
}
}
}else{
throw new ForestRuntimeException("公众号appid或者secret不可为空");
}
}
return accessToken;
}
......
package com.linkwechat.wecom.interceptor;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.dtflys.forest.exceptions.ForestRuntimeException;
......@@ -8,8 +9,12 @@ import com.dtflys.forest.http.ForestResponse;
import com.dtflys.forest.interceptor.Interceptor;
import com.dtflys.forest.utils.ForestDataType;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.core.domain.entity.WeCorpAccount;
import com.linkwechat.common.core.domain.model.LoginUser;
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.ServletUtils;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.wecom.domain.weixin.dto.WxTokenDto;
import com.linkwechat.wecom.domain.weixin.dto.WxBaseResultDto;
......@@ -26,15 +31,11 @@ import java.util.concurrent.TimeUnit;
* @description 微信授权拦截器
* @date 2021/4/5 15:28
**/
@Slf4j
@Component
public class WeiXinAuthInterceptor implements Interceptor {
//暂时写到配置文件,之后写入数据库
@Value("${weixin.appid}")
private String appId;
@Value("${weixin.secret}")
private String secret;
private final String grantType = "refresh_token";
@Autowired
......@@ -63,9 +64,16 @@ public class WeiXinAuthInterceptor implements Interceptor {
if(StringUtils.isEmpty(refreshToken)){
throw new WeComException(1001,"token失效,请重新授权");
}else {
wxTokenDto = wxAuthClient.refreshToken(appId, grantType, refreshToken);
if(wxTokenDto != null && StringUtils.isNotEmpty(wxTokenDto.getAccessToken())){
redisCache.setCacheObject(WeConstans.WX_AUTH_ACCESS_TOKEN+":"+ openId, wxTokenDto, wxTokenDto.getExpiresIn(), TimeUnit.SECONDS);
LoginUser loginUser = SecurityUtils.getLoginUser();
if(null != loginUser && null != loginUser.getUser() && null != loginUser.getUser().getWeCorpAccount()) {
WeCorpAccount weCorpAccount = loginUser.getUser().getWeCorpAccount();
if (StrUtil.isEmpty(weCorpAccount.getAppid())) {
wxTokenDto = wxAuthClient.refreshToken(weCorpAccount.getAppid(), grantType, refreshToken);
if(wxTokenDto != null && StringUtils.isNotEmpty(wxTokenDto.getAccessToken())){
redisCache.setCacheObject(WeConstans.WX_AUTH_ACCESS_TOKEN+":"+ openId, wxTokenDto, wxTokenDto.getExpiresIn(), TimeUnit.SECONDS);
}
}
}
}
}
......
......@@ -62,16 +62,14 @@ public class WeTaskFissionServiceImpl extends ServiceImpl<WeTaskFissionMapper, W
private IWeCustomerMessagePushService weCustomerMessagePushService;
@Autowired
private IWeTaskFissionRecordService weTaskFissionRecordService;
@Autowired
private IWeUserService weUserService;
@Autowired
private WeExternalContactClient weExternalContactClient;
@Autowired
private IWePosterService wePosterService;
@Autowired
private IWeGroupCodeService weGroupCodeService;
@Autowired
private IWeMaterialService weMaterialService;
@Autowired
private IWeCustomerService weCustomerService;
@Autowired
......@@ -81,10 +79,7 @@ public class WeTaskFissionServiceImpl extends ServiceImpl<WeTaskFissionMapper, W
@Autowired
private CosConfig cosConfig;
@Value("${H5.fissionUrl}")
private String pageUrl;
@Value("${H5.fissionGroupUrl}")
private String pageGroupUrl;
/**
* 查询任务宝
......@@ -203,7 +198,9 @@ public class WeTaskFissionServiceImpl extends ServiceImpl<WeTaskFissionMapper, W
//目标员工id
String fissStaffId = weTaskFission.getFissionTargetId();
//H5生成海报页面路径
StringBuilder pageUrlBuilder = new StringBuilder(pageUrl);
StringBuilder pageUrlBuilder = new StringBuilder(
SecurityUtils.getLoginUser().getUser().getWeCorpAccount().getFissionUrl()
);
pageUrlBuilder.append("?")
.append("fissionId=").append(id)
.append("&")
......@@ -436,7 +433,7 @@ public class WeTaskFissionServiceImpl extends ServiceImpl<WeTaskFissionMapper, W
String qrCode = null;
if (weCustomer != null) {
String avatarUrl = weCustomer.getAvatar();
StringBuilder contentBuilder = new StringBuilder(pageGroupUrl);
StringBuilder contentBuilder = new StringBuilder( SecurityUtils.getLoginUser().getUser().getWeCorpAccount().getFissionGroupUrl());
contentBuilder.append("?")
.append("fissionId=")
.append(taskFissionId)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册