From c24e00868b97e410da7163a48d3b545ab93706ee Mon Sep 17 00:00:00 2001 From: herenshan112 Date: Wed, 3 Nov 2021 11:31:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/curlGetPost.go | 19 +++++++++++++++ config/configType.go | 8 +++++++ config/workWechatConfig.go | 26 ++++++++++++++++++++ config/workWechatUrl.go | 1 + controller/shiyan.go | 36 ++++++++++++++++++++++++++++ handlecontroller/handleController.go | 7 ++++++ iniconfig/wechatApiUrl.ini | 1 + iniconfig/workWechatConfig.ini | 14 +++++++++++ route/apiRoute.go | 4 ++-- runtime/log/2021_10/2021_10_25.txt | 26 ++++++++++++++++++++ runtime/log/2021_11/2021_11_01.txt | 4 ++++ 11 files changed, 144 insertions(+), 2 deletions(-) create mode 100644 common/curlGetPost.go create mode 100644 config/workWechatConfig.go create mode 100644 config/workWechatUrl.go create mode 100644 controller/shiyan.go create mode 100644 iniconfig/wechatApiUrl.ini create mode 100644 iniconfig/workWechatConfig.ini create mode 100644 runtime/log/2021_11/2021_11_01.txt diff --git a/common/curlGetPost.go b/common/curlGetPost.go new file mode 100644 index 0000000..ef0a1f9 --- /dev/null +++ b/common/curlGetPost.go @@ -0,0 +1,19 @@ +package common + +import ( + "io/ioutil" + "net/http" +) + +//Get请求 +func CurlGet(getUrl string) []byte { + client := &http.Client{} + reqest, err := http.NewRequest("GET", getUrl, nil) + if err != nil { + panic(err) + } + response, _ := client.Do(reqest) + defer response.Body.Close() + body, err := ioutil.ReadAll(response.Body) + return body +} diff --git a/config/configType.go b/config/configType.go index ddbc860..2aafda3 100644 --- a/config/configType.go +++ b/config/configType.go @@ -26,3 +26,11 @@ type redisConfig struct { Redis_Pwds string //redis密码 Redis_Db int //库 } + +//Redis配置 +type workWechatConfig struct { + ApiUrl string //企业微信接口地址 + CompanyId string //企业ID + SecretStr string //应用Secret + WeChatAgentId string //应用ID +} diff --git a/config/workWechatConfig.go b/config/workWechatConfig.go new file mode 100644 index 0000000..6ac64df --- /dev/null +++ b/config/workWechatConfig.go @@ -0,0 +1,26 @@ +package config + +import ( + "main_exam_server/loges" + + "github.com/go-ini/ini" +) + +var ( + WorkWechatInfo = &workWechatConfig{} +) + +//加载企业微信配置 +func LoadWorkWechatConfig(configPath, configName string) (err error) { + dataBaseSetUp, err := ini.Load(configPath) + if err != nil { + loges.LongInit("企业微信置加载失败!") + return err + } + err = dataBaseSetUp.Section(configName).MapTo(WorkWechatInfo) + if err != nil { + loges.LongInit("企业微信置加载失败!") + return err + } + return nil +} diff --git a/config/workWechatUrl.go b/config/workWechatUrl.go new file mode 100644 index 0000000..d912156 --- /dev/null +++ b/config/workWechatUrl.go @@ -0,0 +1 @@ +package config diff --git a/controller/shiyan.go b/controller/shiyan.go new file mode 100644 index 0000000..4da9c39 --- /dev/null +++ b/controller/shiyan.go @@ -0,0 +1,36 @@ +package controller + +import ( + "flag" + "main_exam_server/common" + "main_exam_server/config" + "main_exam_server/loges" + "net/http" + "os" +) + +var ( + wechatConfigFiles = flag.String("wechatconfigFile", "iniconfig/workWechatConfig.ini", "APP配置文件") +) + +func Shiyan(ret *http.Request) (prt common.JsonOut) { + // flag.Parse() + getdddAppConfig := config.LoadWorkWechatConfig(*wechatConfigFiles, "CompanySet") + if getdddAppConfig != nil { + loges.LongInit("App配置文件读取错误!") + os.Exit(3) + } + getddoAppConfig := config.LoadWorkWechatConfig(*wechatConfigFiles, "MailList") + if getddoAppConfig != nil { + loges.LongInit("App配置文件读取错误!") + os.Exit(3) + } + + getToken := "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=" + config.WorkWechatInfo.CompanyId + "&corpsecret=" + config.WorkWechatInfo.SecretStr + + returData := common.MapOut() + returData["alenda"] = config.WorkWechatInfo + returData["body"] = common.CurlGet(getToken) + prt.Data = returData + return +} diff --git a/handlecontroller/handleController.go b/handlecontroller/handleController.go index c421632..c6ff7a6 100644 --- a/handlecontroller/handleController.go +++ b/handlecontroller/handleController.go @@ -14,3 +14,10 @@ func GetIndexPage() http.HandlerFunc { formatter.JSON(rw, http.StatusOK, controller.Index(rep)) } } + +func GetShiYan() http.HandlerFunc { + return func(rw http.ResponseWriter, rep *http.Request) { + formatter := render.New(render.Options{IndentJSON: true}) + formatter.JSON(rw, http.StatusOK, controller.Shiyan(rep)) + } +} diff --git a/iniconfig/wechatApiUrl.ini b/iniconfig/wechatApiUrl.ini new file mode 100644 index 0000000..ba46f27 --- /dev/null +++ b/iniconfig/wechatApiUrl.ini @@ -0,0 +1 @@ +;企业微信 \ No newline at end of file diff --git a/iniconfig/workWechatConfig.ini b/iniconfig/workWechatConfig.ini new file mode 100644 index 0000000..d18fe36 --- /dev/null +++ b/iniconfig/workWechatConfig.ini @@ -0,0 +1,14 @@ +[CompanySet] +;企业ID +CompanyId = ww02f310301953277a + + +;通讯录 +[MailList] +;Secret +SecretStr = yjcQXkh6_116QKjfZfbRSyzdrFFZ9jbVlKJtL2tn3OU + +;知行学院 +[ZhixingCollege] +WeChatAgentId = 1000008 +SecretStr = YJOHrmHtvevAdctg-06TMLnPokIaLHdfrQMyQolZQC8 \ No newline at end of file diff --git a/route/apiRoute.go b/route/apiRoute.go index c46b815..7d0e940 100644 --- a/route/apiRoute.go +++ b/route/apiRoute.go @@ -7,8 +7,8 @@ import ( ) func InitRoute(m *mux.Router) { - m.HandleFunc("/", handlecontroller.GetIndexPage()).Methods("GET") //访问首页 - // m.HandleFunc("/shiyan", handlecontroller.GetShiYan()).Methods("GET") //实验室数据 + m.HandleFunc("/", handlecontroller.GetIndexPage()).Methods("GET") //访问首页 + m.HandleFunc("/shiyan", handlecontroller.GetShiYan()).Methods("GET") //实验室数据 // m.HandleFunc("/test", handlecontroller.GetShiYan()).Methods("GET") //实验室数据 // m.HandleFunc("/yesterdaypoints", handlecontroller.GetUserYesterdayIntegral()).Methods("GET") //统计员工昨天获得积分总数(测试) // m.HandleFunc("/defen", handlecontroller.GetDeFen()).Methods("GET") //统计员工昨天获得积分总数(测试) diff --git a/runtime/log/2021_10/2021_10_25.txt b/runtime/log/2021_10/2021_10_25.txt index e58d672..a01376e 100644 --- a/runtime/log/2021_10/2021_10_25.txt +++ b/runtime/log/2021_10/2021_10_25.txt @@ -1509,3 +1509,29 @@ 2021/10/25 14:58:20 runlog.go:42: 数据库配置全部加载完成! 2021/10/25 16:25:22 runlog.go:42: 启动程序,开始加载基础配置... 2021/10/25 16:25:22 runlog.go:42: app基础配置全部加载完成! +2021/10/25 16:58:57 runlog.go:42: 启动程序,开始加载基础配置... +2021/10/25 16:58:57 runlog.go:42: app基础配置全部加载完成! +2021/10/25 19:22:31 runlog.go:42: 启动程序,开始加载基础配置... +2021/10/25 19:22:31 runlog.go:42: app基础配置全部加载完成! +2021/10/25 19:26:46 runlog.go:42: 启动程序,开始加载基础配置... +2021/10/25 19:26:46 runlog.go:42: app基础配置全部加载完成! +2021/10/25 19:28:39 runlog.go:42: 启动程序,开始加载基础配置... +2021/10/25 19:28:39 runlog.go:42: app基础配置全部加载完成! +2021/10/25 19:32:33 runlog.go:42: 启动程序,开始加载基础配置... +2021/10/25 19:32:33 runlog.go:42: app基础配置全部加载完成! +2021/10/25 19:35:38 runlog.go:42: 启动程序,开始加载基础配置... +2021/10/25 19:35:38 runlog.go:42: app基础配置全部加载完成! +2021/10/25 19:36:09 runlog.go:42: 启动程序,开始加载基础配置... +2021/10/25 19:36:09 runlog.go:42: app基础配置全部加载完成! +2021/10/25 19:36:34 runlog.go:42: 启动程序,开始加载基础配置... +2021/10/25 19:36:34 runlog.go:42: app基础配置全部加载完成! +2021/10/25 19:37:50 runlog.go:42: 启动程序,开始加载基础配置... +2021/10/25 19:37:50 runlog.go:42: app基础配置全部加载完成! +2021/10/25 19:39:40 runlog.go:42: 启动程序,开始加载基础配置... +2021/10/25 19:39:40 runlog.go:42: app基础配置全部加载完成! +2021/10/25 20:03:12 runlog.go:42: 启动程序,开始加载基础配置... +2021/10/25 20:03:12 runlog.go:42: app基础配置全部加载完成! +2021/10/25 20:06:56 runlog.go:42: 启动程序,开始加载基础配置... +2021/10/25 20:06:56 runlog.go:42: app基础配置全部加载完成! +2021/10/25 20:11:30 runlog.go:42: 启动程序,开始加载基础配置... +2021/10/25 20:11:30 runlog.go:42: app基础配置全部加载完成! diff --git a/runtime/log/2021_11/2021_11_01.txt b/runtime/log/2021_11/2021_11_01.txt new file mode 100644 index 0000000..a0a603b --- /dev/null +++ b/runtime/log/2021_11/2021_11_01.txt @@ -0,0 +1,4 @@ +2021/11/01 07:51:16 runlog.go:42: 启动程序,开始加载基础配置... +2021/11/01 07:51:16 runlog.go:42: app基础配置全部加载完成! +2021/11/01 07:58:24 runlog.go:42: 启动程序,开始加载基础配置... +2021/11/01 07:58:24 runlog.go:42: app基础配置全部加载完成!