From bd48d1cc303246930cc8802a3d9cc2b461ed66d9 Mon Sep 17 00:00:00 2001 From: listen <494177603@qq.com> Date: Wed, 1 Dec 2021 20:56:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E5=9B=BE=E7=89=87=E5=92=8C?= =?UTF-8?q?=E6=96=87=E5=AD=97=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 1 + go.sum | 2 ++ security_check.go | 50 +++++++++++++++++++++++++++++++++++++++--- security_check_test.go | 31 ++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 security_check_test.go diff --git a/go.mod b/go.mod index c7966ff..c0d65ba 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.14 require ( git.tetele.net/tgo/conf v0.39.3 git.tetele.net/tgo/crypter v0.2.2 + git.tetele.net/tgo/helper v0.2.6 github.com/chai2010/protorpc v1.0.0 github.com/golang/protobuf v1.0.0 golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 // indirect diff --git a/go.sum b/go.sum index 64a88aa..2181e0d 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,8 @@ git.tetele.net/tgo/conf v0.39.3 h1:yjeJKmOHMJUeRl5Q3FVCLjIdIcor7UkohycyM87cGng= git.tetele.net/tgo/conf v0.39.3/go.mod h1:AWVIBEDE5dtotthUgR0SWaR2Qa6/f+O5WQ3s7Tj8q7A= git.tetele.net/tgo/crypter v0.2.2 h1:YMQJh2Gj5Po4ZfelJUmXBKi01UbmtiSy3bmqRfnYQMo= git.tetele.net/tgo/crypter v0.2.2/go.mod h1:vfvRLZA8+lHNgNXneOcgvVhDyuv25ZRb+C6xHOmXNx0= +git.tetele.net/tgo/helper v0.2.6 h1:JC+N+If/bGvcwuUSklva17YDNtKBV2Qpvl5RQpMySOY= +git.tetele.net/tgo/helper v0.2.6/go.mod h1:89mQwyfqZ+t8YXiVwzSxA70gLlUNqoZGDEUxvV46jXk= github.com/chai2010/protorpc v1.0.0 h1:aJ45G9sl1utSKo35EqnBSTs5jqTpdJDJAuZMMYPAtFo= github.com/chai2010/protorpc v1.0.0/go.mod h1:woR3WwjaQDqFjlzdVsFEKiK5Ur12QL8mYxVPjfr5z54= github.com/golang/protobuf v1.0.0 h1:lsek0oXi8iFE9L+EXARyHIjU5rlWIhhTkjDz3vHhWWQ= diff --git a/security_check.go b/security_check.go index b2d3825..550336c 100644 --- a/security_check.go +++ b/security_check.go @@ -2,12 +2,13 @@ package weixinrpc import ( "encoding/json" - "strconv" - "time" "git.tetele.net/tgo/crypter" "github.com/golang/protobuf/proto" + "strconv" + "time" ) +//检测图片是否合法 func ImgSecCheck(appId, appSecret,imgUrl string, url ...string) (error) { conn, err := rpc_server_conn(url...) @@ -42,7 +43,7 @@ func ImgSecCheck(appId, appSecret,imgUrl string, url ...string) (error) { res := &Response{} - err = conn.GetMiniappQrcode(req, res) + err = conn.ImgSecCheck(req, res) if err != nil { return err @@ -51,3 +52,46 @@ func ImgSecCheck(appId, appSecret,imgUrl string, url ...string) (error) { return nil } + +//检测文本是否合法 +func MsgSecCheck(appId, appSecret string,checkData map[string]interface{}, url ...string)error{ + conn, err := rpc_server_conn(url...) + if err != nil { + return err + } + defer conn.Close() + + data := map[string]interface{}{} + data["app_id"] = appId + data["app_secret"] = appSecret + data["check_data"] = checkData + + data_json, err := json.Marshal(data) + if err != nil { + return err + } + + encryData := crypter.DesEn(string(data_json), DES_KEY) + + now_int64 := time.Now().Unix() + + now := strconv.FormatInt(now_int64, 10) + + sign := Sign(encryData, now) + + req := &Request{ + proto.String(encryData), + proto.String(now), + proto.String(sign), + nil} + + res := &Response{} + + err = conn.MsgSecCheck(req, res) + + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/security_check_test.go b/security_check_test.go new file mode 100644 index 0000000..bb63f86 --- /dev/null +++ b/security_check_test.go @@ -0,0 +1,31 @@ +package weixinrpc + +import ( + "git.tetele.net/tgo/helper" + "testing" +) + +func Test_CheckImg(t *testing.T){ + appid := "wx3d53ccbaf69f7995" + appSecret := "165983626235636be54a16404e3e70a7" + imgUrl := helper.TencentCloudImageCompress("https://images-1306193253.cos.ap-guangzhou.myqcloud.com/uploads/20211026/1635213788c5713f49816c74a0e130694ed6544e71.jpg","450") + //imgUrl := "https://images-1306193253.cos.ap-guangzhou.myqcloud.com/uploads/20211026/1635213788c5713f49816c74a0e130694ed6544e71.jpg" + err := ImgSecCheck(appid,appSecret,imgUrl) + + t.Log(err) +} + + +func Test_CheckMsg(t *testing.T){ + appid := "wx3d53ccbaf69f7995" + appSecret := "165983626235636be54a16404e3e70a7" + checkData := map[string]interface{}{ + "openid":"oLBHE4kRuj8ywGKuXMgLbmFKrdkM", + "scene":3, + "content":"", + } + + err := MsgSecCheck(appid,appSecret,checkData) + + t.Log(err) +} \ No newline at end of file