配置文件的读取:
<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”):