diff --git a/pom.xml b/pom.xml
index 5e02b24..6f5f2f0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -24,6 +24,11 @@
org.springframework.boot
spring-boot-starter-data-redis
+
+ redis.clients
+ jedis
+ 2.9.3
+
org.springframework.boot
spring-boot-starter-mail
@@ -123,6 +128,7 @@
commons-codec
commons-codec
+ 1.14
io.jsonwebtoken
diff --git a/src/main/java/com/rymcu/vertical/wx/open/controller/WxOpenApiController.java b/src/main/java/com/rymcu/vertical/wx/open/controller/WxOpenApiController.java
new file mode 100644
index 0000000..ed14ee3
--- /dev/null
+++ b/src/main/java/com/rymcu/vertical/wx/open/controller/WxOpenApiController.java
@@ -0,0 +1,76 @@
+package com.rymcu.vertical.wx.open.controller;
+
+import com.rymcu.vertical.wx.open.handler.WxOpenServiceHandler;
+import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerInfoResult;
+import me.chanjar.weixin.open.bean.result.WxOpenQueryAuthResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+/**
+ * @author 007
+ */
+@Controller
+@RequestMapping("/wx/open/auth")
+public class WxOpenApiController {
+
+ private final Logger logger = LoggerFactory.getLogger(getClass());
+
+ @Resource
+ private WxOpenServiceHandler wxOpenServiceHandler;
+
+ @GetMapping("/goto_auth_url_show")
+ @ResponseBody
+ public String gotoPreAuthUrlShow(){
+ return "go";
+ }
+
+ @GetMapping("/goto_auth_url")
+ public void gotoPreAuthUrl(HttpServletRequest request, HttpServletResponse response){
+ String host = request.getHeader("host");
+ String url = "http://"+host+"/vertical-console/wx/open/auth/jump";
+ try {
+ url = wxOpenServiceHandler.getWxOpenComponentService().getPreAuthUrl(url);
+ // 添加来源,解决302跳转来源丢失的问题
+ response.addHeader("Referer", "http://"+host);
+ response.sendRedirect(url);
+ } catch (WxErrorException | IOException e) {
+ logger.error("gotoPreAuthUrl", e);
+ throw new RuntimeException(e);
+ }
+ }
+
+ @GetMapping("/jump")
+ @ResponseBody
+ public WxOpenQueryAuthResult jump(@RequestParam("auth_code") String authorizationCode){
+ try {
+ WxOpenQueryAuthResult queryAuthResult = wxOpenServiceHandler.getWxOpenComponentService().getQueryAuth(authorizationCode);
+ logger.info("getQueryAuth", queryAuthResult);
+ return queryAuthResult;
+ } catch (WxErrorException e) {
+ logger.error("gotoPreAuthUrl", e);
+ throw new RuntimeException(e);
+ }
+ }
+
+ @GetMapping("/get_auth_info")
+ @ResponseBody
+ public WxOpenAuthorizerInfoResult getAuthInfo(@RequestParam String appId){
+ try {
+ return wxOpenServiceHandler.getWxOpenComponentService().getAuthorizerInfo(appId);
+ } catch (WxErrorException e) {
+ logger.error("getAuthInfo", e);
+ throw new RuntimeException(e);
+ }
+ }
+}
diff --git a/src/main/java/com/rymcu/vertical/wx/open/controller/WxOpenNotifyController.java b/src/main/java/com/rymcu/vertical/wx/open/controller/WxOpenNotifyController.java
index 3b2e3fe..1b23a91 100644
--- a/src/main/java/com/rymcu/vertical/wx/open/controller/WxOpenNotifyController.java
+++ b/src/main/java/com/rymcu/vertical/wx/open/controller/WxOpenNotifyController.java
@@ -16,7 +16,7 @@ import org.springframework.web.bind.annotation.*;
* @author 007
*/
@RestController
-@RequestMapping("/notify")
+@RequestMapping("/wx/notify")
public class WxOpenNotifyController {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
@@ -52,7 +52,7 @@ public class WxOpenNotifyController {
return "success";
}
- @RequestMapping("{appId}/callback")
+ @RequestMapping("/{appId}/callback")
public Object callback(@RequestBody(required = false) String requestBody,
@PathVariable("appId") String appId,
@RequestParam("signature") String signature,
diff --git a/src/main/java/com/rymcu/vertical/wx/open/handler/WxOpenServiceHandler.java b/src/main/java/com/rymcu/vertical/wx/open/handler/WxOpenServiceHandler.java
index e361568..f038c2b 100644
--- a/src/main/java/com/rymcu/vertical/wx/open/handler/WxOpenServiceHandler.java
+++ b/src/main/java/com/rymcu/vertical/wx/open/handler/WxOpenServiceHandler.java
@@ -1,17 +1,15 @@
package com.rymcu.vertical.wx.open.handler;
-import com.rymcu.vertical.core.service.props.DynProps4FilesService;
+import com.rymcu.vertical.config.RedisProperties;
import com.rymcu.vertical.wx.open.config.WxOpenProperties;
import me.chanjar.weixin.open.api.impl.WxOpenInRedisConfigStorage;
import me.chanjar.weixin.open.api.impl.WxOpenMessageRouter;
import me.chanjar.weixin.open.api.impl.WxOpenServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.env.Environment;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Service;
-import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
-import redis.clients.jedis.JedisPoolConfig;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
@@ -20,20 +18,17 @@ import javax.annotation.Resource;
* @author ronger
*/
@Service
+@EnableConfigurationProperties({WxOpenProperties.class, RedisProperties.class})
public class WxOpenServiceHandler extends WxOpenServiceImpl {
private Logger logger = LoggerFactory.getLogger(getClass());
-
@Resource
private WxOpenProperties wxOpenProperties;
@Resource
- private WxOpenMessageRouter wxOpenMessageRouter;
- @Resource
- private DynProps4FilesService dynProps4Files;
- @Resource
- private Environment env;
+ private RedisProperties redisProperties;
private static JedisPool pool;
+ private WxOpenMessageRouter wxOpenMessageRouter;
@PostConstruct
public void init() {
@@ -54,14 +49,12 @@ public class WxOpenServiceHandler extends WxOpenServiceImpl {
if (pool == null) {
synchronized (WxOpenServiceHandler.class) {
if (pool == null) {
- JedisPoolConfig config = new JedisPoolConfig();
- config.setMaxIdle(dynProps4Files.getInt("REDIS_MAX_IDLE", JedisPoolConfig.DEFAULT_MAX_IDLE));
- config.setMaxTotal(dynProps4Files.getInt("REDIS_MAX_TOTAL", JedisPoolConfig.DEFAULT_MAX_TOTAL));
- config.setMaxWaitMillis(dynProps4Files.getLong("REDIS_MAX_WAIT", JedisPoolConfig.DEFAULT_MAX_WAIT_MILLIS));
- config.setTestOnBorrow(true);
- pool = new JedisPool(config, env.getProperty("spring.redis.host"),
- dynProps4Files.getInt("REDIS_PORT", 6379), dynProps4Files.getInt(
- "REDIS_MAX_WAIT", 1000), dynProps4Files.getProperty("REDIS_PASSWORD", env.getProperty("spring.redis.password")));
+ pool = new JedisPool(redisProperties, redisProperties.getHost(),
+ redisProperties.getPort(), redisProperties.getConnectionTimeout(),
+ redisProperties.getSoTimeout(), redisProperties.getPassword(),
+ redisProperties.getDatabase(), redisProperties.getClientName(),
+ redisProperties.isSsl(), redisProperties.getSslSocketFactory(),
+ redisProperties.getSslParameters(), redisProperties.getHostnameVerifier());
}
}
}