You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.2 KiB
57 lines
1.2 KiB
package message
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"math/rand"
|
|
"recook/internal/cache"
|
|
"recook/internal/dbc"
|
|
"recook/internal/v2/lib/back"
|
|
"recook/internal/v2/lib/common"
|
|
"recook/internal/v2/model/recook/user"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type Message struct {
|
|
}
|
|
|
|
func (m *Message) SendDestroyMessage(c *gin.Context) {
|
|
id, _ := common.GetAppUserId(c)
|
|
|
|
var u user.RecookUserInfoModel
|
|
if err := dbc.DB.Table(u.TableName()).Where("id = ?", id).First(&u).Error; err != nil {
|
|
back.Err(c, err.Error())
|
|
return
|
|
}
|
|
|
|
randString := fmt.Sprintf("%04v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000))
|
|
request := ReturnRequest(u.Mobile, randString)
|
|
response, err := Client.ProcessCommonRequest(request)
|
|
if err != nil {
|
|
back.Err(c, err.Error())
|
|
return
|
|
}
|
|
|
|
if response.IsSuccess() {
|
|
cache.SetUserDestroySMSCode(u.Id, randString)
|
|
|
|
var p AliResp
|
|
if err = json.Unmarshal(response.GetHttpContentBytes(), &p); err != nil {
|
|
back.Err(c, err.Error())
|
|
return
|
|
}
|
|
if p.Message != "OK" {
|
|
back.Err(c, "短信发送失败"+p.Message)
|
|
return
|
|
}
|
|
|
|
back.Suc(c, "发送成功", nil)
|
|
} else {
|
|
back.Err(c, "短信发送失败")
|
|
}
|
|
|
|
return
|
|
}
|