- 注释掉老user与auth相关的代码
This commit is contained in:
@@ -1,104 +1,90 @@
|
||||
package mobile
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"time"
|
||||
// const (
|
||||
// DefVerifyCodeDuration = 5 * time.Minute
|
||||
// TestMobile = "91112345678"
|
||||
// TestVerifyCode = "123456"
|
||||
// )
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/auth"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
aliyunsmsclient "github.com/KenmyZhang/aliyun-communicate"
|
||||
)
|
||||
// var (
|
||||
// warningMap = map[string]int{
|
||||
// "isv.AMOUNT_NOT_ENOUGH": 1,
|
||||
// "isv.ACCOUNT_ABNORMAL": 1,
|
||||
// "isv.OUT_OF_SERVICE": 1,
|
||||
// "isv.DAY_LIMIT_CONTROL": 1,
|
||||
// }
|
||||
// )
|
||||
|
||||
const (
|
||||
DefVerifyCodeDuration = 5 * time.Minute
|
||||
TestMobile = "91112345678"
|
||||
TestVerifyCode = "123456"
|
||||
)
|
||||
// const (
|
||||
// LoginType = "mobile"
|
||||
// )
|
||||
|
||||
var (
|
||||
warningMap = map[string]int{
|
||||
"isv.AMOUNT_NOT_ENOUGH": 1,
|
||||
"isv.ACCOUNT_ABNORMAL": 1,
|
||||
"isv.OUT_OF_SERVICE": 1,
|
||||
"isv.DAY_LIMIT_CONTROL": 1,
|
||||
}
|
||||
)
|
||||
// var (
|
||||
// ErrVerifyCodeIsWrong = errors.New("验证码错")
|
||||
// )
|
||||
|
||||
const (
|
||||
LoginType = "mobile"
|
||||
)
|
||||
// type Auther struct {
|
||||
// }
|
||||
|
||||
var (
|
||||
ErrVerifyCodeIsWrong = errors.New("验证码错")
|
||||
)
|
||||
// var (
|
||||
// auther *Auther
|
||||
// )
|
||||
|
||||
type Auther struct {
|
||||
}
|
||||
// func init() {
|
||||
// auther = new(Auther)
|
||||
// auth.RegisterAuther(LoginType, auther)
|
||||
// }
|
||||
|
||||
var (
|
||||
auther *Auther
|
||||
)
|
||||
// func SendVerifyCode(mobileNumber string) error {
|
||||
// code := fmt.Sprintf("%06d", rand.Intn(1000000))
|
||||
// globals.SugarLogger.Debugf("SendVerifyCode mobileNumber:%s, code:%s", mobileNumber, code)
|
||||
|
||||
func init() {
|
||||
auther = new(Auther)
|
||||
auth.RegisterAuther(LoginType, auther)
|
||||
}
|
||||
// smsClient := aliyunsmsclient.New("http://dysmsapi.aliyuncs.com/")
|
||||
// response, err := smsClient.Execute(globals.AliKey, globals.AliSecret, mobileNumber, "京西菜市", "SMS_84655036", string(utils.MustMarshal(map[string]interface{}{
|
||||
// "code": code,
|
||||
// })))
|
||||
// api.Cacher.Set(mobileNumber, code, DefVerifyCodeDuration)
|
||||
// if err == nil && response.Code == aliyunsmsclient.ResponseCodeOk {
|
||||
// } else {
|
||||
// if err == nil {
|
||||
// if warningMap[response.Code] == 1 {
|
||||
// globals.SugarLogger.Warnf("SendVerifyCode mobileNumber:%s failed with response:%s", mobileNumber, utils.Format4Output(response, false))
|
||||
// } else {
|
||||
// globals.SugarLogger.Infof("SendVerifyCode mobileNumber:%s failed with response:%s", mobileNumber, utils.Format4Output(response, false))
|
||||
// }
|
||||
// err = fmt.Errorf("发送短信出错:%s", response.Message)
|
||||
// } else {
|
||||
// globals.SugarLogger.Warnf("SendVerifyCode mobileNumber:%s failed with error:%v", mobileNumber, err)
|
||||
// }
|
||||
// }
|
||||
// return err
|
||||
// }
|
||||
|
||||
func SendVerifyCode(mobileNumber string) error {
|
||||
code := fmt.Sprintf("%06d", rand.Intn(1000000))
|
||||
globals.SugarLogger.Debugf("SendVerifyCode mobileNumber:%s, code:%s", mobileNumber, code)
|
||||
// func VerifyCode(mobileNumber, code string) (err error) {
|
||||
// globals.SugarLogger.Debugf("VerifyCode mobileNumber:%s, code:%s", mobileNumber, code)
|
||||
|
||||
smsClient := aliyunsmsclient.New("http://dysmsapi.aliyuncs.com/")
|
||||
response, err := smsClient.Execute(globals.AliKey, globals.AliSecret, mobileNumber, "京西菜市", "SMS_84655036", string(utils.MustMarshal(map[string]interface{}{
|
||||
"code": code,
|
||||
})))
|
||||
api.Cacher.Set(mobileNumber, code, DefVerifyCodeDuration)
|
||||
if err == nil && response.Code == aliyunsmsclient.ResponseCodeOk {
|
||||
} else {
|
||||
if err == nil {
|
||||
if warningMap[response.Code] == 1 {
|
||||
globals.SugarLogger.Warnf("SendVerifyCode mobileNumber:%s failed with response:%s", mobileNumber, utils.Format4Output(response, false))
|
||||
} else {
|
||||
globals.SugarLogger.Infof("SendVerifyCode mobileNumber:%s failed with response:%s", mobileNumber, utils.Format4Output(response, false))
|
||||
}
|
||||
err = fmt.Errorf("发送短信出错:%s", response.Message)
|
||||
} else {
|
||||
globals.SugarLogger.Warnf("SendVerifyCode mobileNumber:%s failed with error:%v", mobileNumber, err)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
// err = ErrVerifyCodeIsWrong
|
||||
// if mobileNumber == TestMobile && code == TestVerifyCode {
|
||||
// err = nil
|
||||
// } else {
|
||||
// if value := api.Cacher.Get(mobileNumber); value != nil {
|
||||
// if code == value.(string) {
|
||||
// api.Cacher.Del(mobileNumber)
|
||||
// err = nil
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return err
|
||||
// }
|
||||
|
||||
func VerifyCode(mobileNumber, code string) (err error) {
|
||||
globals.SugarLogger.Debugf("VerifyCode mobileNumber:%s, code:%s", mobileNumber, code)
|
||||
// func (a *Auther) Login(mobileNum, verifyCode string) (userID, LoginType string, err error) {
|
||||
// if err = VerifyCode(mobileNum, verifyCode); err == nil {
|
||||
// _, err = dao.GetWeiXinUserByIDs(dao.GetDB(), mobileNum, "", "", "")
|
||||
// err = auth.ConvertErr2NoUser(err, mobileNum)
|
||||
// }
|
||||
// return "", "", err
|
||||
// }
|
||||
|
||||
err = ErrVerifyCodeIsWrong
|
||||
if mobileNumber == TestMobile && code == TestVerifyCode {
|
||||
err = nil
|
||||
} else {
|
||||
if value := api.Cacher.Get(mobileNumber); value != nil {
|
||||
if code == value.(string) {
|
||||
api.Cacher.Del(mobileNumber)
|
||||
err = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *Auther) Login(mobileNum, verifyCode string) (userID, LoginType string, err error) {
|
||||
if err = VerifyCode(mobileNum, verifyCode); err == nil {
|
||||
_, err = dao.GetWeiXinUserByIDs(dao.GetDB(), mobileNum, "", "", "")
|
||||
err = auth.ConvertErr2NoUser(err, mobileNum)
|
||||
}
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
func (a *Auther) Logout(loginInfo *auth.LoginInfo) error {
|
||||
return nil
|
||||
}
|
||||
// func (a *Auther) Logout(loginInfo *auth.LoginInfo) error {
|
||||
// return nil
|
||||
// }
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
package mobile
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSendVerifyCode(t *testing.T) {
|
||||
err := SendVerifyCode("18180948107")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
// func TestSendVerifyCode(t *testing.T) {
|
||||
// err := SendVerifyCode("18180948107")
|
||||
// if err != nil {
|
||||
// t.Fatal(err)
|
||||
// }
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user