39 lines
952 B
Go
39 lines
952 B
Go
package mobile
|
|
|
|
import (
|
|
"fmt"
|
|
"math/rand"
|
|
"time"
|
|
|
|
"git.rosy.net.cn/baseapi/utils"
|
|
"git.rosy.net.cn/jx-callback/globals"
|
|
"github.com/KenmyZhang/aliyun-communicate"
|
|
)
|
|
|
|
const (
|
|
DefVerifyCodeDuration = 5 * time.Minute
|
|
)
|
|
|
|
func SendVerifyCode(mobileNumber string) error {
|
|
smsClient := aliyunsmsclient.New("http://dysmsapi.aliyuncs.com/")
|
|
code := fmt.Sprintf("%06d", rand.Intn(1000000))
|
|
_, err := smsClient.Execute(globals.AliKey, globals.AliSecret, mobileNumber, "京西菜市", "SMS_84655036", string(utils.MustMarshal(map[string]interface{}{
|
|
"code": code,
|
|
})))
|
|
if err == nil {
|
|
globals.Cacher.Set(mobileNumber, code, DefVerifyCodeDuration)
|
|
}
|
|
// globals.SugarLogger.Debug(utils.Format4Output(result, false))
|
|
return err
|
|
}
|
|
|
|
func VerifyCode(mobileNumber, code string) bool {
|
|
if value := globals.Cacher.Get(mobileNumber); value != nil {
|
|
if code == value.(string) {
|
|
globals.Cacher.Del(mobileNumber)
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|