⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 0000thread.cpp

📁 关于联通的一个统一定制程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// 0000Thread.cpp: implementation of the C0000Thread class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "0000Thread.h"
#include "ParseHelper.h"
#include "servicelist.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

IMPLEMENT_DYNCREATE(C0000Thread, CWinThread)

C0000Thread::C0000Thread()
{
}

C0000Thread::~C0000Thread()
{
}

BOOL C0000Thread::InitInstance()
{
	// TODO:  perform and per-thread initialization here
	return TRUE;
}

int C0000Thread::ExitInstance()
{
	// TODO:  perform any per-thread cleanup here
	return CWinThread::ExitInstance();
}

BEGIN_MESSAGE_MAP(C0000Thread, CWinThread)
	//{{AFX_MSG_MAP(C0000Thread)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// C0000Thread message handlers

int C0000Thread::Run()
{
	IOD_Info info;	

	while (!theData.m_bServiceExit)
	{
		if (theData.Get0000Msg(&info))
		{
			if (Work(&info))
			{
			}
		}
		else
			Sleep(1);
	}
	
	return CWinThread::Run();
}

BOOL C0000Thread::Work(LPIOD_Info pIOD)
{
	m_Info.szMobile=pIOD->szDestMobile;
	m_Db.GetCommonInfo(&m_Info);

	CString strSubId(pIOD->szSubID),strMsg,strTemp,strGwId(pIOD->szSrcGWID),strContent;
	int iRet=-1;
	int uId=-1;

	if (strSubId.CompareNoCase("IUNKNOW")==0)
	{
	//	strcpy(pIOD->szSubID, pIOD->szContent);
	//	strcpy(pIOD->szContent, "");
	//	strSubId=pIOD->szSubID;	
		strSubId=pIOD->szContent;
	}
	
	strSubId.MakeUpper();

	if (strSubId == "00000")	// 取消所有定制
		H00000(pIOD);
//	else if ((strSubId.Left(5)=="00000")&&(strSubId.GetLength()>5))	// 1860代为取消所有定制
//		H1860_00000(pIOD);
	else if (strSubId == "0000")	// 查询定制列表
		H0000(pIOD);
//	else if ((strSubId.Left(4)=="0000")&&
//		    (strSubId.GetLength()>4)&&
//			(strSubId.Left(5)!="00000")&&
//			(strcmp(pIOD->szSrcGWID,"0008")==0))	// 浙江_1860_代为查询定制列表
//		H1860_571_0000(pIOD);
//	else if ((strSubId.Left(4)=="0000")&&(strSubId.GetLength()>4)&&(strSubId.Left(5)!="00000"))	// 1860代为查询定制列表
//		H1860_0000(pIOD);
//	else if (CParseHelper::IsQX_ID_MobilePhone(strSubId,uId,strTemp))
//	{
//		if(uId==0)
//			H1860_00000(pIOD,strTemp);
//		else
//			H1860_QX(pIOD,strTemp,uId);
//	}		
	else if(strSubId.Left(1).CompareNoCase("Q")==0)
	{
		strSubId.Replace("+", " ");
		strTemp=strSubId.Mid(1);
		strTemp.TrimRight();
		strTemp.TrimLeft();
		uId=atoi(strTemp);
		if (uId==0 && !strTemp.IsEmpty())
			H00000(pIOD);
		else
			H_QX(pIOD, uId);
//		if((Is1860Allowed(pIOD->szDestMobile))&&(strGwId=="0008"))
//		{
//			// 属浙江移动1860号码,屏蔽其次功能
//			theData.SetMsg2(&m_Db,pIOD,"00000_1860_qx_invalid", NULL, &m_Info);
//			return true;
//		}

//		strSubId.Replace("+"," ");
//		strTemp=strSubId.Mid(2);
//		strTemp.TrimLeft();strTemp.TrimRight();
		
//		if(strTemp.IsEmpty())
//		{
			// 指令没有跟退定的索引,返回提示语句给用户
//			theData.SetMsg2(&m_Db,pIOD,"00000_qx_have_not_index", NULL, &m_Info);			
//			return true;
//		}
//		uId=atoi(strTemp);
//		if(uId==0)
//			H00000(pIOD);
//		else
//			H_QX(pIOD,uId);
	}
//	else if(strSubId=="013")
//	{
		//判断内容是否为QX...
//		strContent=pIOD->szContent;
//		if((strContent.Left(2).CompareNoCase("Q")==0)&&(strContent.GetLength()>1))
//		{
//			strContent.Replace("+"," ");
//			strTemp=strContent.Mid(1);
//			strTemp.TrimLeft();strTemp.TrimRight();
//			if(strTemp.IsEmpty())
//			{
//				// 指令没有跟退定的索引,返回提示语句给用户
//				theData.SetMsg2(&m_Db,pIOD,"00000_1860_qx_have_not_index", NULL, &m_Info);
//				return TRUE;
//			}
//			uId=atoi(strTemp);
//			if(uId==0)
//				H1860_00000(pIOD,CString("13")+CString(pIOD->szSrcTermID));
//			else
//				H1860_QX(pIOD,CString("13")+CString(pIOD->szSrcTermID),uId);
//		}
//		else
//		{
//			// 不是QX...代为退定指令,返回提示语句
//			theData.SetMsg2(&m_Db,pIOD,"00000_1860_qx_invalid_command", NULL, &m_Info);
//			return TRUE;
//		}
//	}
	//else if(strSubId.Left(3)=="800")
	//	H800(pInfo);
	else
		theData.SetMsg2(&m_Db,pIOD,"00000_invalid_command", NULL, &m_Info);

	return TRUE;
}

BOOL C0000Thread::Is0000Service(LPIOD_Info pIOD)
{
	CString strSubId(pIOD->szSubID);

	if (strSubId.CompareNoCase("IUNKNOW2")==0)
		return FALSE;

	if (strSubId.CompareNoCase("IUNKNOW")==0)
	{
	//	lstrcpy(pIOD->szSubID, pIOD->szContent);
	//	lstrcpy(pIOD->szContent,"");
	//	strSubId=pIOD->szSubID;
		strSubId=pIOD->szContent;
	}
	strSubId.MakeUpper();

	if (strSubId.Left(4)=="0000")
		return TRUE; // 取消所有定制
	else if (strSubId.Left(2)=="QR" && lstrcmp(pIOD->szSrcTermID, "1818")==0)
		return FALSE;
	else if (strSubId.Left(2)=="QX" && lstrcmp(pIOD->szSrcTermID, "1818")==0)
		return FALSE;
	else if (strSubId.Left(1)=="Q" && lstrcmp(pIOD->szSrcTermID, "1818")==0)
		return TRUE;

	return FALSE;
}

int C0000Thread::ParseSubscribeItem(LPCTSTR pszList, vector<SUBSCRIBEITEM>& items)
{
	int iRet=0,iPos=0,iPosOfComma=0,iIndex=0;
	CString strList(pszList),strItem,strCustomNo,strPushType,strName,strTypecode,strType;
	SUBSCRIBEITEM item;
	CString strLog;

	while((iPos=strList.Find(";"))>0)
	{
		strItem=strList.Left(iPos);

		// Custom No
		iPosOfComma=strItem.Find(":");
		if(iPosOfComma<1)
		{
			strLog.Format("%s在解析时不合法。略过继续。",strItem);
			theData.WriteLog(strLog,"ERR");
			strList=strList.Mid(iPos+1);
			continue;
		}
		strCustomNo=strItem.Left(iPosOfComma);

		// Push Type
		strItem=strItem.Mid(iPosOfComma+1);
		iPosOfComma=strItem.Find(":");
		if(iPosOfComma<1)
		{
			strLog.Format("%s在解析时不合法。略过继续。",strItem);
			theData.WriteLog(strLog,"ERR");
			strList=strList.Mid(iPos+1);
			continue;
		}
		strPushType=strItem.Left(iPosOfComma);

		// Name
		strItem=strItem.Mid(iPosOfComma+1);
		iPosOfComma=strItem.Find(":");
		if(iPosOfComma<1)
		{
			// 旧版本:只有customno,pushtype,name
			strName=strItem;
		}
		else
		{
			strName = strItem.Left(iPosOfComma);
			// typecode		
			strItem=strItem.Mid(iPosOfComma+1);
			iPosOfComma=strItem.Find(":");
			if(iPosOfComma<0)
			{
				strLog.Format("%s在解析时不合法。略过继续。",strItem);
				theData.WriteLog(strLog,"ERR");
				strList=strList.Mid(iPos+1);
				continue;
			}
			strTypecode = strItem.Left(iPosOfComma);
			// type
			strType = strItem.Mid(iPosOfComma+1);
		}

		strPushType.TrimLeft();
		strName.TrimLeft();
		strCustomNo.TrimLeft();
		strTypecode.TrimLeft();
		strType.TrimLeft();
		item.lIndex=iIndex+1;

		item.lCustomNo=atoi(strCustomNo);
		item.lType=atoi(strType);
		_tcscpy(item.pszPushType,strPushType);
		_tcscpy(item.pszColName,strName);
		_tcscpy(item.pszTypeCode,strTypecode);
		items.push_back(item);
		// Next
		strList=strList.Mid(iPos+1);
		iIndex++;
	}

	iRet=iIndex;
	return iRet;
}

void C0000Thread::H00000(IOD_Info *pInfo)
{	
	OUTPUTMSGLIST mmlist; // misc msg

	int iRet=m_Db.CancelAll(pInfo->szDestMobile,&mmlist);
	list<OUTPUTMSG>::iterator mm;
	switch(iRet)
	{
	case 0:	// 成功
		theData.SetMsg2(&m_Db,pInfo,"00000_succ", NULL, &m_Info);
		// MISC
		for (mm=mmlist.begin(); mm!=mmlist.end(); ++mm)
		{
		//	if ((*mm).szFeeType.CompareNoCase("09")==0)
			theData.SetMsg(pInfo, (*mm).szMsg, (*mm).szSendNo, (*mm).szSubID, (*mm).szFeeCode, (*mm).szFeeType, (*mm).nMsgType, &m_Info);
		}
		break;
	case -6:// 没有定制栏目
		theData.SetMsg2(&m_Db,pInfo,"00000_user_have_no_sucscribe", NULL, &m_Info);
		break;
	case -7:// 该用户不存在
		theData.SetMsg2(&m_Db,pInfo,"00000_user_not_registered", NULL, &m_Info);
		break;
	case -8:// 已经取消过了
		theData.SetMsg2(&m_Db,pInfo,"00000_user_unregistered_before", NULL, &m_Info);
		break;
	default:
		theData.SetMsg2(&m_Db,pInfo,"00000_failed", NULL, &m_Info);
		//您未申请XXXX公司的移动梦网服务,我公司客服热线:XXXXXXXX。谢谢。"
		break;
	}
}

void C0000Thread::H0000(IOD_Info *pInfo)
{
	// 返回用户定制列表
	CString strList,strMsg,strTemp;
	vector<SUBSCRIBEITEM> items;
	vector<SUBSCRIBEITEM>::iterator it;
	int iRet=m_Db.GetUserCustomList(pInfo->szDestMobile,strList,strMsg);
	switch(iRet)
	{
	case 0:
		if(ParseSubscribeItem(strList,items)>0)
		{
			//strMsg="回复Q+序号,取消相应的服务(如要取消第三项服务则只需直接回复:Q3):\n0 取消所有定制";
			for(it=items.begin();it!=items.end();it++)
			{
				if(strMsg.IsEmpty())
					strTemp.Format("%d %s",(*it).lIndex,(*it).pszColName);
				else
					strTemp.Format("\n%d %s",(*it).lIndex,(*it).pszColName);

				strMsg+=strTemp;
				if(strMsg.GetLength()>90)
				{
					SetMsg(pInfo,strMsg,0);
					theData.AddOneSendMsg(pInfo);
					strMsg="";
					continue;
				}
			}
			if(!strMsg.IsEmpty())
			{
				strcpy(pInfo->szSrcTermID,"1818");
				SetMsg(pInfo,strMsg,0);
				theData.AddOneSendMsg(pInfo);
			}
			theData.m_UserCustoms.AddOneInfo(pInfo->szDestMobile,items);
		}
		else
			theData.SetMsg2(&m_Db,pInfo,"0000_user_have_no_subscribe", NULL, &m_Info);
		break;
	case 1:
			strMsg+=strList;
			if(!strList.IsEmpty())
			{
				strcpy(pInfo->szSrcTermID,"1818");
				SetMsg(pInfo,strMsg,0);
				theData.AddOneSendMsg(pInfo);
			}
			else
				theData.SetMsg2(&m_Db,pInfo,"0000_user_have_no_subscribe", NULL, &m_Info);
		break;
	case -7:
		theData.SetMsg2(&m_Db,pInfo,"0000_user_not_registered", NULL, &m_Info);
		break;
	case -8:
		theData.SetMsg2(&m_Db,pInfo,"0000_user_unregistered_before", NULL, &m_Info);
		break;
	default:
		theData.SetMsg2(&m_Db,pInfo,"0000_unable_get_users_config", NULL, &m_Info);
		break;
	}
}

bool C0000Thread::Is1860Allowed(LPCTSTR pszMobile)
{
	int r = m_Db.Is1860Allowed(pszMobile) ;
	if(r==1)
		return true;
	else 
		return false ;
	/*
	CString strTemp;
	TCHAR pszTemp[_MAX_PATH];
	TCHAR path[_MAX_PATH];
	LPTSTR temp = NULL;
	GetModuleFileName(NULL, path, _MAX_PATH);
	temp = strrchr(path, '\\');
	path[temp - path + 1] = '\0';
	lstrcat(path, IOD_Cfg_File);

	int iLen=GetPrivateProfileString("Option", "1860", "", pszTemp, _MAX_PATH, path);
	pszTemp[iLen]=0;
	strTemp=pszTemp;

	if(strTemp.Find(pszMobile)>-1)
		return true;
	
	return false;
	*/
}

void C0000Thread::H1860_0000(IOD_Info *pInfo)
{
	// 返回1860用户定制列表
	CString strList,strClientPhone,strSubId(pInfo->szSubID),strTemp,strSrcTermId,strMsg;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -