void CAPNSClient::CheckConnectFeedback() { StopCheckConnectFeedback(); //在规定得时间内没有连上,则可能是openssl连接又出现问题,强制关闭 if (m_pFeedbackClient->GetSSLConnectStatus() == FALSE) { PUSH_SERVER_ERROR("feedback client ssl connect timeout."); m_pFeedbackClient->Close(); } }
BOOL CAPNSClient::SendPushMsgToGateway(const char* szBuf, uint32_t nBufLen) { if (m_pGatewayClient && m_pGatewayClient->GetSSLConnectStatus()) { m_pGatewayClient->SendMsgAsync(szBuf, nBufLen); } else { PUSH_SERVER_ERROR("gateway client ssl connection error, discard the msg."); } return TRUE; }
BOOL CPushServer::Start() { m_pServer->DoAccept.connect(&m_handler, &CPushServerHandler::OnAccept); m_pServer->DoClose.connect(&m_handler, &CPushServerHandler::OnClose); if (m_pServer->Bind(GetListenIP().c_str(), GetPort()) == FALSE) { PUSH_SERVER_ERROR("push server bind failed, ip: %s, port: %u.", GetListenIP().c_str(), GetPort()); return FALSE; } m_pServer->Listen(); PUSH_SERVER_DEBUG("push server start successed, ip: %s, port: %u.", GetListenIP().c_str(), GetPort()); return TRUE; }
BOOL CAPNSClient::ConnectFeedback() { BOOL bRet = FALSE; m_pFeedbackClient->DoConnect.connect(&m_feedbackhandler, &CAPNSFeedBackHandler::OnConnect); m_pFeedbackClient->DoClose.connect(&m_feedbackhandler, &CAPNSFeedBackHandler::OnClose); m_pFeedbackClient->DoException.connect(&m_feedbackhandler, &CAPNSFeedBackHandler::OnException); m_pFeedbackClient->DoRecv.connect((CBaseHandler*)&m_feedbackhandler, &CAPNSFeedBackHandler::OnRecv); m_pFeedbackClient->DoSSLConnect.connect(&m_feedbackhandler, &CAPNSFeedBackHandler::OnSSLConnect); if (m_pFeedbackClient->InitSSL(GetCertPath().c_str(), GetKeyPath().c_str(), GetKeyPassword().c_str()) == FALSE) { PUSH_SERVER_ERROR("feedback client init ssl failed."); return bRet; } if (_GetAPNSServerAddress()) { m_pFeedbackClient->ConnectAsync(GetFeedbackIP().c_str(), GetFeedbackPort()); bRet = TRUE; } return bRet; }
void CPushSessionHandler::_HandlePushMsg(const char* szBuf, int32_t nBufSize) { CPduMsg pdu_msg; if (!pdu_msg.ParseFromArray(szBuf, nBufSize)) { PUSH_SERVER_ERROR("HandlePushMsg, msg parse failed."); return; } push_session_ptr pSession = CSessionManager::GetInstance()->GetPushSessionBySockID(_GetSockID()); if (pSession == nullptr) { return; } pSession->SetHeartBeat(S_GetTickCount()); IM::Server::IMPushToUserReq msg; if (!msg.ParseFromArray(pdu_msg.Body(), pdu_msg.GetBodyLength())) { PUSH_SERVER_ERROR("HandlePushMsg, msg parse failed."); pSession->Stop(); return; } string strFlash = msg.flash(); string strUserData = msg.data(); apns_client_ptr pClient = CSessionManager::GetInstance()->GetAPNSClient(); if (pClient) { IM::Server::IMPushToUserRsp msg2; for (uint32_t i = 0; i < msg.user_token_list_size(); i++) { IM::BaseDefine::PushResult* push_result = msg2.add_push_result_list(); IM::BaseDefine::UserTokenInfo user_token = msg.user_token_list(i); if (user_token.user_type() != IM::BaseDefine::CLIENT_TYPE_IOS) { push_result->set_user_token(user_token.token()); push_result->set_result_code(1); continue; } m_NotificationID++; PUSH_SERVER_INFO("HandlePushMsg, token: %s, push count: %d, push_type:%d, notification id: %u.", user_token.token().c_str(), user_token.push_count(), user_token.push_type(), m_NotificationID); CAPNSGateWayMsg msg; msg.SetAlterBody(strFlash); msg.SetCustomData(strUserData); msg.SetDeviceToken(user_token.token()); time_t time_now = 0; time(&time_now); msg.SetExpirationDate(time_now + 3600); if (user_token.push_type() == PUSH_TYPE_NORMAL) { msg.SetSound(TRUE); } else { msg.SetSound(FALSE); } msg.SetBadge(user_token.push_count()); msg.SetNotificationID(m_NotificationID); if (msg.SerializeToArray()) { pClient->SendPushMsgToGateway(msg.Data(), msg.GetDataLength()); push_result->set_result_code(0); } else { push_result->set_result_code(1); PUSH_SERVER_WARN("HandlePushMsg, serialize CAPNSGateWayMsg failed."); } push_result->set_user_token(user_token.token()); } CPduMsg pdu_msg2; pdu_msg2.SetServiceID(IM::BaseDefine::SID_OTHER); pdu_msg2.SetCommandID(IM::BaseDefine::CID_OTHER_PUSH_TO_USER_RSP); if (pdu_msg2.SerializeToArray(&msg2)) { pSession->SendMsg(pdu_msg2.Data(), pdu_msg2.GetDataLength()); } else { PUSH_SERVER_WARN("HandlePushMsg, serialize IMPushToUserRsp failed."); } } }