|
|
@@ -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);
|
|
|
+ }
|
|
|
+}
|