package mobile import ( "errors" "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/business/auth2" "git.rosy.net.cn/jx-callback/business/auth2/authprovider" "git.rosy.net.cn/jx-callback/globals" "github.com/KenmyZhang/aliyun-communicate" ) const ( AuthType = auth2.AuthTypeMobile TestVerifyCode = "123456" ) var ( ErrVerifyCodeIsWrong = errors.New("验证码错") ) type Auther struct { authprovider.DefAuther } var ( AutherObj *Auther ) func init() { AutherObj = new(Auther) auth2.RegisterAuther(AuthType, AutherObj) } // 特殊接口 func (a *Auther) SendVerifyCode(mobileNumber string) error { code := a.GenerateVerifyCode(mobileNumber) smsClient := aliyunsmsclient.New("http://dysmsapi.aliyuncs.com/") _, err := smsClient.Execute(globals.AliKey, globals.AliSecret, mobileNumber, "京西菜市", "SMS_84655036", string(utils.MustMarshal(map[string]interface{}{ "code": code, }))) if err == nil { a.SaveVerifyCode(mobileNumber, code) } else { globals.SugarLogger.Infof("SendVerifyCode mobileNumber:%s failed with error:%v", mobileNumber, err) } return err } func (a *Auther) VerifySecret(mobileNumber, code string) (authBindEx *auth2.AuthBindEx, err error) { globals.SugarLogger.Debugf("VerifySecret mobileNumber:%s, code:%s", mobileNumber, code) err = ErrVerifyCodeIsWrong if (auth2.TestMobileMap[mobileNumber] == 1 && code == TestVerifyCode) || a.VerifyCode(mobileNumber, code) { err = nil } return nil, err } // 此函数为空 func (a *Auther) AddAuthBind(authBindEx *auth2.AuthBindEx, userName string) (err error) { return err } // 此函数为空 func (a *Auther) UnbindAuth(authInfo *auth2.AuthInfo, authType string) (err error) { return err }