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 }