Commit d3178ac3 authored by haoyanbin's avatar haoyanbin

Msg

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