From 6dddf402fd6abd2a5a4c539cf162de059001c085 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Tue, 17 Dec 2024 10:27:04 +0800 Subject: [PATCH] =?UTF-8?q?mob=E9=AA=8C=E8=AF=81=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 3 +++ go.sum | 14 +++++------ mob/api.go | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 8 deletions(-) create mode 100644 mob/api.go diff --git a/go.mod b/go.mod index 6cbd25c..d40a6a1 100644 --- a/go.mod +++ b/go.mod @@ -17,6 +17,7 @@ require ( github.com/olivere/elastic/v7 v7.0.32 github.com/shopspring/decimal v1.3.1 github.com/syyongx/php2go v0.9.8 + github.com/tidwall/gjson v1.18.0 go.uber.org/zap v1.16.0 gopkg.in/natefinch/lumberjack.v2 v2.2.1 xorm.io/xorm v1.3.1 @@ -37,6 +38,8 @@ require ( github.com/mailru/easyjson v0.7.7 // indirect github.com/nxadm/tail v1.4.8 // indirect github.com/pkg/errors v0.9.1 // indirect + github.com/tidwall/match v1.1.1 // indirect + github.com/tidwall/pretty v1.2.0 // indirect github.com/tjfoc/gmsm v1.4.1 // indirect golang.org/x/net v0.23.0 // indirect golang.org/x/tools v0.9.1 // indirect diff --git a/go.sum b/go.sum index fd8298c..0610063 100644 --- a/go.sum +++ b/go.sum @@ -1,13 +1,5 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241211055111-7c47b67b46d2 h1:g4zWPWExuZAG8nTmkcSJnTbxKhz5B+VANCWEsJOMGXg= -code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241211055111-7c47b67b46d2/go.mod h1:+bDK4gfBq4LEkhh6K/A46+0urH/sgxDxnjIjlxb9HI8= -code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241212120727-3681308aeb14 h1:pmSd/GlPECRYCcVKZWPuC1NksGsjUwwUZ7yctmDgP70= -code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241212120727-3681308aeb14/go.mod h1:+bDK4gfBq4LEkhh6K/A46+0urH/sgxDxnjIjlxb9HI8= -code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241214031442-d77dffce2625 h1:MdAv5hY6sB8tQ8paY5fhPnz7tdHsv3shbwgyRumbL+c= -code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241214031442-d77dffce2625/go.mod h1:+bDK4gfBq4LEkhh6K/A46+0urH/sgxDxnjIjlxb9HI8= -code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241214062221-cde2ce240fa8 h1:QTviY49R4NDgw47ZUNnn8yJwGevl+C6/PX4Nqsi9J3c= -code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241214062221-cde2ce240fa8/go.mod h1:+bDK4gfBq4LEkhh6K/A46+0urH/sgxDxnjIjlxb9HI8= code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241214095356-fdac2df9537f h1:MS7l8BLTEjKGXVzuej78I7IPollXFGzYCLfLJTLGlV4= code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241214095356-fdac2df9537f/go.mod h1:+bDK4gfBq4LEkhh6K/A46+0urH/sgxDxnjIjlxb9HI8= code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.1-0.20241118083738-0f22da9ba0be h1:zuleX5JnIGQpt6wDAmCFs++lLgOmE6kWo3xkJnjrSck= @@ -442,6 +434,12 @@ github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFd github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= github.com/syyongx/php2go v0.9.8 h1:FNwV1y+RaZxl7KTm/ICh0Zrhca/70d5JRMpwByuQ1FM= github.com/syyongx/php2go v0.9.8/go.mod h1:meN2eIhhUoxOd2nMxbpe8g6cFPXI5O9/UAAuz7oDdzw= +github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY= +github.com/tidwall/gjson v1.18.0/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= github.com/tjfoc/gmsm v1.3.2/go.mod h1:HaUcFuY0auTiaHB9MHFGCPx5IaLhTUd2atbCFBQXn9w= github.com/tjfoc/gmsm v1.4.1 h1:aMe1GlZb+0bLjn+cKTPEvvn9oUEBlJitaZiiBwsbgho= github.com/tjfoc/gmsm v1.4.1/go.mod h1:j4INPkHWMrhJb38G+J6W4Tw0AbuN8Thu3PbdVYhVcTE= diff --git a/mob/api.go b/mob/api.go new file mode 100644 index 0000000..611a5cd --- /dev/null +++ b/mob/api.go @@ -0,0 +1,71 @@ +package mob + +import ( + utils "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils" + "errors" + "fmt" + "github.com/tidwall/gjson" +) + +func MobSms(key, phone, templateCode string) error { + where := make(map[string]interface{}) + + send := "" + var err error + where = map[string]interface{}{ + "appkey": key, + "zone": "86", + "phone": phone, + "templateCode": templateCode, + } + send, err = SmsMobApiSend(where) + if err != nil { + return err + } + status := gjson.Get(send, "status").Int() + msg := gjson.Get(send, "error").String() + if status == 471 { + return errors.New("发送的ip不在白名单中") + } + if status == 406 { + return errors.New("appkey不存在") + } + if status != 200 { + return errors.New(msg) + } + return nil +} +func MobSMSCheck(key, phone, captcha string) (bool, error) { + // mob 的短信验证 + // https://www.mob.com/wiki/detailed/?wiki=SMSSDK_for_yanzhengmafuwuduanxiaoyanjiekou&id=23 + url := "https://webapi.sms.mob.com/sms/verify" + args := map[string]string{ + "phone": phone, + "zone": "86", + "code": captcha, + } + args["appkey"] = key + // 发送请求 + respBody, err := utils.CurlPost(url, args, nil) + if err != nil { + fmt.Println(err) + return false, err + } + code := gjson.GetBytes(respBody, "status").Int() + if code == 468 { + return false, errors.New("验证码错误") + } + if code != 200 { + utils.FilePutContents("sms", string(respBody)) + return false, errors.New("验证码错误~") + } + return true, nil +} + +func SmsMobApiSend(args map[string]interface{}) (string, error) { + thisUrl := "https://webapi.sms.mob.com/sms/sendmsg" + post, err := utils.CurlPost(thisUrl, args, nil) + fmt.Println(string(post)) + fmt.Println(err) + return string(post), err +}