feat(ShopController): 添加企业微信认证和重定向功能
新增了企业微信认证和重定向功能,根据用户设备类型(移动端或PC端)进行不同的重定向处理。同时,优化了URL编码的测试代码。
This commit is contained in:
parent
455cdb2f1a
commit
b4d4e658dd
|
@ -1,6 +1,7 @@
|
|||
package com.agileboot.api.controller;
|
||||
|
||||
import cn.hutool.core.util.URLUtil;
|
||||
import cn.hutool.http.useragent.UserAgentUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.agileboot.api.response.ShopGoodsResponse;
|
||||
import com.agileboot.common.constant.WeixinConstants;
|
||||
|
@ -138,8 +139,61 @@ public class ShopController {
|
|||
return new RedirectView(builder.build().encode().toUriString());
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/qy/wechatAuth/home")
|
||||
public RedirectView qyWechatAuthHomeRedirect(HttpServletRequest request) {
|
||||
String userAgent = request.getHeader("User-Agent");
|
||||
boolean isMobile = UserAgentUtil.parse(userAgent).isMobile();
|
||||
String redirectPath = isMobile ? "homeRedirect" : "adminRedirect";
|
||||
|
||||
String authUrl = "https://open.weixin.qq.com/connect/oauth2/authorize"
|
||||
+ "?appid=" + WeixinConstants.corpid
|
||||
+ "&redirect_uri=http%3A%2F%2Fwxshop.ab98.cn%2Fshop-api%2Fapi%2Fshop%2F" + redirectPath
|
||||
+ "&response_type=code"
|
||||
+ "&scope=snsapi_base"
|
||||
+ "&state=STATE"
|
||||
+ "&agentid=" + WeixinConstants.agentid
|
||||
+ "#wechat_redirect";
|
||||
return new RedirectView(authUrl);
|
||||
}
|
||||
|
||||
@GetMapping("/homeRedirect")
|
||||
public RedirectView homeRedirect(HttpServletRequest request) {
|
||||
UriComponentsBuilder builder = UriComponentsBuilder
|
||||
.fromHttpUrl("http://wxshop.ab98.cn/shop")
|
||||
.queryParam("corpid", WeixinConstants.corpid)
|
||||
.queryParam("device", "APP");
|
||||
|
||||
request.getParameterMap().forEach((key, values) -> {
|
||||
if (!"corpid".equals(key) && !"device".equals(key)) {
|
||||
builder.queryParam(key, (Object[]) values);
|
||||
}
|
||||
});
|
||||
|
||||
return new RedirectView(builder.build().encode().toUriString());
|
||||
}
|
||||
|
||||
@GetMapping("/adminRedirect")
|
||||
public RedirectView adminRedirect(HttpServletRequest request) {
|
||||
UriComponentsBuilder builder = UriComponentsBuilder
|
||||
.fromHttpUrl("http://wxshop.ab98.cn/shop-admin")
|
||||
.queryParam("corpid", WeixinConstants.corpid)
|
||||
.queryParam("device", "PC");
|
||||
|
||||
request.getParameterMap().forEach((key, values) -> {
|
||||
if (!"corpid".equals(key) && !"device".equals(key)) {
|
||||
builder.queryParam(key, (Object[]) values);
|
||||
}
|
||||
});
|
||||
|
||||
return new RedirectView(builder.build().encode().toUriString());
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws UnsupportedEncodingException {
|
||||
String res = URLEncoder.encode("token=12312", StandardCharsets.UTF_8.name());
|
||||
System.out.println(res);
|
||||
|
||||
String url = URLUtil.encode("http://wxshop.ab98.cn/shop-api/api/shop/");
|
||||
System.out.println(url);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue