From 077a56b53ea7e1ae76221d3acd1209085cea5c1d Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 3 Apr 2019 16:02:15 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E6=A3=80=E6=9F=A5=E5=8F=91=E9=80=81?= =?UTF-8?q?=E7=9F=AD=E4=BF=A1=E7=BB=93=E6=9E=9C=EF=BC=8C=E5=87=BA=E9=94=99?= =?UTF-8?q?=E6=8A=A5=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/auth2/authprovider/mobile/mobile.go | 27 +++++++++++++++++--- business/jxcallback/auth/mobile/mobile.go | 26 ++++++++++++++++--- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/business/auth2/authprovider/mobile/mobile.go b/business/auth2/authprovider/mobile/mobile.go index bf13cedcc..193861264 100644 --- a/business/auth2/authprovider/mobile/mobile.go +++ b/business/auth2/authprovider/mobile/mobile.go @@ -2,12 +2,13 @@ package mobile import ( "errors" + "fmt" "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" + aliyunsmsclient "github.com/KenmyZhang/aliyun-communicate" ) const ( @@ -15,6 +16,15 @@ const ( TestVerifyCode = "123456" ) +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("验证码错") ) @@ -36,13 +46,22 @@ func init() { 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{}{ + response, err := smsClient.Execute(globals.AliKey, globals.AliSecret, mobileNumber, "京西菜市", "SMS_84655036", string(utils.MustMarshal(map[string]interface{}{ "code": code, }))) - if err == nil { + if err == nil && response.Code == aliyunsmsclient.ResponseCodeOk { a.SaveVerifyCode(mobileNumber, code) } else { - globals.SugarLogger.Infof("SendVerifyCode mobileNumber:%s failed with error:%v", mobileNumber, err) + 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 } diff --git a/business/jxcallback/auth/mobile/mobile.go b/business/jxcallback/auth/mobile/mobile.go index 341f7cafc..7b0d90bc7 100644 --- a/business/jxcallback/auth/mobile/mobile.go +++ b/business/jxcallback/auth/mobile/mobile.go @@ -11,7 +11,7 @@ import ( "git.rosy.net.cn/jx-callback/business/model/dao" "git.rosy.net.cn/jx-callback/globals" "git.rosy.net.cn/jx-callback/globals/api" - "github.com/KenmyZhang/aliyun-communicate" + aliyunsmsclient "github.com/KenmyZhang/aliyun-communicate" ) const ( @@ -20,6 +20,15 @@ const ( TestVerifyCode = "123456" ) +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 ( LoginType = "mobile" ) @@ -45,13 +54,22 @@ func SendVerifyCode(mobileNumber string) error { globals.SugarLogger.Debugf("SendVerifyCode mobileNumber:%s, code:%s", mobileNumber, code) smsClient := aliyunsmsclient.New("http://dysmsapi.aliyuncs.com/") - _, err := smsClient.Execute(globals.AliKey, globals.AliSecret, mobileNumber, "京西菜市", "SMS_84655036", string(utils.MustMarshal(map[string]interface{}{ + response, err := smsClient.Execute(globals.AliKey, globals.AliSecret, mobileNumber, "京西菜市", "SMS_84655036", string(utils.MustMarshal(map[string]interface{}{ "code": code, }))) - if err == nil { + if err == nil && response.Code == aliyunsmsclient.ResponseCodeOk { api.Cacher.Set(mobileNumber, code, DefVerifyCodeDuration) } else { - globals.SugarLogger.Infof("SendVerifyCode mobileNumber:%s failed with error:%v", mobileNumber, err) + 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 }