This commit is contained in:
邹宗楠
2022-08-25 17:07:23 +08:00
parent 561c92b528
commit 771c01585b

View File

@@ -1,5 +1,17 @@
package app_server package app_server
import (
"errors"
"fmt"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-print/globals"
"git.rosy.net.cn/jx-print/putils"
"git.rosy.net.cn/jx-print/services/api"
aliyunsmsclient "github.com/KenmyZhang/aliyun-communicate"
"math/rand"
"time"
)
type SendVerifyCode struct { type SendVerifyCode struct {
} }
@@ -7,44 +19,43 @@ var SendVerifyCodeServer = new(SendVerifyCode)
// SendCode 获取手机短信验证码 // SendCode 获取手机短信验证码
func (s *SendVerifyCode) SendCode(mobile string) (string, error) { func (s *SendVerifyCode) SendCode(mobile string) (string, error) {
//// 获取code // 获取code
//smsCode := fmt.Sprintf("%06d", rand.Intn(1000000)) smsCode := fmt.Sprintf("%06d", rand.Intn(1000000))
//
//// 发送短信 // 发送短信
//response, err := api.SMSClient.Execute(globals.AliKey, globals.AliSecret, mobile, globals.SmsSignName, globals.SmsMobileVerifyTemplate, string(utils.MustMarshal(map[string]interface{}{ response, err := api.SMSClient.Execute(globals.AliKey, globals.AliSecret, mobile, globals.SmsSignName, globals.SmsMobileVerifyTemplate, string(utils.MustMarshal(map[string]interface{}{
// "code": smsCode, "code": smsCode,
//}))) })))
//
//if err != nil { if err != nil {
// return "", err return "", err
//} }
//if response.Code != aliyunsmsclient.ResponseCodeOk { if response.Code != aliyunsmsclient.ResponseCodeOk {
// return "", fmt.Errorf("发送短信出错:%s", response.Message) return "", fmt.Errorf("发送短信出错:%s", response.Message)
//} }
//
//if err := putils.SetKey(response.BizId+"_"+mobile, smsCode, time.Minute*2); err != nil { if err := putils.SetKey(response.BizId+"_"+mobile, smsCode, time.Minute*2); err != nil {
// globals.SugarLogger.Debugf("redis set key err key[%s] value[%s]:", mobile, smsCode) globals.SugarLogger.Debugf("redis set key err key[%s] value[%s]:", mobile, smsCode)
// return "", err return "", err
//} }
//
//return response.BizId, nil return response.BizId, nil
return "111111", nil
} }
// VerifySecret 检查验证码 // VerifySecret 检查验证码
func (s *SendVerifyCode) VerifySecret(mobile, bizId, code string) (bool, error) { func (s *SendVerifyCode) VerifySecret(mobile, bizId, code string) (bool, error) {
//result := putils.GetKey(bizId + "_" + mobile) result := putils.GetKey(bizId + "_" + mobile)
//fmt.Println(utils.IsNil(result)) fmt.Println(utils.IsNil(result))
//fmt.Println(result) fmt.Println(result)
//if utils.IsNil(result) || result == "" || result == nil { if utils.IsNil(result) || result == "" || result == nil {
// return false, errors.New("验证码过期") return false, errors.New("验证码过期")
//} }
//
//if result.(string) != code { if result.(string) != code {
// return false, errors.New("验证码错误,重新确认") return false, errors.New("验证码错误,重新确认")
//} }
//
//defer putils.DelKey(bizId + "_" + mobile) defer putils.DelKey(bizId + "_" + mobile)
return true, nil return true, nil
} }