Kaynağa Gözat

分享微信支持

gaodm 5 yıl önce
ebeveyn
işleme
258cd5b900

+ 9 - 5
zzcx-service/src/main/java/com/diagbot/web/WeXinJsSdkController.java

@@ -1,11 +1,12 @@
 package com.diagbot.web;
 
+import com.diagbot.dto.RespDTO;
 import io.swagger.annotations.Api;
 import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 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;
@@ -21,34 +22,37 @@ import javax.servlet.http.HttpServletRequest;
 @AllArgsConstructor
 @RestController
 @Api(value = "微信验证", tags = { "微信验证API" })
+@SuppressWarnings("unchecked")
+@Slf4j
 @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) {
+    public RespDTO<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;
+            log.info("createJsapiSignature被调用了~~~");
+            return RespDTO.onSuc(wxJsapiSignature);
         } catch (WxErrorException e) {
             return null;
         }
     }
 
     @RequestMapping(value = "/ticket", method = RequestMethod.GET)
-    public String wxjsapiTicket(HttpServletRequest request, @PathVariable String appid) {
+    public RespDTO<String> wxjsapiTicket(HttpServletRequest request, @PathVariable String appid) {
         if (!this.wxMpService.switchover(appid)) {
             throw new IllegalArgumentException(String.format("未找到对应appid=[%s]的配置,请核实!", appid));
         }
 
         try { // 直接调用wxMpServer 接口
             String jsapiTicket = wxMpService.getJsapiTicket();
-            return jsapiTicket;
+            return RespDTO.onSuc(jsapiTicket);
         } catch (WxErrorException e) {
             return null;
         }