From b6542bf42ae74fb77b63cf3e1f0ca33dbe7ea7d7 Mon Sep 17 00:00:00 2001 From: taoshihan1991 <630892807@qq.com> Date: Tue, 9 Feb 2021 10:10:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=8E=A8=E9=80=81token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/shout.go | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/controller/shout.go b/controller/shout.go index d95c638..d8e6899 100644 --- a/controller/shout.go +++ b/controller/shout.go @@ -44,7 +44,6 @@ func SendAppGetuiPush(kefu string, title, content string) { return } } - appid := models.FindConfig("GetuiAppID") format := ` { "request_id":"%s", @@ -74,15 +73,31 @@ func SendAppGetuiPush(kefu string, title, content string) { for _, client := range clients { //clientIds = append(clientIds, client.Client_id) req := fmt.Sprintf(format, tools.Md5(tools.Uuid()), client.Client_id, title, content) - url := "https://restapi.getui.com/v2/" + appid + "/push/single/cid" - headers := make(map[string]string) - headers["Content-Type"] = "application/json;charset=utf-8" - headers["token"] = token - res, err := tools.PostHeader(url, []byte(req), headers) - log.Println(url, req, err, res) + num := sendPushApi(token, req) + if num == 10001 { + token = getGetuiToken() + sendPushApi(token, req) + } } } +func sendPushApi(token string, req string) int { + appid := models.FindConfig("GetuiAppID") + url := "https://restapi.getui.com/v2/" + appid + "/push/single/cid" + headers := make(map[string]string) + headers["Content-Type"] = "application/json;charset=utf-8" + headers["token"] = token + res, err := tools.PostHeader(url, []byte(req), headers) + log.Println(url, req, err, res) + if err == nil && res != "" { + var pushRes GetuiResponse + json.Unmarshal([]byte(res), &pushRes) + if pushRes.Code == 10001 { + return 10001 + } + } + return 200 +} func getGetuiToken() string { appid := models.FindConfig("GetuiAppID") appkey := models.FindConfig("GetuiAppKey")