www.pudn.com > xltsm.rar > xltsm.cpp


// xltsm.cpp : Defines the entry point for the console application. 
// 
 
#include "stdafx.h" 
#include "smset.h" 
#include "smei.h" 
#include "SendSM.h" 
#include "ChkQueue.h" 
 
int  nLclPort	  = 9988;        // 本地端口 
char szServerIP[65] = "202.108.250.176"; // 远程网关地址 
int	 nServerPort  = 9890;        // 网关端口号 
char szCngpUser[32] = "Bjzhx";	 // 登录用户名 
char szCngpPwd[32] = "1234";	 // 登录口令 
char szIcpNbr[9] = "94011";		 // 特服号 
char szCorpId[11] = "3001888882"; // 企业代码 
int nDeliverWait = 5;	// 扫描间隔 
 
char szCorp[20]="";		// 智响通讯 
char szTel[20]="";		// 公司电话 
char szWeb[50]="";		// 公司主页 
char szCmccTest[50] = ""; // CMCC信息 
char szCmdSet[161]="";		// 当用户发送无效命令字时提示 
 
static CMyDatabase db; // 数据库连接 
 
void EnrollFlag() 
{ 
	static char Mark[8] = { '|', '/', '-', '\\', '|', '/', '-', '\\' }; 
	static int Index = 0; 
	cprintf("\b%c", Mark[Index]); 
	Index = (Index + 1) % 8; 
	return; 
} 
 
int main() 
{ 
	LPCSTR lpcszPhsCfgFile = "xltsm.ini"; 
	LPCSTR lpcszIsmrCfgFile = "e2hismr.ini"; 
 
	SetConsoleTitle("网通小灵通短信接口V1·0"); // 由于要移动标题,为简化处理,要求全是全角字符或汉字 
 
	printf("\n网通小灵通短信接口 版本1.0 版权(C)归北京智响通讯技术有限公司所有\n"); 
 
	printf("\n从文件%s读取PHS配置参数...", lpcszPhsCfgFile); 
	GetSetting(lpcszPhsCfgFile, "CNGP", "local_port", 9988, &nLclPort);	// 本地端口 
	GetSetting(lpcszPhsCfgFile, "CNGP", "server_ip", "202.108.250.176", szServerIP, sizeof(szServerIP)); // 远程网关地址 
	GetSetting(lpcszPhsCfgFile, "CNGP", "server_port", 9890, &nServerPort);			// 网关端口号 
	GetSetting(lpcszPhsCfgFile, "CNGP", "user", "Bjzhx", szCngpUser, sizeof(szCngpUser));	// 登录用户名 
	GetSetting(lpcszPhsCfgFile, "CNGP", "pwd", "1234", szCngpPwd, sizeof(szCngpPwd));	// 登录口令 
	GetSetting(lpcszPhsCfgFile, "CNGP", "icpnbr", "94011", szIcpNbr, sizeof(szIcpNbr));	// 特服号 
	GetSetting(lpcszPhsCfgFile, "CNGP", "CorpId", "3001888882", szCorpId, sizeof(szCorpId)); // 企业代码 
	GetSetting(lpcszPhsCfgFile, "CNGP", "timeout", 5, &nDeliverWait); 
	printf("成功!\n"); 
 
	printf("\n从文件%s读取ISMR配置参数...", lpcszIsmrCfgFile); 
	GetSetting(lpcszIsmrCfgFile, "Translation", "CTIVR", "智响通讯", szCorp, sizeof(szCorp)); 
	GetSetting(lpcszIsmrCfgFile, "Translation", "TEL", "010-82856615", szTel, sizeof(szTel)); 
	GetSetting(lpcszIsmrCfgFile, "Translation", "WEB", "http://www.ctivr.com", szWeb, sizeof(szWeb)); 
	GetSetting(lpcszIsmrCfgFile, "Translation", "CMCCTEST", "北京,智响通讯,01658,901500", szCmccTest, sizeof(szCmccTest)); 
	GetSetting(lpcszIsmrCfgFile, "Translation", "CMDSET", "EDU-家校通 TBLX-同步练习 YJJC-有奖竞猜 TBJY-同步记忆 XXCD-学习辞典", szCmdSet, sizeof(szCmdSet));	// 命令菜单 
	printf("成功!\n"); 
 
	AfxSocketInit(); 
 
	mkdir("./phsqueue"); 
 
	SOCKET sktDeliver = _login(szServerIP, nServerPort, szCngpUser, szCngpPwd, LOGINMODE_DELIVER); 
	if (sktDeliver == INVALID_SOCKET){ 
		printf("\n登录CNGP网关失败。\n"); 
		return FALSE; 
	} 
 
	printf("\n程序开始等待并处理短信...成功!\n");  
 
	for ( ; ; ) { 
		try { 
			if (_delivery(sktDeliver, nDeliverWait) != ERROR_SUCCESS){ 
				_logout(sktDeliver); 
				do { 
					Sleep(5000); 
					printf("\n重连CNGP网关..."); 
					sktDeliver = _login(szServerIP, nServerPort, szCngpUser, szCngpPwd, LOGINMODE_DELIVER); 
				} while (sktDeliver == INVALID_SOCKET); 
				printf("成功!\n"); 
			} 
			_submit(szServerIP, nServerPort, szCngpUser, szCngpPwd); 
			if (!ProcDelivery(0)){ 
				CheckMonthTable(db); 
			} 
			EnrollFlag(); 
			/* 
			if (_activetest(sktDeliver) != ERROR_SUCCESS) throw (const char *)"reconnect"; 
			Sleep(nDeliverWait * 1000); 
			*/ 
		}  
		catch(const char *e){ 
			if (!strcmp(e, "reconnect")){ 
				sktDeliver = _login(szServerIP, nServerPort, szCngpUser, szCngpPwd, LOGINMODE_DELIVER); 
				if (sktDeliver == INVALID_SOCKET){ 
					printf("\n重连CNGP网关...失败"); 
					Sleep(nDeliverWait); 
					continue; 
				} 
			} else { 
				printf("\n关键错误:%s。", e); 
			} 
			Sleep(nDeliverWait * 1000); 
		} 
		catch(...){ 
			printf("\n内存访问非法。"); 
		} 
	} 
 
	_logout(sktDeliver); 
 
	printf("\n信息:服务被成功终止!\n"); 
 
	return 0; 
}