- mobile sms verify added.
This commit is contained in:
38
business/jxcallback/auth/mobile/mobile.go
Normal file
38
business/jxcallback/auth/mobile/mobile.go
Normal file
@@ -0,0 +1,38 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user