瀏覽代碼

mob验证码

master
huangjiajun 5 天之前
父節點
當前提交
6dddf402fd
共有 3 個文件被更改,包括 80 次插入8 次删除
  1. +3
    -0
      go.mod
  2. +6
    -8
      go.sum
  3. +71
    -0
      mob/api.go

+ 3
- 0
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


+ 6
- 8
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=


+ 71
- 0
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
}

Loading…
取消
儲存