|
@@ -0,0 +1,43 @@
|
|
|
+package com.diagbot.web;
|
|
|
+
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import me.chanjar.weixin.common.bean.WxJsapiSignature;
|
|
|
+import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
+import me.chanjar.weixin.mp.api.WxMpService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description:
|
|
|
+ * @author: gaodm
|
|
|
+ * @time: 2020/2/5 18:03
|
|
|
+ */
|
|
|
+@AllArgsConstructor
|
|
|
+@RestController
|
|
|
+@Api(value = "微信验证", tags = { "微信验证API" })
|
|
|
+@RequestMapping("jssdk/{appid}")
|
|
|
+public class WeXinJsSdkController {
|
|
|
+
|
|
|
+ private final WxMpService wxMpService;
|
|
|
+
|
|
|
+ @RequestMapping(value = "/config", method = RequestMethod.GET)
|
|
|
+ public WxJsapiSignature wxJsSdkConfig(HttpServletRequest request, @PathVariable String appid, String url) {
|
|
|
+ if (!this.wxMpService.switchover(appid)) {
|
|
|
+ throw new IllegalArgumentException(String.format("未找到对应appid=[%s]的配置,请核实!", appid));
|
|
|
+ }
|
|
|
+
|
|
|
+ try { // 直接调用wxMpServer 接口
|
|
|
+ WxJsapiSignature wxJsapiSignature = wxMpService.createJsapiSignature(url);
|
|
|
+ return wxJsapiSignature;
|
|
|
+ } catch (WxErrorException e) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|