Browse Source

加入图片和文字检测

master v0.4.9
listen 3 years ago
parent
commit
bd48d1cc30
4 changed files with 81 additions and 3 deletions
  1. +1
    -0
      go.mod
  2. +2
    -0
      go.sum
  3. +47
    -3
      security_check.go
  4. +31
    -0
      security_check_test.go

+ 1
- 0
go.mod View File

@ -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


+ 2
- 0
go.sum View File

@ -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=


+ 47
- 3
security_check.go View File

@ -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
}

+ 31
- 0
security_check_test.go View File

@ -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)
}

Loading…
Cancel
Save