1、### Jslogin模塊與前端以及JsLogin模塊與Sdologin的交互
配置文件的讀取:
<CompanyIdForQq value="301"/> <CompanyIdForWx value="300"/><CompanyIdForWb value="302"/><qq value="https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=101531594&redirect_uri=https://mygm.sdo.com/v1/oauth/authorize&state=qq" /><wx value="https://open.weixin.qq.com/connect/qrconnect?response_type=code&scope=snsapi_login&appid=wxa0ef5c72c3732d26&redirect_uri=https://mygm.sdo.com/v1/oauth/authorize&state=wx#wechat_redirect" /><wb value="https://api.weibo.com/oauth2/authorize?client_id=3349601784&redirect_uri=https://mygm.sdo.com/v1/oauth/authorize&state=wb" />
假設url:
https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=101531594&redirect_uri=https://mygm.sdo.com/v1/oauth/authorize&state=qq
然后代碼里面調用:
tstring qq_url = CConfigManager::GetInstance()->GetClientInfoValue(L"qq");
最后被轉義,所以url要被設定為:
https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=101531594&redirect_uri=https://mygm.sdo.com/v1/oauth/authorize&state=qq
與前端交互接口的注冊:
SystemAction::SystemAction()
{TRACET();m_mapFunctions["Minimize"] = &SystemAction::Minimize;m_mapFunctions["Close"] = &SystemAction::Close;m_mapFunctions["Login"] = &SystemAction::Login;m_mapFunctions["IeResize"] = &SystemAction::IeResize;m_mapFunctions["CloseAgreementIE"] = &SystemAction::CloseAgreementIE;m_mapFunctions["OpenAgreementIE"] = &SystemAction::OpenAgreementIE;m_mapFunctions["IeWResize"] = &SystemAction::IeWResize;m_mapFunctions["IeHResize"] = &SystemAction::IeResize;m_mapFunctions["OpenShunWangloginIE"] = &SystemAction::OpenShunWangloginIE;m_mapFunctions["CloseShunWangloginIE"]= &SystemAction::CloseShunWangloginIE;m_mapFunctions["CloseAreaSetting"] = &SystemAction::CloseAreaSetting;m_mapFunctions["IeHReset"] = &SystemAction::IeHReset;m_mapFunctions["FeiHuoLoginResult"] = &SystemAction::FeiHuoLoginResult;m_mapFunctions["onCommonGeetestResult"] = &SystemAction::onCommonGeetestResult;//三方打開ie關閉ie/*m_mapFunctions["OpenThirdloginIE"] = &SystemAction::OpenThirdloginIE;*/m_mapFunctions["CloseThirdloginIE"]= &SystemAction::CloseThirdloginIE;通知前端登錄器調用//m_mapFunctions["NotifyThirdlogin"]= &SystemAction::NotifyThirdlogin;m_mapFunctions["IsThirdLogin"]= &SystemAction::IsThirdLogin;
}
與前端交互接口定義:
HRESULT SystemAction::CloseThirdloginIE( DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, unsigned int* puArgErr,EXCEPINFO* pInternalExcepInfo)
{TRACET();ThirdloginReq request;request.m_flag = 0;LPWSTR _ticket = pDispParams->rgvarg[0].bstrVal;wcsncpy_s(request.ticket, _ticket, _countof(request.ticket)-1);if(!CJsLoginExternal::GetInstance()->SendMessage(&request)){TRACEW(_T("Send CloseThirdloginIE failed."));return S_FALSE;}//MessageRsp response;//if(!CJsLoginExternal::GetInstance()->WaitResponse(&request, &response, DEFAULT_TIMEOUT))//{// TRACEW(_T("Send CloseShunWangloginIE timeout"));// return S_FALSE;//}return S_OK;
}
獲取前端JS代碼調用接口傳過來的參數:
然后使用CJsLoginExternal::GetInstance()->SendMessage(&request)把消息發送給SdoLogin:
case SDOL_CMD_THIRD_DIALOG_REQ:return new ThirdloginReq();
LRESULT CSDOLApp::OnThirdDialogLogin(WPARAM wParam, LPARAM lParam)
{TRACET();ThirdloginReq* pReq = (ThirdloginReq*)wParam;ASSERT_RETURN_VALUE(pReq, -1);wchar_t* ticket = pReq->ticket;//m_flag為0時候可以驗證QQ登錄if (pReq->m_flag == 0){CDataReportMaker::GetInstance()->OnCollecUserOperated("0x018");tstring phone, smsCode;CAuthenManager::GetInstance()->AsyncForThirdLogin(StringHelper::Format(ticket),all_commpany_id, phone, smsCode,"1");//區分老舊版本:extend=1表示新版本if(GetIetDlg()){GetIetDlg()->OnBtnClose();}HWND hwd = CSDOLApp::GetInstance()->GetGameWnd();ShowWindow(hwd,SW_RESTORE);}m_LoginModule.SendSimpleResponse(pReq, 0);return 0;
}
JsLogin模塊參數傳給前端:
HRESULT SystemAction::IsThirdLogin(DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, unsigned int* puArgErr,EXCEPINFO* pInternalExcepInfo)
{TRACET();pVarResult->vt = VT_BOOL;pVarResult->boolVal = True;return S_OK;
}
前端調用JsLogin模塊方法:web頁面是在相同的瀏覽器環境內打開的 向這個環境內注入了方法是可以在拿到三方返回的code之后前端通過該方法把code傳遞給JsLogin模塊的。
當出現問題根據調試工具調試:
根據傳給前端的參數為false:
然后調用System.Action.CloseThirdLoginIE(“ticket”):