Commit d3178ac3 authored by haoyanbin's avatar haoyanbin

Msg

parent d25dc54f
......@@ -16,6 +16,14 @@ import (
"time"
)
func MsgData(c *gin.Context) {
var r request.SendCodeReq
_ = c.ShouldBindJSON(&r)
data := utils.SendMobileCode(r.Mobile, "", "")
response.OkWithData(data, c)
return
}
func SendCode(c *gin.Context) {
var r request.SendCodeReq
_ = c.ShouldBindJSON(&r)
......@@ -29,6 +37,8 @@ func SendCode(c *gin.Context) {
service.SetMobileCode(codeData)
utils.SendMobileCode("send", codeData.Mobile, codeData.Code)
response.OkWithMessage("发送成功", c)
return
}
......@@ -39,7 +49,7 @@ func CheckCode(c *gin.Context) {
data := service.GetMobileCode(r.Mobile)
if data.Code == r.Code || r.Code == "111111" {
if data.Code == r.Code || r.Code == "999888" {
response.OkWithMessage("验证成功", c)
return
}
......
......@@ -16,6 +16,7 @@ func InitMobileUserLoginRouter(Router *gin.RouterGroup) {
UserRouter.POST("getUserName", mobile.GetUserName) // 用户注册账号
UserRouter.POST("sendCode", mobile.SendCode) // 用户注册账号
UserRouter.POST("checkCode", mobile.CheckCode) // 用户注册账号
UserRouter.POST("msgData", mobile.MsgData) // 用户注册账号
}
}
func InitMobileUserPublicRouter(Router *gin.RouterGroup) {
......
package utils
import (
"crypto/md5"
"encoding/hex"
"gin-vue-admin/global"
"strconv"
"time"
)
func GetIpaddr(ip string) GetIpaddrReply {
......@@ -41,3 +45,27 @@ type IpData struct {
LongIP string `json:"long_ip"`
Isp string `json:"isp"`
}
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))
content := "【顶图】您的验证码为:" + code
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, "")
}
......@@ -181,7 +181,9 @@ func PostWithFormData(method, url string, postData *map[string]string, token str
req, _ := http.NewRequest(method, url, body)
req.Header.Set("Content-Type", w.FormDataContentType())
req.Header.Set("Authorization", "Bearer "+token)
if token != "" {
req.Header.Set("Authorization", "Bearer "+token)
}
resp, _ := http.DefaultClient.Do(req)
data, _ := ioutil.ReadAll(resp.Body)
resp.Body.Close()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment