From 6d4d0994b4bbeca0148613684d9fe3e9303de36f Mon Sep 17 00:00:00 2001 From: zhangyuxiang <1323804152@qq.com> Date: Thu, 4 Jun 2026 17:52:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AE=89=E4=BF=A1=E5=BC=A0?= =?UTF-8?q?=E5=AE=B6=E5=8F=A39=E6=A1=A59=E9=9A=A7=E9=A1=B9=E7=9B=AEes?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- consumers/consumerZWYHBJCAS.go | 5 +++-- dbOperate/httpHelper.go | 38 ++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/consumers/consumerZWYHBJCAS.go b/consumers/consumerZWYHBJCAS.go index 2fa7d91..4960865 100644 --- a/consumers/consumerZWYHBJCAS.go +++ b/consumers/consumerZWYHBJCAS.go @@ -75,6 +75,7 @@ func (the *consumerZWYHBJCAS) InputInitial() error { the.ch = make(chan []adaptors.NeedPush, 200) //数据入口 the.InHttp = &dbOperate.HttpHelper{Url: the.Info.IoConfig.In.Http.Url, Token: ""} + the.InHttp.InitialWithTls() the.InKafka = _kafka.KafkaHelper{ Brokers: the.Info.IoConfig.In.Kafka.Brokers, GroupId: the.Info.IoConfig.In.Kafka.GroupId, @@ -184,7 +185,7 @@ func (the *consumerZWYHBJCAS) getEs1HourAggData() { for _, factorId := range hourFactorIds { esQuery := the.getESQueryStrByHour(structId, factorId, start, end) auth := map[string]string{"Authorization": "Bear 85a441d4-022b-4613-abba-aaa8e2693bf7"} - esAggResultStr := the.InHttp.HttpGetWithHeader(esQuery, auth) + esAggResultStr := the.InHttp.HttpGetWithHeaderWithTLS(esQuery, auth) adaptor := the.getAdaptor() adaptor.PointInfo = the.Info.PointInfo @@ -212,7 +213,7 @@ func (the *consumerZWYHBJCAS) getEs10minAggData() { for _, factorId := range factorIds { esQuery := the.getESQueryStrBy10min(structId, factorId, start, end) auth := map[string]string{"Authorization": "Bear 85a441d4-022b-4613-abba-aaa8e2693bf7"} - esAggResultStr := the.InHttp.HttpGetWithHeader(esQuery, auth) + esAggResultStr := the.InHttp.HttpGetWithHeaderWithTLS(esQuery, auth) adaptor := the.getAdaptor() adaptor.PointInfo = the.Info.PointInfo diff --git a/dbOperate/httpHelper.go b/dbOperate/httpHelper.go index 0b82989..9c7c410 100644 --- a/dbOperate/httpHelper.go +++ b/dbOperate/httpHelper.go @@ -26,6 +26,14 @@ func (the *HttpHelper) Initial() { the.client.Timeout = time.Minute } + +func (the *HttpHelper) InitialWithTls() { + the.client = http.Client{} + //取消证书校验,避免证书过期问题 + the.client.Transport = &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}} + the.client.Timeout = time.Minute +} + func (the *HttpHelper) HttpGet(queryBody string) string { url := the.Url client := the.client @@ -40,6 +48,34 @@ func (the *HttpHelper) HttpGet(queryBody string) string { body, err := io.ReadAll(resp.Body) return string(body) } +func (the *HttpHelper) HttpGetWithHeaderWithTLS(queryBody string, headerMap map[string]string) string { + url := the.Url + client := the.client + req, err := http.NewRequest("GET", url, strings.NewReader(queryBody)) + req.Header.Set("Content-Type", "application/json") + + for k, v := range headerMap { + req.Header.Set(k, v) + } + + resp, err := client.Do(req) + if err != nil { + log.Printf("查询esproxy 异常=>%s", err.Error()) + return "" + } + defer func(resp *http.Response) { + if resp != nil && resp.Body != nil { + errClose := resp.Body.Close() + if errClose != nil { + log.Printf("关闭异常") + } + } + }(resp) + log.Println("http get 请求,url", url, " <- code=", resp.StatusCode) + body, err := io.ReadAll(resp.Body) + return string(body) +} + func (the *HttpHelper) HttpGetWithHeader(queryBody string, headerMap map[string]string) string { url := the.Url client := the.client @@ -49,6 +85,7 @@ func (the *HttpHelper) HttpGetWithHeader(queryBody string, headerMap map[string] for k, v := range headerMap { req.Header.Set(k, v) } + //取消证书校验,避免证书过期问题 client.Transport = &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}} @@ -69,6 +106,7 @@ func (the *HttpHelper) HttpGetWithHeader(queryBody string, headerMap map[string] body, err := io.ReadAll(resp.Body) return string(body) } + func (the *HttpHelper) Publish(messageBytes []byte) (string, error) { url := the.Url client := the.client