From c0ea9b4b5a2fa8d7932aad386f13b239064bd2e1 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Mon, 4 Jul 2022 11:33:17 +0800 Subject: [PATCH] =?UTF-8?q?add=20reverse:for=20v1.0.1=20=E6=9E=81=E5=85=89?= =?UTF-8?q?=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 5 ++++- go.sum | 6 ++++++ hdl/jg_push.go | 17 +++++++++++------ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 3343900..b6419cd 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,7 @@ module code.fnuoos.com/go_rely_warehouse/zyos_go_jg_push.git go 1.15 -require github.com/syyongx/php2go v0.9.7 +require ( + github.com/syyongx/php2go v0.9.7 + github.com/tidwall/gjson v1.14.1 +) diff --git a/go.sum b/go.sum index 6ba1677..c7570e6 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,8 @@ github.com/syyongx/php2go v0.9.7 h1:boZtLbm2xYbW49mX9M7Vq2zkVhBhv3fCqs2T16d2bGA= github.com/syyongx/php2go v0.9.7/go.mod h1:meN2eIhhUoxOd2nMxbpe8g6cFPXI5O9/UAAuz7oDdzw= +github.com/tidwall/gjson v1.14.1 h1:iymTbGkQBhveq21bEvAQ81I0LEBork8BFe1CUZXdyuo= +github.com/tidwall/gjson v1.14.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= +github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= +github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= +github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= diff --git a/hdl/jg_push.go b/hdl/jg_push.go index 09d49e3..71d36db 100644 --- a/hdl/jg_push.go +++ b/hdl/jg_push.go @@ -7,12 +7,13 @@ import ( "errors" "fmt" "github.com/syyongx/php2go" + "github.com/tidwall/gjson" ) -func Send(appKey, appSecret string, param md.PushParam) (interface{}, error) { +func Send(appKey, appSecret string, param md.PushParam) (string, error) { if appKey == "" || appSecret == "" { - return nil, errors.New("配置未设置") + return "", errors.New("配置未设置") } url := "https://api.jpush.cn/v3/push" var iosAlert = md.PushIosAlert{Title: param.Title, Body: param.Content} @@ -54,12 +55,16 @@ func Send(appKey, appSecret string, param md.PushParam) (interface{}, error) { } b, err := json.Marshal(req) if err != nil { - return nil, err + return "", err } res, err := jg_push_utils.CurlPost(url, b, headers) if err != nil { - return nil, err + return "", err } - fmt.Println(res) - return res, nil + fmt.Println(string(res)) + msgId := gjson.Get(string(res), "msg_id").String() + if msgId == "0" || msgId == "" { + return "", err + } + return msgId, nil }