文章目录
- 短信登录获取图形验证码调用过程
- 1、输入某个要获取短信验证的电话
短信登录获取图形验证码调用过程
1、输入某个要获取短信验证的电话
调用到skin皮肤里面的sms_login里面的xml的按钮控件:
这个按钮属于点击信息在Notify里面收到:
void CSMSLoginDlg::Notify(TNotifyUI& msg)
{
if (_tcsicmp(msg.sType, _T("windowinit")) == 0)
{
this->OnPrepare(msg);
}else if(_tcsicmp(msg.sType,_T("click")) == 0){
if (msg.pSender == this->m_pBtnVerifyCode)
{
this->onBtnGetVerifyCode();
}else if(msg.pSender == this->m_pBtnLogin)
{
this->OnBtnOk();
}
else if(NULL != m_pOptSaveLoginState && msg.pSender->GetName() == m_pOptSaveLoginState->GetRelatedBtnName())
{
m_pOptSaveLoginState->Selected(!m_pOptSaveLoginState->IsSelected());
}
else
{
}
}
}
随机跳转到:onBtnGetVerifyCode接口:
void CSMSLoginDlg::onBtnGetVerifyCode()
{
if (this->m_pEditMobile == NULL)
{
return ;
}
m_pEditCode->SetEnabled(true);
//简单的手机号码验证
if(this->m_pEditMobile->GetText().GetLength() == 0){
this->ShowUserPrompt(-105240030,_T("请输入手机号"));
this->m_pEditMobile->SetFocus();
return;
}
//验证手机号码是否为数字
for(int i=0;i<m_pEditMobile->GetText().GetLength();++i){
if(m_pEditMobile->GetText().GetData()[i] < '0' || m_pEditMobile->GetText().GetData()[i] > '9'){
this->ShowUserPrompt(-105240030,_T("请输入数字手机号码"));
this->m_pEditMobile->SetFocus();
return;
}
}
tstring strCellphoneNumber = this->m_pEditMobile->GetText();
if (CAuthenManager::GetInstance()->AsyncSendSmsCheckCode(strCellphoneNumber.c_str(),this) == FALSE)
{
this->ShowUserPrompt(-105240030, _T("获取短信验证码失败,请您重试!"));
return;
}
}
在这个接口里面调用发送给服务器的异步接口CAuthenManager::GetInstance()->AsyncSendSmsCheckCode(strCellphoneNumber.c_str(),this):
//新增短信验证码验证函数
BOOL CAuthenManager::AsyncSendSmsCheckCode(const tstring& strCellPhoneNumber, void *pUserData){
TRACET();
if (m_pSdoBaseHandle == NULL)
{
TRACEE("AM -- a.s.sscc -- sbh is NULL!");
return FALSE;
}
if (strCellPhoneNumber.empty())
{
TRACEW("AM -- a.s.sscc -- cpn is empty!");
return FALSE;
}
CTimeRecorder::GetInstance()->RecordStartTime(CallInterface_SendSmsCheckCode, ::GetTickCount());
m_nLastActionId = CallInterface_SendSmsCheckCode;
SdoBase_SetUserData(m_pSdoBaseHandle, pUserData);
string strCellPhoneNumberA = StringHelper::UnicodeToANSI(strCellPhoneNumber);
std::string scene = "pc_sms";
if(CSystemUtil::SystemIsLowwerAndEqualXP()){
scene="xp_sms";
}
int nError = SdoBase_SendSms(m_pSdoBaseHandle, m_strSmsSessionKey.c_str(), strCellPhoneNumberA.c_str(), 4, scene.c_str());
if (nError != 0)
{
TRACEW(_T("AM -- a.s.sb_ss -- Failed. Error[%d]"), nError);
}
return (nError == 0);
}
随即调用**SdoBase_SendSms(m_pSdoBaseHandle, m_strSmsSessionKey.c_str(), strCellPhoneNumberA.c_str(), 4, scene.c_str())**接口:
/**短信发送
/
typedef void (SDOAPI SdoBase_SendSmsCallback)(int resultCode, const char *failReason, const char smsSessionKey, const char checkCodeUrl, int needCheckCode,int width,int height, SdoBaseHandle handle);
int SdoBase_SendSms(SdoBaseHandle handle, const char *smsSessionKey, const char phone, int smsType,const char scene=NULL);
然后收到短信验证码发送的回调函数:
/设置获取短信验证码回调
static void SDOAPI onSendSmsCallback(int resultCode, const char *failReason, const char *smsSessionKey, const char checkCodeUrl, int needCheckCode,int width,int height, SdoBaseHandle handle);
void SDOAPI CAuthenManager::onSendSmsCallback(int resultCode, const char *failReason, const char *smsSessionKey, const char *checkCodeUrl, int needCheckCode,int width,int height, SdoBaseHandle* handle)
{
TRACET();
SGetSmsCodeResult res;
res.resultCode = resultCode;
res.failReason = StringHelper::ANSIToUnicode(failReason);
res.needCheckCode = needCheckCode;
res.checkCodeUrl = checkCodeUrl;
res.width=width;
res.height=height;
m_strSmsSessionKey = smsSessionKey;//保存短信登录session
sm_pAuthenManager->NotifyLoginWnd(WM_LOGIN_GETSMSCODE_RESULT,&res,0);
}
这个时候就调用sm_pAuthenManager->NotifyLoginWnd(WM_LOGIN_GETSMSCODE_RESULT,&res,0);会向登录器发生一个WM_LOGIN_GETSMSCODE_RESULT这个消息。
void CAuthenManager::NotifyLoginWnd(int nNotifyType, void* result, void* ud)
{
TRACET();
// 全部采用PostMessage 防止阻塞认证组件中的线程
// 动态分配的内存 在相关窗口收到相应消息后再释放
switch(nNotifyType)
{
case WM_LOGIN_GET_DYNAMICKEY:
{
SGetDynamicKeyResult *pResult = new SGetDynamicKeyResult(*(SGetDynamicKeyResult*)result);
::PostMessage(this->m_hWnd, WM_LOGIN_GET_DYNAMICKEY, WPARAM(pResult), 0);
}
break;
case WM_LOGIN_AUTHEN_RESULT:
{
SAuthenResult *pResult = new SAuthenResult(*(SAuthenResult*)result);
::PostMessage(this->m_hWnd, WM_LOGIN_AUTHEN_RESULT, WPARAM(pResult), 0);
}
break;
case WM_LOGIN_AUTHEN_CONTINUE:
{
SAuthenContinue *pResult = new SAuthenContinue(*(SAuthenContinue*)result);
::PostMessage(this->m_hWnd, WM_LOGIN_AUTHEN_CONTINUE, WPARAM(pResult), 0);
}
break;
case WM_LOGIN_CHECKCODE_LOGIN_CONTINUE:
{
SCheckCodeLoginContinue *pResult = new SCheckCodeLoginContinue(*(SCheckCodeLoginContinue*)result);
::PostMessage(this->m_hWnd, WM_LOGIN_CHECKCODE_LOGIN_CONTINUE, WPARAM(pResult), 0);
}
break;
case WM_LOGIN_MOBILE_GETMOBILEVALIDATECODE_RESULT:
{
SGetMobileValidateCodeResult *pResult = new SGetMobileValidateCodeResult(*(SGetMobileValidateCodeResult*)result);
::PostMessage(this->m_hWnd, WM_LOGIN_MOBILE_GETMOBILEVALIDATECODE_RESULT, WPARAM(pResult), 0);
}
break;
case WM_LOGIN_CHECK_ACCOUNT_TYPE:
{
SAccountTypeCheckingResult *pResult = new SAccountTypeCheckingResult(*(SAccountTypeCheckingResult*)result);
::PostMessage(this->m_hWnd, WM_LOGIN_CHECK_ACCOUNT_TYPE, WPARAM(pResult), 0);
}
break;
case WM_LOGIN_UPDATE_FCM_INFO:
{
SUpdateFcmInfoResult *pResult = NULL;
if (result != NULL)
{
pResult = new SUpdateFcmInfoResult(*(SUpdateFcmInfoResult*)result);
}
::PostMessage(this->m_hWnd, WM_LOGIN_UPDATE_FCM_INFO, WPARAM(pResult), 0);
}
break;
case WM_LOGIN_GETCODEKEY_RESULT:
{
SGetCodeKeyResult *pResult = new SGetCodeKeyResult(*(SGetCodeKeyResult*)result);
::PostMessage(this->m_hWnd, WM_LOGIN_GETCODEKEY_RESULT, WPARAM(pResult), 0);
}
break;
case WM_LOGIN_GETPUSHMESSAGE_RESULT:
{
SSendPushMessageResult *pResult = new SSendPushMessageResult(*(SSendPushMessageResult*)result);
::PostMessage(this->m_hWnd, WM_LOGIN_GETPUSHMESSAGE_RESULT, WPARAM(pResult), 0);
}
break;
case WM_LOGIN_GET_ACCOUNT_INFO:
{
SGetAccountInfoResult *pResult = new SGetAccountInfoResult(*(SGetAccountInfoResult*)result);
::PostMessage(m_notifyHwnd, WM_LOGIN_GET_ACCOUNT_INFO, WPARAM(pResult), 0);
}
break;
case WM_LOGIN_GET_LOGIN_HISTORY:
{
SGetLoginHistoryResult *pResult = new SGetLoginHistoryResult(*(SGetLoginHistoryResult*)result);
::PostMessage(m_notifyHwnd, WM_LOGIN_GET_LOGIN_HISTORY, WPARAM(pResult), 0);
}
break;
case WM_LOGIN_GET_PUSHMESSAGE_STATUS:
{
SGetPushMessageStatusResult *pResult = new SGetPushMessageStatusResult(*(SGetPushMessageStatusResult*)result);
::PostMessage(this->m_hWnd, WM_LOGIN_GET_PUSHMESSAGE_STATUS, WPARAM(pResult), 0);
}
break;
case WM_LOGIN_GET_CLIENT_VKEY:
{
SGetClientVKeyResult *pResult = new SGetClientVKeyResult(*(SGetClientVKeyResult*)result);
::PostMessage(this->m_hWnd, WM_LOGIN_GET_CLIENT_VKEY, WPARAM(pResult), 0);
}
break;
case WM_LOGIN_SEND_USER_ACCOUNT:
{
SSendUserAccountResult *pResult = new SSendUserAccountResult(*(SSendUserAccountResult*)result);
::PostMessage(this->m_hWnd, WM_LOGIN_SEND_USER_ACCOUNT, WPARAM(pResult), 0);
}
break;
case WM_LOGIN_CANCEL_SEND_PUSHMESSAGE:
{
::PostMessage(this->m_hWnd, WM_LOGIN_CANCEL_SEND_PUSHMESSAGE, 0, 0);
}
break;
case WM_LOGIN_SEND_MIGU_SMS:
{
SNormalCommonResult *pResult = new SNormalCommonResult(*(SNormalCommonResult*)result);
::PostMessage(this->m_hWnd, WM_LOGIN_SEND_MIGU_SMS, WPARAM(pResult), 0);
}
break;
case WM_LOGIN_GETSMSCODE_RESULT:
{
SGetSmsCodeResult *pResult = new SGetSmsCodeResult(*(SGetSmsCodeResult*)result);
::PostMessage(this->m_hWnd, WM_LOGIN_GETSMSCODE_RESULT, WPARAM(pResult), 0);
}
break;
case WM_LOGIN_GETSMSCODEWITHCAPTCHA_RESULT:
{
SGetSmsCodeResult *pResult = new SGetSmsCodeResult(*(SGetSmsCodeResult*)result);
::PostMessage(this->m_hWnd, WM_LOGIN_GETSMSCODEWITHCAPTCHA_RESULT, WPARAM(pResult), 0);
}
break;
case WM_APPMSG_REFRESHQRCODE_NOTIFY:
{
FaceVerifyInitResult *pResult = new FaceVerifyInitResult(*(FaceVerifyInitResult*)result);
::PostMessage(this->m_notifyHwnd, WM_APPMSG_REFRESHQRCODE_NOTIFY, WPARAM(pResult), 0);
}break;
case WM_APPMSG_FACECODERESULT_NOTIFY:
{
FaceCodeResult *pResult = new FaceCodeResult(*(FaceCodeResult*)result);
::PostMessage(this->m_notifyHwnd, WM_APPMSG_FACECODERESULT_NOTIFY, WPARAM(pResult), 0);
}break;
default:
break;
}
}
根据消息id找到对应实现逻辑:
case WM_LOGIN_GETSMSCODE_RESULT:
{
SGetSmsCodeResult *pResult = new SGetSmsCodeResult(*(SGetSmsCodeResult*)result);
::PostMessage(this->m_hWnd, WM_LOGIN_GETSMSCODE_RESULT, WPARAM(pResult), 0);
}
break;
再次向窗口发送消息id为WM_LOGIN_GETSMSCODE_RESULT发送消息:随即在SMSLoginDlg短信登录界面收到这个消息id:
LRESULT CSMSLoginDlg::HandleCustomMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
bHandled = FALSE;
LRESULT lResult = 0;
switch( uMsg )
{
case WM_TIMER:
lResult = OnTimer(uMsg, wParam, lParam, bHandled);
break;
case WM_LOGIN_GET_DYNAMICKEY:
{
SGetDynamicKeyResult *pGetDynamicKeyResult = (SGetDynamicKeyResult*)wParam;
this->OnGetDynamicKeyResult(pGetDynamicKeyResult);
SAFE_DELETE(pGetDynamicKeyResult);
}
break;
case WM_LOGIN_GETSMSCODE_RESULT:
{
SGetSmsCodeResult *pSGetSmsCodeResult = (SGetSmsCodeResult*)wParam;
if(pSGetSmsCodeResult->resultCode != 0){
this->ShowUserPrompt(-105240030,pSGetSmsCodeResult->failReason);
//this->m_pEditCode->SetFocus();
return 0;
}
this->OnSGetSmsCodeResult(pSGetSmsCodeResult);
SAFE_DELETE(pSGetSmsCodeResult);
}break;
case WM_LOGIN_GETSMSCODEWITHCAPTCHA_RESULT:
{
SGetSmsCodeResult *pSGetSmsCodeResult = (SGetSmsCodeResult*)wParam;
if(pSGetSmsCodeResult->resultCode != 0){
this->ShowUserPrompt(pSGetSmsCodeResult->resultCode,pSGetSmsCodeResult->failReason);
return 0;
}
this->OnSGetSmsCodeResult(pSGetSmsCodeResult);
SAFE_DELETE(pSGetSmsCodeResult);
}
break;
case WM_LOGIN_GETSMSCODEWITHCAPTCHA_SUCCESS:
{
this->m_pEditCode->SetFocus();
//倒计时
m_nRemainTime = 60;
this->m_pBtnVerifyCode->SetVisible(false);
this->m_pLabelTimer->SetVisible(true);
TCHAR szText[10]={0};
swprintf_s(szText,_countof(szText),_T("%ds"),m_nRemainTime);
this->m_pLabelTimer->SetText(szText);
::SetTimer(m_pParentWindow->GetHWND(),IDT_REMAIN,1000,NULL);
//当弹出图形验证码时,改变了登录窗口句柄,重新还原
CAuthenManager::GetInstance()->SetLoginWndHandle(m_pParentWindow->GetHWND());
}
break;
case WM_LOGIN_AUTHEN_CONTINUE:
{
SAuthenContinue* pSdoaAuthenContinue = (SAuthenContinue*)wParam;
this->OnAuthenContinue(pSdoaAuthenContinue);
SAFE_DELETE(pSdoaAuthenContinue);
}
break;
case WM_LOGIN_AUTHEN_RESULT:
{
SAuthenResult* pSdoaAuthenResult = (SAuthenResult*)wParam;
this->OnAuthenResult(pSdoaAuthenResult);
SAFE_DELETE(pSdoaAuthenResult);
}
break;
case WM_LOGIN_UPDATE_FCM_INFO:
{
SUpdateFcmInfoResult* pSUpdateFcmInfoResult = (SUpdateFcmInfoResult*)wParam;
if(pSUpdateFcmInfoResult != NULL){
this->m_bIsNewWithFcm = pSUpdateFcmInfoResult->m_bIsNew;
}
this->m_bIsFcm=true;
this->ShowFcmDlg(pSUpdateFcmInfoResult);
SAFE_DELETE(pSUpdateFcmInfoResult);
}
break;
default:
bHandled = FALSE;
break;
}
return lResult;
}
根据消息id找到实现逻辑:
case WM_LOGIN_GETSMSCODE_RESULT:
{
SGetSmsCodeResult *pSGetSmsCodeResult = (SGetSmsCodeResult*)wParam;
if(pSGetSmsCodeResult->resultCode != 0){
this->ShowUserPrompt(-105240030,pSGetSmsCodeResult->failReason);
//this->m_pEditCode->SetFocus();
return 0;
}
this->OnSGetSmsCodeResult(pSGetSmsCodeResult);
SAFE_DELETE(pSGetSmsCodeResult);
}
break;
随后调用**this->OnSGetSmsCodeResult(pSGetSmsCodeResult);**接口:
void CSMSLoginDlg::OnSGetSmsCodeResult(SGetSmsCodeResult* pOnSGetSmsCodeResult)
{
if(pOnSGetSmsCodeResult->needCheckCode == 0){
::PostMessage(m_pParentWindow->GetHWND(),WM_LOGIN_GETSMSCODEWITHCAPTCHA_SUCCESS,0,0);
return;
}
CAuthenManager::GetInstance()->SetLoginWndHandle(m_pParentWindow->GetHWND());
SCheckCodeLoginContinue checkCodeLoginContinue;
checkCodeLoginContinue.strCheckCodeUrl=pOnSGetSmsCodeResult->checkCodeUrl;
checkCodeLoginContinue.needCheckCode=pOnSGetSmsCodeResult->needCheckCode;
checkCodeLoginContinue.height=pOnSGetSmsCodeResult->height;
checkCodeLoginContinue.width=pOnSGetSmsCodeResult->width;
checkCodeLoginContinue.type=2;
checkCodeLoginContinue.pUserData=this;
int ret = this->OnCheckCodeLoginContinue(&checkCodeLoginContinue);//验证码
if(ret != DialogResult::OK){
//当弹出图形验证码时,改变了登录窗口句柄,重新还原
CAuthenManager::GetInstance()->SetLoginWndHandle(m_pParentWindow->GetHWND());
return;
}
}
然后调用在LoginCommon.h种调用**this->OnCheckCodeLoginContinue(&checkCodeLoginContinue);**接口:
int OnCheckCodeLoginContinue(SCheckCodeLoginContinue* pSdoaCheckCodeLoginContinue)
{
if(pSdoaCheckCodeLoginContinue->pUserData != this) return -1;
if(pSdoaCheckCodeLoginContinue->needCheckCode == 4) return this->ShowGeetestCodeDlg(pSdoaCheckCodeLoginContinue);
else if(pSdoaCheckCodeLoginContinue->needCheckCode == 1){
if(pSdoaCheckCodeLoginContinue->type == 1)
return this->ShowProtectCodeDlg(pSdoaCheckCodeLoginContinue);
else if(pSdoaCheckCodeLoginContinue->type == 2)
return this->ShowCaptchaCodeDlg(pSdoaCheckCodeLoginContinue);
}
}
根据type为2调用return this->ShowCaptchaCodeDlg(pSdoaCheckCodeLoginContinue);
int ShowCaptchaCodeDlg(SCheckCodeLoginContinue* pSdoaCheckCodeLoginContinue)
{
::EnableWindow(m_pParentWindow->GetHWND(),false);
CCaptchaDlg::SetOwner(this);
int ret = CCaptchaDlg::Show(m_pParentWindow, pSdoaCheckCodeLoginContinue);
::EnableWindow(m_pParentWindow->GetHWND(),true);
this->OnModalDone(ret);
return ret;
}
最后调用CCaptchaDlg::Show(m_pParentWindow, pSdoaCheckCodeLoginContinue);接口
int CCaptchaDlg::Show(CWindowWnd* pParent, SCheckCodeLoginContinue* pSdoaCheckCodeLoginContinue)
{
TRACET();
CCaptchaDlg *pDlg = new CCaptchaDlg(pSdoaCheckCodeLoginContinue,pParent);
if (pDlg == NULL)
{
return DialogResult::Cancel;
}
pDlg->Create(pParent->GetHWND());
if (CConfigManager::GetInstance()->GetClientInfoValue(_T("ToolWindow")) == _T("True"))
{
pDlg->CenterWindow();
}
else
{
pDlg->CenterWindow();
}
CAuthenManager::GetInstance()->SetLoginWndHandle(pDlg->GetHWND());
pDlg->ShowModal();
int ret = pDlg->m_nResult;
delete pDlg;
pDlg=NULL;
return ret;
}
这样图形验证码框就显示出来了。