📄 appserver.cpp
字号:
// AppServer.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "AppServer.h"
#include "AppServerDlg.h"
#include "adpcmdll.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAppServerApp
BEGIN_MESSAGE_MAP(CAppServerApp, CWinApp)
//{{AFX_MSG_MAP(CAppServerApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAppServerApp construction
CAppServerApp::CAppServerApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CAppServerApp object
CAppServerApp theApp;
HANDLE ghUniqueEvent;
/////////////////////////////////////////////////////////////////////////////
// CAppServerApp initialization
BOOL CAppServerApp::InitInstance()
{
//禁止AppServer在同一台电脑中运行两个以上实例
ghUniqueEvent = ::CreateEvent(NULL, TRUE, TRUE, _T("HXD AppServer Running"));
if (::GetLastError() == ERROR_ALREADY_EXISTS)
{
AfxMessageBox(_T("应用业务服务器已运行中! 不能同时运行两个实例!"));
return FALSE;
}
AfxOleInit();
if (!AfxSocketInit())
{
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
return FALSE;
}
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
m_pIconList[0] = LoadIcon (MAKEINTRESOURCE(IDR_MAINFRAME));
m_pIconList[1] = LoadIcon (MAKEINTRESOURCE(IDR_MAINFRAME));
m_pIconList[2] = LoadIcon (MAKEINTRESOURCE(IDR_MAINFRAME));
this->ProcessINIFile ();
ConnectDatabase();
iBegin=0;
long lpServerThreadID;
if((m_htProcessMo=::CreateThread((LPSECURITY_ATTRIBUTES)NULL,(DWORD)0,
(LPTHREAD_START_ROUTINE)ProcessMo,NULL,
(DWORD)0,(LPDWORD)&lpServerThreadID))==NULL)
AfxMessageBox("创建线程失败!");
/* if((m_htProcessCheckCallOut=::CreateThread((LPSECURITY_ATTRIBUTES)NULL,(DWORD)0,
(LPTHREAD_START_ROUTINE)ProcessCheckCallOut,NULL,
(DWORD)0,(LPDWORD)&lpServerThreadID))==NULL)
AfxMessageBox("创建线程失败!");
*/
CAppServerDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
::CloseHandle(ghUniqueEvent);
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
void ProcessCheckCallOut()
{
_RecordsetPtr m_pRecordset;
m_pRecordset.CreateInstance(_uuidof(Recordset));
CAppServerApp *pApp=(CAppServerApp*)AfxGetApp();
_variant_t TheValue;
CString sql,str,strTime;
while(1 && pApp->iBegin==1)
{
CTime time=CTime::GetCurrentTime();
strTime.Format ("%d-%d-%d %d:%d",time.GetYear(),time.GetMonth(),time.GetDay(),time.GetHour(),time.GetMinute ());
sql.Format("proc_TimeCallOut '%s'",strTime);
try{
m_pRecordset->Open(_variant_t(sql),(IDispatch*)pApp->m_pConnection,
adOpenDynamic,adLockOptimistic, adCmdText);
if(!m_pRecordset->EndOfFile)
{
CString caller,called;
CString namepath,filepath,str;
short suc=m_pRecordset->GetCollect ("sucess").intVal;
if (suc==0)
goto monext;
caller=(CString)m_pRecordset->GetCollect ("caller").intVal;
called=(CString)m_pRecordset->GetCollect ("called").intVal;
namepath=m_pRecordset->GetCollect ("namepath").bstrVal;
filepath=m_pRecordset->GetCollect ("filepath").bstrVal;
((CAppServerDlg * )pApp->m_pMainWnd)->SendCallOut(caller,called,-1);
str.Format("发现点歌任务:'%s'-->'%s','%s'",caller,called,strTime);
((CAppServerDlg * )pApp->m_pMainWnd)->AddListMessage(1,str);
goto monext;
}
}
catch (_com_error err)
{
pApp->EventLog(err.ErrorMessage ());
goto monext;
}
monext:
Sleep(500);
}
}
void CAppServerApp::ProcessINIFile()
{
char sBuffer[400];
CFileStatus rStatus;
if (CFile::GetStatus(_T("system.ini"), rStatus) == TRUE)
{
::GetCurrentDirectory(400, sBuffer);
::lstrcat(sBuffer, _T("\\system.ini"));
free((void*)m_pszProfileName);
m_pszProfileName = _tcsdup(sBuffer);
}
strDataServer=GetProfileString(_T("DataBase"), _T("server"), _T(""));
strUser=GetProfileString(_T("DataBase"), _T("username"), _T("sa"));
strPwd=GetProfileString(_T("DataBase"), _T("password"), _T(""));
//CFileStatus rStatus;
//CHAR sBuffer[400];
//检查当前路径有没有AppServer.ini,如果有,从中读取配置信息.否则,从系统路径中读
if (CFile::GetStatus(_T("AppServer.ini"), rStatus) == TRUE)
{
::GetCurrentDirectory(400, sBuffer);
::lstrcat(sBuffer, _T("\\AppServer.ini"));
free((void*)m_pszProfileName); //释放掉已经分配的内存
m_pszProfileName = _tcsdup(sBuffer); //字符串拷贝
}
//读取配置信息
m_sHXDIpAddress = GetProfileString(_T("Network"), _T("HXD_IP"), _T("200.200.200.6"));
m_nHXDPort = GetProfileInt(_T("Network"), _T("HXD_PORT"), 6003);
m_sAppIpAddress = GetProfileString(_T("Network"), _T("APP_IP"), _T("200.200.200.6"));
m_nAppPort = GetProfileInt(_T("Network"), _T("APP_PORT"), 6005);
//m_sAppIpAddress="127.0.0.1";
strcpy(lmsg.lw1,GetProfileString(_T("SengMsg"), _T("leaveWord1"), _T("")));
strcpy(lmsg.lw2,GetProfileString(_T("SengMsg"), _T("leaveWord2"), _T("")));
strcpy(lmsg.lw3,GetProfileString(_T("SengMsg"), _T("leaveWord3"), _T("")));
strcpy(lmsg.lw4,GetProfileString(_T("SengMsg"), _T("leaveWord4"), _T("")));
CString str;
/*
for(int i=0;i<8;i++)
{
str.Format ("%d",i+1);
strcpy(operInfo[i].desc,GetProfileString(_T("operdesc"), _T(str), _T("")));
strcpy(operInfo[i].spnumber,GetProfileString(_T("spnumber"), _T(str), _T("")));
}
*/
spCode=GetProfileInt(_T("system"), _T("spcode"), 0);
loginMode=GetProfileInt(_T("system"), _T("LoginMode"), 1);///1--提示 2--直接
iTtsMode=GetProfileInt(_T("system"), _T("ttsmode"), 0);///0--呼叫完成以后计费 1--直接
////mtcode
strcpy(mtcode.leaveMsg,GetProfileString(_T("MtCode"), _T("leaveSendMsg"), _T("0000")));
strcpy(mtcode.RecordBack,GetProfileString(_T("MtCode"), _T("recordback"), _T("0000")));
strcpy(mtcode.orderSong,GetProfileString(_T("MtCode"), _T("ordersong"), _T("0000")));
sZeroCode=GetProfileString(_T("MtCode"), _T("zerocode"), _T("0000"));
strTTSSp=GetProfileString(_T("smsg"), _T("tts"), _T(""));
strTTSSet=GetProfileString(_T("smsg"), _T("ttsn"), _T(""));
iTTSCode=GetProfileInt(_T("smsg"), _T("ttscode"), 0);
strCaiHua=GetProfileString(_T("smsg"), _T("caihua"), _T(""));
strLiaotian=GetProfileString(_T("smsg"), _T("liaotian"), _T(""));
}
void CAppServerApp::ConnectDatabase()
{
HRESULT hr;
CString str;
str.Format("driver={SQL Server};Server=%s;DATABASE=JSLT;UID=%s;PWD=%s"
,strDataServer,strUser,strPwd);
//str.Format("driver={SQL Server};Server=61.240.111.24,1433;DATABASE=unionsphz;UID=hzCTI;PWD=hzCTI");
try
{
hr = m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象
//int ii=GetLastError();
hr = m_pConnection->Open(_bstr_t(str),"","",-1);///连接数据库
}
catch(_com_error e)///捕捉异常
{
CString str;
str=e.ErrorMessage ();
AfxMessageBox("数据库连接失败! "+str);
}
ReadParam();
}
int CAppServerApp::ExitInstance()
{
try {
if (m_pConnection !=NULL)
m_pConnection->Close();
}
catch(...){}
///jTTS_End();
return CWinApp::ExitInstance();
}
BOOL CAppServerApp::SQLEXEC(CString str)
{
_variant_t RecordsAffected;
try{
m_pConnection->Execute(_bstr_t(str),&RecordsAffected,adCmdText) ;
}
catch(_com_error err)
{
EventLog(err.ErrorMessage ());
return false;
}
return true;
}
void CAppServerApp::EventLog(CString str)
{
CString str1;
CTime time=CTime::GetCurrentTime ();
str1.Format ("\r\n %4d年%2d月%2d日%2d时%2d分%2d秒 %s",time.GetYear (),
time.GetMonth (),time.GetDay (),time.GetHour (),time.GetMinute ()
,time.GetSecond (),str);
//#ifdef _DEBUG
TRACE(str1);
//#endif
int fh;
CFile file;
CString strfn= "dbevent.log";
fh=file.Open(strfn, CFile::modeReadWrite | CFile::shareDenyRead);/////
if(!fh)
{
fh=file.Open(strfn, CFile::modeWrite|CFile::modeCreate | CFile::shareDenyRead);
if(fh)
{
file.SeekToEnd( );
file.Write(str1,str1.GetLength());
file.Close ();
}
}
else
{
file.SeekToEnd( );
file.Write(str1,str1.GetLength ());
file.Close();
}
}
//DEL BOOL CAppServerApp::RegisterUser(CString strTel, int oper, int type)
//DEL {
//DEL
//DEL }
//DEL BOOL CAppServerApp::InitTTS()
//DEL {
//DEL ERRCODE err;
//DEL err = jTTS_Init(g_szInitPath, g_szSerialNo);
//DEL if(err != ERR_NONE)
//DEL {
//DEL ErrorMessage(err);
//DEL return FALSE;
//DEL }
//DEL
//DEL // 预载当前音色
//DEL jTTS_PreLoad(g_config.szVoiceID);
//DEL
//DEL // 设置当前属性
//DEL jTTS_Set(&g_config);
//DEL
//DEL // 设置显示串
//DEL UpdateVoiceInfoString();
//DEL
//DEL return TRUE;
//DEL }
//DEL void CAppServerApp::SetDefaultConfig()
//DEL {
//DEL g_config.nCodePage =CODEPAGE_GB;
//DEL g_config.nDigitMode = 0;
//DEL g_config.nEngMode = 0;
//DEL g_config.nPitch = 5;
//DEL g_config.nSpeed = 5;
//DEL g_config.nVolume = 5;
//DEL g_config.nPuncMode = 0;
//DEL
//DEL g_config.wVersion = JTTS_VERSION4;
//DEL g_config.nDomain = 0;
//DEL g_config.nTagMode = 0;
//DEL
//DEL g_config.nVoiceStyle = 1;
//DEL g_config.nBackAudio = 0;
//DEL g_config.nBackAudioVolume = 50;
//DEL g_config.wBackAudioFlag = 0;
//DEL
//DEL g_config.nVoiceBufSize = 0;
//DEL g_config.nInsertInfoSize = 0;
//DEL
//DEL g_bCallbackFunc = 0;
//DEL g_bCallbackHwnd = 0;
//DEL
//DEL /* CString strTmp;
//DEL strTmp = GetProfileString("Init", "szInitPath");
//DEL strcpy(g_szInitPath, strTmp);
//DEL
//DEL strTmp = GetProfileString("Init", "szSerialNo");
//DEL strcpy(g_szSerialNo, strTmp);
//DEL
//DEL ;
//DEL */
//DEL strcpy(g_config.szVoiceID, "93A47B28-FE41-4e99-9458-7A781484A467");
//DEL }
int GetOperFromSpnumber(CString strSp)
{
CAppServerApp *pApp=(CAppServerApp*)AfxGetApp();
CString str;
for(int i=0;i<8;i++)
{
str=pApp->operInfo[i].SSpnumber;
if(strSp.Left(str.GetLength())==str) break;
str=pApp->operInfo[i].SSpnumber1;
if(strSp.Left(str.GetLength())==str) break;
}
if(i==8) return 0;
return i+1;
}
CString GetUserID(CString strTel)
{
_RecordsetPtr m_pRecordset;
m_pRecordset.CreateInstance(_uuidof(Recordset));
CAppServerApp *pApp=(CAppServerApp*)AfxGetApp();
_variant_t TheValue;
CString str;
str.Format ("proc_GetUserInfo '%s'",strTel);
try{
m_pRecordset->Open(_variant_t(str),(IDispatch*)pApp->m_pConnection,
adOpenDynamic,adLockOptimistic, adCmdText);
if(!m_pRecordset->EndOfFile)
{
str=m_pRecordset->GetCollect ("userid").bstrVal;
return str;
}
}
catch (_com_error err)
{
pApp->EventLog(err.ErrorMessage ());
return "";
}
return "";
}
BOOL GetSongInfo(CString strsong,char *namepath,char *filepath)
{
_RecordsetPtr m_pRecordset;
m_pRecordset.CreateInstance(_uuidof(Recordset));
CAppServerApp *pApp=(CAppServerApp*)AfxGetApp();
_variant_t TheValue;
CString str;
str.Format ("proc_GetSongInfo '%s'",strsong);
try{
m_pRecordset->Open(_variant_t(str),(IDispatch*)pApp->m_pConnection,
adOpenDynamic,adLockOptimistic, adCmdText);
if(!m_pRecordset->EndOfFile)
{
str=m_pRecordset->GetCollect ("namepath").bstrVal;
strcpy(namepath,str);
str=m_pRecordset->GetCollect ("filepath").bstrVal;
strcpy(filepath,str);
return TRUE;
}
}
catch (_com_error err)
{
pApp->EventLog(err.ErrorMessage ());
return FALSE;
}
return FALSE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -