common_api.go 1.58 KB
Newer Older
haoyanbin's avatar
1  
haoyanbin committed
1 2 3
package utils

import (
haoyanbin's avatar
haoyanbin committed
4 5
	"crypto/md5"
	"encoding/hex"
haoyanbin's avatar
1  
haoyanbin committed
6
	"gin-vue-admin/global"
haoyanbin's avatar
haoyanbin committed
7 8
	"strconv"
	"time"
haoyanbin's avatar
1  
haoyanbin committed
9 10 11 12 13
)

func GetIpaddr(ip string) GetIpaddrReply {
	url := global.GVA_CONFIG.Ipaddr.Url

haoyanbin's avatar
1  
haoyanbin committed
14 15
	data := map[string]string{}
	data["ip"] = ip
haoyanbin's avatar
1  
haoyanbin committed
16

haoyanbin's avatar
1  
haoyanbin committed
17
	resp := GetIpaddrPostUrl(url, data, global.GVA_CONFIG.Ipaddr.Appcode, 1)
haoyanbin's avatar
1  
haoyanbin committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

	reply := new(GetIpaddrReply)

	UnserislizeJson(resp, reply)

	return *reply
}

type GetIpaddrReq struct {
	Ip string `json:"ip"`
}
type GetIpaddrReply struct {
	Code   int    `json:"code"`
	Msg    string `json:"msg"`
	TaskNo string `json:"taskNo"`
	Data   IpData `json:"data"`
}

type IpData struct {
	Country   string `json:"country"`
	CountryID string `json:"country_id"`
	Area      string `json:"area"`
	Region    string `json:"region"`
	RegionID  string `json:"region_id"`
	City      string `json:"city"`
	CityID    string `json:"city_id"`
	IP        string `json:"ip"`
	LongIP    string `json:"long_ip"`
	Isp       string `json:"isp"`
}
haoyanbin's avatar
haoyanbin committed
48 49 50 51 52 53 54 55 56

func SendMobileCode(action, mobile, code string) string {
	url := "http://39.101.175.217:8088" + "/v2sms.aspx"
	nowtime := strconv.FormatInt(time.Now().Unix(), 10)

	h := md5.New()
	h.Write([]byte("dthydthy12345" + nowtime))
	sign := hex.EncodeToString(h.Sum(nil))

haoyanbin's avatar
1  
haoyanbin committed
57
	content := "【顶图DR】您的验证码为:" + code
haoyanbin's avatar
haoyanbin committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71

	postData := make(map[string]string)
	postData["action"] = action
	postData["rt"] = "json"
	postData["userid"] = "47"
	postData["timestamp"] = nowtime
	postData["sign"] = string(sign)
	postData["mobile"] = mobile
	postData["content"] = content
	postData["sendTime"] = ""
	postData["extno"] = ""

	return PostWithFormData("POST", url, &postData, "")
}