fllmoyu 4 gadi atpakaļ
vecāks
revīzija
418024e94b

+ 1 - 0
web/src/main/java/com/jpsoft/enterprise/config/WebMvcConfig.java

@@ -70,6 +70,7 @@ public class WebMvcConfig implements WebMvcConfigurer {
 				.excludePathPatterns("/mobile/companyInfoApi/attributeList")
 				.excludePathPatterns("/mobile/companyInfoApi/industryList")
 				.excludePathPatterns("/mobile/enterpriseInfoApi/enterpriseInfo")
+				.excludePathPatterns("/mobile/wechat/getConfig")
         ;
 	}
 }

+ 62 - 0
web/src/main/java/com/jpsoft/enterprise/modules/wechat/controller/WxController.java

@@ -0,0 +1,62 @@
+package com.jpsoft.enterprise.modules.wechat.controller;
+
+import com.jpsoft.enterprise.config.WxConfig;
+import com.jpsoft.enterprise.modules.common.dto.MessageResult;
+import com.jpsoft.enterprise.modules.common.utils.Sign;
+import com.jpsoft.enterprise.modules.common.utils.WeixinUtil;
+import com.jpsoft.enterprise.modules.wechat.entity.AccessToken;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author 墨鱼_mo
+ * @date 2021-1-6 17:21
+ */
+@Slf4j
+@RequestMapping("/wechat")
+@RestController
+public class WxController {
+
+
+    @Autowired
+    private WxConfig wxConfig;
+
+    @ApiOperation(value = "获取微信配置")
+    @GetMapping(value = "/getConfig")
+    public MessageResult getConfig(String url) {
+
+        int code = 200;
+        String message = "获取成功";
+        Object data = "";
+        boolean result = true;
+
+        try {
+            AccessToken token = WeixinUtil.getAccessToken(wxConfig.getAppId(), wxConfig.getAppSecret());
+
+            Map<String, String> wxMap = Sign.sign(WeixinUtil.getJsAPI(token.getToken()), url);
+
+            wxMap.put("appId", wxConfig.getAppId());
+
+            HashMap<String, Object> dataMap = new HashMap<String, Object>();
+
+            dataMap.put("wxConfig", wxMap);
+
+            data = dataMap;
+        } catch (Exception ex) {
+            log.error(ex.getMessage(),ex);
+
+            code = 500;
+            result = false;
+            message = "系统错误";
+        }
+
+        return new MessageResult(result, message, data, code);
+    }
+}