fix(微信授权): 在所有微信授权URL中添加corpid参数并处理默认值
修改多个服务和应用层代码,确保微信授权URL中正确传递corpid参数。 当未接收到corpid参数时,使用默认值并记录警告日志。 同时更新相关重定向逻辑以保持参数一致性。
This commit is contained in:
parent
f19a8077c4
commit
8c29745228
|
|
@ -193,7 +193,7 @@ public class QywxMessageJob {
|
|||
article.setDescription("你借用的 【" + record.getGoodsName() + "】 已逾期未归还,请及时归还");
|
||||
article.setPicurl(record.getCoverImg());
|
||||
String serverHost = CacheCenter.configCache.get(ConfigKeyEnum.SERVER_HOST.getValue());
|
||||
article.setUrl(serverHost + UrlConstants.WECHAT_AUTH_HOME_URL);
|
||||
article.setUrl(serverHost + UrlConstants.WECHAT_AUTH_HOME_URL + "?corpid=" + authCorpInfo.getCorpid());
|
||||
articles.add(article);
|
||||
|
||||
QywxApiUtil.sendNewsMessage(accessToken, Integer.valueOf(authCorpInfo.getAgentid()),
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ import com.agileboot.common.constant.UrlConstants;
|
|||
import com.agileboot.common.core.dto.ResponseDTO;
|
||||
import com.agileboot.common.enums.common.ConfigKeyEnum;
|
||||
import com.agileboot.domain.common.cache.CacheCenter;
|
||||
import com.agileboot.domain.qywx.authCorpInfo.AuthCorpInfoApplicationService;
|
||||
import com.agileboot.domain.qywx.authCorpInfo.db.QyAuthCorpInfoEntity;
|
||||
import com.agileboot.domain.shop.category.CategoryApplicationService;
|
||||
import com.agileboot.domain.shop.category.db.ShopCategoryEntity;
|
||||
import com.agileboot.domain.shop.category.dto.ShopCategoryDTO;
|
||||
|
|
@ -47,6 +49,7 @@ public class ShopController {
|
|||
private final CategoryApplicationService categoryApplicationService;
|
||||
private final CacheCenter cacheCenter;
|
||||
private final WxshopConfig wxshopConfig;
|
||||
private final AuthCorpInfoApplicationService authCorpInfoApplicationService;
|
||||
|
||||
@GetMapping("/list")
|
||||
public ResponseDTO<List<ShopEntity>> getShopList(@RequestParam(required = false) String corpid,
|
||||
|
|
@ -56,6 +59,7 @@ public class ShopController {
|
|||
if (StringUtils.isNotBlank(corpid)) {
|
||||
shopList = shopApplicationService.getShopListByCorpid(corpid, modeValue);
|
||||
} else {
|
||||
log.warn("getShopList接口未接收到corpid参数,使用默认corpid: {}", WeixinConstants.corpid);
|
||||
shopList = shopApplicationService.getShopListByCorpid(WeixinConstants.corpid, modeValue);
|
||||
}
|
||||
return ResponseDTO.ok(shopList);
|
||||
|
|
@ -64,6 +68,7 @@ public class ShopController {
|
|||
@GetMapping("/goods/list")
|
||||
public ResponseDTO<List<SearchGoodsDO>> getShopGoodsList(SearchShopGoodsQuery<SearchGoodsDO> query) {
|
||||
if (StringUtils.isBlank(query.getCorpid())) {
|
||||
log.warn("getShopGoodsList接口未接收到corpid参数,使用默认corpid: {}", WeixinConstants.corpid);
|
||||
query.setCorpid(WeixinConstants.corpid);
|
||||
}
|
||||
if (query.getBelongType() == null) {
|
||||
|
|
@ -161,15 +166,21 @@ public class ShopController {
|
|||
joiner.add(key + "=" + String.join(",", values));
|
||||
});
|
||||
log.info("/qy/wechatAuth 参数:{}", joiner.toString());*/
|
||||
String corpid = request.getParameter("corpid");
|
||||
if (StringUtils.isBlank(corpid)) {
|
||||
log.warn("qyWechatAuthRedirect接口未接收到corpid参数,使用默认corpid: {}", WeixinConstants.corpid);
|
||||
corpid = WeixinConstants.corpid;
|
||||
}
|
||||
QyAuthCorpInfoEntity authCorpInfo = authCorpInfoApplicationService.selectByCorpid(corpid);
|
||||
|
||||
String serverHost = cacheCenter.configCache.get(ConfigKeyEnum.SERVER_HOST.getValue());
|
||||
String authUrl = "https://open.weixin.qq.com/connect/oauth2/authorize"
|
||||
+ "?appid=" + WeixinConstants.corpid
|
||||
+ "&redirect_uri=" + URLUtil.encodeQuery(serverHost + UrlConstants.APPROVAL_REDIRECT_HANDLER_URL)
|
||||
+ "?appid=" + authCorpInfo.getCorpid()
|
||||
+ "&redirect_uri=" + URLUtil.encodeQuery(serverHost + UrlConstants.APPROVAL_REDIRECT_HANDLER_URL + "?corpid=" + corpid)
|
||||
+ "&response_type=code"
|
||||
+ "&scope=snsapi_base"
|
||||
+ "&state=STATE"
|
||||
+ "&agentid=" + WeixinConstants.agentid
|
||||
+ "&agentid=" + authCorpInfo.getAgentid()
|
||||
+ "#wechat_redirect";
|
||||
return new RedirectView(authUrl);
|
||||
}
|
||||
|
|
@ -181,10 +192,16 @@ public class ShopController {
|
|||
*/
|
||||
@GetMapping("/approvalRedirect")
|
||||
public RedirectView approvalRedirect(HttpServletRequest request) {
|
||||
String corpid = request.getParameter("corpid");
|
||||
if (StringUtils.isBlank(corpid)) {
|
||||
log.warn("approvalRedirect接口未接收到corpid参数,使用默认corpid: {}", WeixinConstants.corpid);
|
||||
corpid = WeixinConstants.corpid;
|
||||
}
|
||||
|
||||
String serverHost = cacheCenter.configCache.get(ConfigKeyEnum.SERVER_HOST.getValue());
|
||||
UriComponentsBuilder builder = UriComponentsBuilder
|
||||
.fromHttpUrl(serverHost + UrlConstants.APPROVAL_REDIRECT_URL)
|
||||
.queryParam("corpid", WeixinConstants.corpid)
|
||||
.queryParam("corpid", corpid)
|
||||
.queryParam("device", "APP");
|
||||
|
||||
request.getParameterMap().forEach((key, values) -> {
|
||||
|
|
@ -203,14 +220,21 @@ public class ShopController {
|
|||
*/
|
||||
@GetMapping("/qy/wechatAuth/asset")
|
||||
public RedirectView qyWechatAuthAssetRedirect(HttpServletRequest request) {
|
||||
String corpid = request.getParameter("corpid");
|
||||
if (StringUtils.isBlank(corpid)) {
|
||||
log.warn("qyWechatAuthAssetRedirect接口未接收到corpid参数,使用默认corpid: {}", WeixinConstants.corpid);
|
||||
corpid = WeixinConstants.corpid;
|
||||
}
|
||||
QyAuthCorpInfoEntity authCorpInfo = authCorpInfoApplicationService.selectByCorpid(corpid);
|
||||
|
||||
String serverHost = cacheCenter.configCache.get(ConfigKeyEnum.SERVER_HOST.getValue());
|
||||
String authUrl = "https://open.weixin.qq.com/connect/oauth2/authorize"
|
||||
+ "?appid=" + WeixinConstants.corpid
|
||||
+ "&redirect_uri=" + URLUtil.encodeQuery(serverHost + UrlConstants.APPROVAL_ASSET_REDIRECT_HANDLER_URL)
|
||||
+ "?appid=" + authCorpInfo.getCorpid()
|
||||
+ "&redirect_uri=" + URLUtil.encodeQuery(serverHost + UrlConstants.APPROVAL_ASSET_REDIRECT_HANDLER_URL + "?corpid=" + corpid)
|
||||
+ "&response_type=code"
|
||||
+ "&scope=snsapi_base"
|
||||
+ "&state=STATE"
|
||||
+ "&agentid=" + WeixinConstants.agentid
|
||||
+ "&agentid=" + authCorpInfo.getAgentid()
|
||||
+ "#wechat_redirect";
|
||||
return new RedirectView(authUrl);
|
||||
}
|
||||
|
|
@ -222,10 +246,16 @@ public class ShopController {
|
|||
*/
|
||||
@GetMapping("/approvalAssetRedirect")
|
||||
public RedirectView approvalAssetRedirect(HttpServletRequest request) {
|
||||
String corpid = request.getParameter("corpid");
|
||||
if (StringUtils.isBlank(corpid)) {
|
||||
log.warn("approvalAssetRedirect接口未接收到corpid参数,使用默认corpid: {}", WeixinConstants.corpid);
|
||||
corpid = WeixinConstants.corpid;
|
||||
}
|
||||
|
||||
String serverHost = cacheCenter.configCache.get(ConfigKeyEnum.SERVER_HOST.getValue());
|
||||
UriComponentsBuilder builder = UriComponentsBuilder
|
||||
.fromHttpUrl(serverHost + UrlConstants.APPROVAL_ASSET_REDIRECT_URL)
|
||||
.queryParam("corpid", WeixinConstants.corpid)
|
||||
.queryParam("corpid", corpid)
|
||||
.queryParam("device", "APP");
|
||||
|
||||
request.getParameterMap().forEach((key, values) -> {
|
||||
|
|
@ -244,19 +274,25 @@ public class ShopController {
|
|||
*/
|
||||
@GetMapping("/qy/wechatAuth/home")
|
||||
public RedirectView qyWechatAuthHomeRedirect(HttpServletRequest request) {
|
||||
String corpid = request.getParameter("corpid");
|
||||
if (StringUtils.isBlank(corpid)) {
|
||||
log.warn("qyWechatAuthHomeRedirect接口未接收到corpid参数,使用默认corpid: {}", WeixinConstants.corpid);
|
||||
corpid = WeixinConstants.corpid;
|
||||
}
|
||||
QyAuthCorpInfoEntity authCorpInfo = authCorpInfoApplicationService.selectByCorpid(corpid);
|
||||
|
||||
String userAgent = request.getHeader("User-Agent");
|
||||
boolean isMobile = UserAgentUtil.parse(userAgent).isMobile();
|
||||
String redirectPath = isMobile ? "homeRedirect" : "adminRedirect";
|
||||
|
||||
String serverHost = cacheCenter.configCache.get(ConfigKeyEnum.SERVER_HOST.getValue());
|
||||
String redirectHandlerUrl = isMobile ? UrlConstants.HOME_REDIRECT_HANDLER_URL : UrlConstants.ADMIN_REDIRECT_HANDLER_URL;
|
||||
String authUrl = "https://open.weixin.qq.com/connect/oauth2/authorize"
|
||||
+ "?appid=" + WeixinConstants.corpid
|
||||
+ "&redirect_uri=" + URLUtil.encodeQuery(serverHost + redirectHandlerUrl)
|
||||
+ "?appid=" + authCorpInfo.getCorpid()
|
||||
+ "&redirect_uri=" + URLUtil.encodeQuery(serverHost + redirectHandlerUrl + "?corpid=" + corpid)
|
||||
+ "&response_type=code"
|
||||
+ "&scope=snsapi_base"
|
||||
+ "&state=STATE"
|
||||
+ "&agentid=" + WeixinConstants.agentid
|
||||
+ "&agentid=" + authCorpInfo.getAgentid()
|
||||
+ "#wechat_redirect";
|
||||
return new RedirectView(authUrl);
|
||||
}
|
||||
|
|
@ -269,10 +305,16 @@ public class ShopController {
|
|||
*/
|
||||
@GetMapping("/homeRedirect")
|
||||
public RedirectView homeRedirect(HttpServletRequest request) {
|
||||
String corpid = request.getParameter("corpid");
|
||||
if (StringUtils.isBlank(corpid)) {
|
||||
log.warn("homeRedirect接口未接收到corpid参数,使用默认corpid: {}", WeixinConstants.corpid);
|
||||
corpid = WeixinConstants.corpid;
|
||||
}
|
||||
|
||||
String serverHost = cacheCenter.configCache.get(ConfigKeyEnum.SERVER_HOST.getValue());
|
||||
UriComponentsBuilder builder = UriComponentsBuilder
|
||||
.fromHttpUrl(serverHost + UrlConstants.HOME_REDIRECT_URL)
|
||||
.queryParam("corpid", WeixinConstants.corpid)
|
||||
.queryParam("corpid", corpid)
|
||||
.queryParam("device", "APP");
|
||||
|
||||
request.getParameterMap().forEach((key, values) -> {
|
||||
|
|
@ -292,10 +334,16 @@ public class ShopController {
|
|||
*/
|
||||
@GetMapping("/adminRedirect")
|
||||
public RedirectView adminRedirect(HttpServletRequest request) {
|
||||
String corpid = request.getParameter("corpid");
|
||||
if (StringUtils.isBlank(corpid)) {
|
||||
log.warn("adminRedirect接口未接收到corpid参数,使用默认corpid: {}", WeixinConstants.corpid);
|
||||
corpid = WeixinConstants.corpid;
|
||||
}
|
||||
|
||||
String serverHost = cacheCenter.configCache.get(ConfigKeyEnum.SERVER_HOST.getValue());
|
||||
UriComponentsBuilder builder = UriComponentsBuilder
|
||||
.fromHttpUrl(serverHost + UrlConstants.ADMIN_REDIRECT_URL)
|
||||
.queryParam("corpid", WeixinConstants.corpid)
|
||||
.queryParam("corpid", corpid)
|
||||
.queryParam("device", "PC");
|
||||
|
||||
request.getParameterMap().forEach((key, values) -> {
|
||||
|
|
|
|||
|
|
@ -199,7 +199,7 @@ public class AssetApplicationService {
|
|||
}
|
||||
article.setPicurl(firstGoods.getCoverImg());
|
||||
String serverHost = CacheCenter.configCache.get(ConfigKeyEnum.SERVER_HOST.getValue());
|
||||
article.setUrl(serverHost + UrlConstants.WECHAT_AUTH_ASSET_URL);
|
||||
article.setUrl(serverHost + UrlConstants.WECHAT_AUTH_ASSET_URL + "?corpid=" + postAssetApprovalCommand.getCorpid());
|
||||
articles.add(article);
|
||||
|
||||
QywxApiUtil.sendNewsMessage(accessToken.getAccessToken(), Integer.valueOf(authCorpInfo.getAgentid()),
|
||||
|
|
|
|||
|
|
@ -815,7 +815,7 @@ public class ReturnApprovalApplicationService {
|
|||
article.setDescription("退还商品:" + orderGoods.getGoodsName());
|
||||
article.setPicurl(orderGoods.getCoverImg());
|
||||
String serverHost = CacheCenter.configCache.get(ConfigKeyEnum.SERVER_HOST.getValue());
|
||||
article.setUrl(serverHost + UrlConstants.WECHAT_AUTH_URL);
|
||||
article.setUrl(serverHost + UrlConstants.WECHAT_AUTH_URL + "?corpid=" + command.getCorpid());
|
||||
articles.add(article);
|
||||
|
||||
QywxApiUtil.sendNewsMessage(accessToken.getAccessToken(), Integer.valueOf(authCorpInfo.getAgentid()),
|
||||
|
|
|
|||
|
|
@ -288,7 +288,7 @@ public class OrderApplicationService {
|
|||
article.setPicurl(firstOrderGoods.getCoverImg());
|
||||
|
||||
String serverHost = CacheCenter.configCache.get(ConfigKeyEnum.SERVER_HOST.getValue());
|
||||
article.setUrl(serverHost + UrlConstants.WECHAT_AUTH_URL);
|
||||
article.setUrl(serverHost + UrlConstants.WECHAT_AUTH_URL + "?corpid=" + command.getCorpid());
|
||||
articles.add(article);
|
||||
|
||||
QywxApiUtil.sendNewsMessage(accessToken.getAccessToken(), Integer.valueOf(authCorpInfo.getAgentid()),
|
||||
|
|
|
|||
Loading…
Reference in New Issue