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

📄 mobmsgdlg.cpp

📁 一个完整的短讯网关示例,支持短讯收发,支持UDP及Text格式.
💻 CPP
📖 第 1 页 / 共 5 页
字号:
void UserTvodMovieNo()
{
	memset(UserRequestMovieNo,0,10);//用户短讯中传入的节目编号
	memcpy(UserRequestMovieNo,MsgInfo,strlen(MsgInfo));

	int nMovieNo = atoi(UserRequestMovieNo);
	memset(UserRequestMovieNo,0,10);//用户短讯中传入的节目编号
	itoa(nMovieNo,UserRequestMovieNo,10);

	memset(sendMsg,32,100);
	pMsg = sendMsg;
	memcpy(pMsg, "^^001", 5);///获取卡号
	pMsg += 5;
	memcpy(pMsg, MobilChannel, 3);
	pMsg += 3;
	
	memcpy(pMsg, MsgMobNo, 20);
	pMsg += 20;
	
	sendMsg[98] = '*';
	sendMsg[99] = '*';
	if (SendOrGetMsgFromServer())
	{
		memset(sendMsg,0,100);
		memset(sendMsg,32,100);
		pMsg = sendMsg;
		memcpy(pMsg, "^^041", 5);
		pMsg += 5;
		memcpy(pMsg, MobilChannel, 3);
		pMsg += 3;
		
		memcpy(pMsg, MsgMobNo, 20);
		pMsg += 20;
		
		memcpy(pMsg, RequestIcCardNo, 20);
		pMsg += 20;
		
		memcpy(pMsg, UserRequestMovieNo, 20);
		pMsg += 20;
		sendMsg[98] = '*';
		sendMsg[99] = '*';
		if (SendOrGetMsgFromServer())
		{
			CString sTmpSendMseeage = "当前节目费用为:";
			char sMovieInfoPrice[1000];
			memset(sMovieInfoPrice,0,1000);	
			memcpy(sMovieInfoPrice,sMsgRtn+88,5);
			sTmpSendMseeage += sMovieInfoPrice;
			sTmpSendMseeage += "元 ";
			memset(sendMsg,32,100);
			pMsg = sendMsg;
			memcpy(pMsg, "^^051", 5);
			pMsg += 5;
			memcpy(pMsg, MobilChannel, 3);
			pMsg += 3;
			
			memcpy(pMsg, MsgMobNo, 20);
			pMsg += 20;
			
			memcpy(pMsg, RequestIcCardNo, 20);
			pMsg += 20;
			
			memcpy(pMsg, UserRequestMovieNo, 20);
			pMsg += 20;
			sendMsg[98] = '*';
			sendMsg[99] = '*';
			SendOrGetMsgFromServer();
			if (memcmp(sMsgRtn, "^^131", 5) == 0) //节目已开始播放
			{
				sTmpSendMseeage += "请在一分钟内进行点播确认!";//sMovieInfoPrice;
				
				if (atoi(sMovieInfoPrice) <= 0)
				{
					nTvodCostFlag = 1;
					UserTvodMovieValidate();
					return ;
				}
				else nTvodCostFlag = 0;
				memset(sMovieInfoPrice,0,1000);	
				memcpy(sMovieInfoPrice,sTmpSendMseeage,60);
				SendMsgInfo(StrSmsCenterCode,MsgMobNo,sMovieInfoPrice);

				memset(sendMsg,0,100);
				memcpy(sendMsg,sMsgRtn,100);
				closesocket(sockClt);
				sockClt = INVALID_SOCKET;
			}
			if (memcmp(sMsgRtn, "^^133", 5) == 0) //此卡号有点播节目正在播放,不充许再点播
			{
				SendMsgInfo(StrSmsCenterCode,MsgMobNo,"此卡号有点播节目正在播放,不充许再点播!");
				memset(sendMsg,0,100);
				memcpy(sendMsg,sMsgRtn,100);
				closesocket(sockClt);
				sockClt = INVALID_SOCKET;
			}
			if (memcmp(sMsgRtn, "^^134", 5) == 0) //卡号不存在或被禁用
			{
				SendMsgInfo(StrSmsCenterCode,MsgMobNo,"IC卡号不存在!");
				memset(sendMsg,0,100);
				memcpy(sendMsg,sMsgRtn,100);
				closesocket(sockClt);
				sockClt = INVALID_SOCKET;
			}
			/////////////////////
		}
	}
}
//-------------------------用户按节目名称点播
void UserTvodMovieName()
{
	CString sTmpSendMseeage = "";
	int nRtn = 0 ;
	char sMovieInfoPrice[1000];
	memset(UserRequestMovieName,0,40);//用户短讯中传入的节目名称
	memcpy(UserRequestMovieName,MsgInfo+1,40);

	memset(sendMsg,32,100);
	pMsg = sendMsg;
	memcpy(pMsg, "^^001", 5);///获取卡号
	pMsg += 5;
	memcpy(pMsg, MobilChannel, 3);
	pMsg += 3;
	
	memcpy(pMsg, MsgMobNo, 20);
	pMsg += 20;
	
	sendMsg[98] = '*';
	sendMsg[99] = '*';
	if (SendOrGetMsgFromServer())
	{
		memset(sendMsg,32,100);
		pMsg = sendMsg;

		memcpy(pMsg , "^^071", 5);
		pMsg += 5 ;
		memcpy(pMsg , MobilChannel, 3);
		pMsg += 3;
		memcpy(pMsg, MsgMobNo, 20);
		pMsg += 20;

		memcpy(pMsg, RequestIcCardNo, 20);
		pMsg += 20;
		memcpy(pMsg, UserRequestMovieName, 40);
		pMsg += 40;
		sendMsg[98] = '*';
		sendMsg[99] = '*';
		
		if (SendOrGetMsgFromServer()) 
		{
			if (strncmp(sMsgRtn,"^^171",5) == 0)
			{
				sTmpSendMseeage = "您点播的节目是:";
				
				memset(sMovieInfoPrice,0,1000);	
				memcpy(sMovieInfoPrice,sMsgRtn + 8 + 20  + 20 ,40);	
				sTmpSendMseeage += sMovieInfoPrice ;
				memset(sMovieInfoPrice,0,1000);	
				memcpy(sMovieInfoPrice,sMsgRtn + 8 + 20  + 20 + 5 + 40,5);
				sTmpSendMseeage +=":费用为";
				sTmpSendMseeage += sMovieInfoPrice;
				sTmpSendMseeage += "元 ";
				memset(UserRequestMovieNo,0,12);
				memcpy(UserRequestMovieNo,sMsgRtn+ 8 + 20  + 20 + 40,5);

				memset(sendMsg,32,100);
				pMsg = sendMsg;
				memcpy(pMsg, "^^051", 5);
				pMsg += 5;
				memcpy(pMsg, MobilChannel, 3);
				pMsg += 3;
				
				memcpy(pMsg, MsgMobNo, 20);
				pMsg += 20;
				
				memcpy(pMsg, RequestIcCardNo, 20);
				pMsg += 20;
				
				memcpy(pMsg, UserRequestMovieNo, 20);
				pMsg += 20;
				sendMsg[98] = '*';
				sendMsg[99] = '*';
				SendOrGetMsgFromServer();
				if (memcmp(sMsgRtn, "^^131", 5) == 0) //节目已开始播放
				{
					if (atoi(sMovieInfoPrice)<=0)
					{
						nTvodCostFlag = 1;
						UserTvodMovieValidate();
						return ;	
					}
					nTvodCostFlag = 0;
					sTmpSendMseeage += "请在一分钟内进行点播确认!";//sMovieInfoPrice;
					memset(sMovieInfoPrice,0,1000);	
					memcpy(sMovieInfoPrice,sTmpSendMseeage,70);
					SendMsgInfo(StrSmsCenterCode,MsgMobNo,sMovieInfoPrice);
					memset(sendMsg,0,100);
					memcpy(sendMsg,sMsgRtn,100);
					closesocket(sockClt);
					sockClt = INVALID_SOCKET;
				}
				if (memcmp(sMsgRtn, "^^133", 5) == 0) //此卡号有点播节目正在播放,不充许再点播
				{
					SendMsgInfo(StrSmsCenterCode,MsgMobNo,"此卡号有点播节目正在播放,不充许再点播!");
					memset(sendMsg,0,100);
					memcpy(sendMsg,sMsgRtn,100);
					closesocket(sockClt);
					sockClt = INVALID_SOCKET;
				}
				if (memcmp(sMsgRtn, "^^134", 5) == 0) //卡号不存在或被禁用
				{
					SendMsgInfo(StrSmsCenterCode,MsgMobNo,"IC卡号不存在!");
					memset(sendMsg,0,100);
					memcpy(sendMsg,sMsgRtn,100);
					closesocket(sockClt);
					sockClt = INVALID_SOCKET;
				}
			}
			else if (strncmp(sMsgRtn,"^^172",5) == 0)
			{
				char sMsgMovieInfo[1000];
				memset(sMsgMovieInfo,0,1000);
				nRtn = recv(sockClt,sMsgMovieInfo,sizeof(sMsgMovieInfo),0);
				if (nRtn == SOCKET_ERROR)
				{
					SendSystemInfo("与点播服务器连接失败!",0);
					return ;
				}
				sTmpSendMseeage = "查询到节目信息(名称,编号,价格)";
				sTmpSendMseeage += sMsgMovieInfo ;
				memset(sMovieInfoPrice,0,1000);	
				memcpy(sMovieInfoPrice,sTmpSendMseeage,1000);
				SendMsgInfo(StrSmsCenterCode,MsgMobNo,sMovieInfoPrice);
			}
			else if (strncmp(sMsgRtn,"^^173",5) == 0)
			{
				//SendSystemInfo("节目名称未找到",1);
				SendMsgInfo(StrSmsCenterCode,MsgMobNo,"没有查询到您所需节目!");
			}
		}
	}
}
//-------------------------用户取消点播节目
void UserRemoveTvodMovie()
{
	memset(sendMsg,32,100);
	pMsg = sendMsg;
	memcpy(pMsg, "^^001", 5);///获取卡号
	pMsg += 5;
	memcpy(pMsg, MobilChannel, 3);
	pMsg += 3;
	
	memcpy(pMsg, MsgMobNo, 20);
	pMsg += 20;
	
	sendMsg[98] = '*';
	sendMsg[99] = '*';
	if (SendOrGetMsgFromServer()) 
	{
		memset(sendMsg,32,100);
		pMsg = sendMsg;
		memcpy(pMsg, "^^051", 5);
		pMsg += 5;
		memcpy(pMsg, MobilChannel, 3);
		pMsg += 3;
		
		memcpy(pMsg, MsgMobNo, 20);
		pMsg += 20;
		
		memcpy(pMsg, RequestIcCardNo, 20);
		pMsg += 20;
		
		memset(UserRequestMovieNo,0,20);
		memcpy(UserRequestMovieNo,"0",1);
		memcpy(pMsg, UserRequestMovieNo, 20);
		pMsg += 20;
		sendMsg[98] = '*';
		sendMsg[99] = '*';
		SendOrGetMsgFromServer();//验证节目编号
		if (memcmp(sMsgRtn, "^^133", 5) == 0) //在有播放节目的情况下进行确认
		{
			memset(sendMsg,32,100);
			pMsg = sendMsg;
			memcpy(pMsg, "^^202", 5);
			pMsg += 5;
			memcpy(pMsg, MobilChannel, 3);
			pMsg += 3;
			
			memcpy(pMsg, MsgMobNo, 20);
			pMsg += 20;
			
			memcpy(pMsg, RequestIcCardNo, 20);
			pMsg += 20;
			
			memcpy(pMsg, UserRequestMovieNo, 20);
			pMsg += 20;
			sendMsg[98] = '*';
			sendMsg[99] = '*';
			SendOrGetMsgFromServer();
		}
		else
		if (memcmp(sMsgRtn, "^^132", 5) == 0) //网络资源分配失败
		{
			SendMsgInfo(StrSmsCenterCode,MsgMobNo,"当前IC卡无点播节目!");//此电话已绑定到其它卡号
			memset(sendMsg,0,100);
			memcpy(sendMsg,sMsgRtn,100);
			closesocket(sockClt);
			sockClt = INVALID_SOCKET;
		}
	}
}
//-------------------------------------用户请求绑定
void UserRequestService()
{
	//根据短信息内容取得用户所要绑定的卡号
	memset(RequestIcCardNo,0,20);
	memcpy(RequestIcCardNo,MsgInfo + 1,strlen(MsgInfo) - 1);

	memset(sendMsg,32,100);
	pMsg = sendMsg;
	memcpy(pMsg, "^^021", 5);
	pMsg += 5;
	memcpy(pMsg, MobilChannel, 3);
	pMsg += 3;
	
	memcpy(pMsg, MsgMobNo, 20);
	pMsg += 20;

	memcpy(pMsg, RequestIcCardNo, 20);
	pMsg += 20;
	
	sendMsg[98] = '*';
	sendMsg[99] = '*';

	if (SendOrGetMsgFromServer())
	{
		memset(sendMsg,0,100);
		pMsg = sendMsg;
		memcpy(pMsg, "^^031", 5);
		pMsg += 5;
		memcpy(pMsg, MobilChannel, 3);
		pMsg += 3;
		
		memcpy(pMsg, MsgMobNo, 20);
		pMsg += 20;

		memcpy(pMsg, RequestIcCardNo, 20);
		pMsg += 20;
		
		sendMsg[98] = '*';
		sendMsg[99] = '*';
		SendOrGetMsgFromServer();//如果成功的话则发送短讯给用户说明绑定成功
	}   
}


//*/
char* ReceiveFromMobile()
{
	DWORD rbNum;
	OVERLAPPED lpol;
	memset(&lpol, 0, sizeof(OVERLAPPED));
	memset(MsgBuf,0,8192);//8192

	if (!ReadFile(Mobile, MsgBuf, 8192, &rbNum, &lpol))
		return NULL;

	if (rbNum < 1)
		return NULL;
	else
	{
		MsgBuf[rbNum] = 0;
		return MsgBuf;
	}
}
//-----------------------------------用户取消绑定
void UserCancleService()//char *IcCard,char *MobNo
{
	memset(sendMsg,32,100);
	pMsg = sendMsg;
	memcpy(pMsg, "^^001", 5);
	pMsg += 5;
	memcpy(pMsg, MobilChannel, 3);///获取卡号
	pMsg += 3;

	memcpy(pMsg, MsgMobNo, strlen(MsgMobNo));
	pMsg += 20;

	sendMsg[98] = '*';
	sendMsg[99] = '*';
	if (SendOrGetMsgFromServer()) 
	{
		memset(sendMsg,0,100);
		pMsg = sendMsg;
		memcpy(pMsg, "^^011", 5);
		pMsg += 5;
		memcpy(pMsg, MobilChannel, 3);
		pMsg += 3;

		memcpy(pMsg, MsgMobNo, 20);
		pMsg += 20;
		
		memcpy(pMsg, RequestIcCardNo, 20);
		pMsg += 20;
		sendMsg[98] = '*';
		sendMsg[99] = '*';
		SendOrGetMsgFromServer();
	}
}
void SendShortMsgToReceive()
{
	HOSTENT *host;
	int nRtn = 0;
	SOCKADDR_IN addrSrv;
	//sSendToReceiveMsg //要传送到机顶盒上的短信息内容
	//进来短信格式:M+RequestIcCardNo+""+ShortMsg(1+11+1+50)
	memset(RequestIcCardNo,0,20);

⌨️ 快捷键说明

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