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

📄 zzxs_thread.cpp

📁 这是一个短信应用程序.主要接口是数据库接口.是个不错的学习应用软件
💻 CPP
字号:
// zzxs_Thread.cpp : 实现文件
//

#include "stdafx.h"
#include "zztg.h"
#include "zzxs_Thread.h"


static UINT_PTR		lpTimerID=0;
// CAutoSMSDlg 对话框
using namespace SMS;
static CADODatabase * db=NULL;
static int iPrice=10;
// CAutoTVThread
static CString strYDIP,strYDUSERNAME,strYDPASSWORD,strEnterprise;
static CString strLTIP,strLTUSERNAME,strLTPASSWORD,strLocalIP,strServiceID="self";
static int iYDMTPORT,iLTMTPORT;
static int iConn=-1;	
static int MeroryVar=1;
static int mt=0;
// zzxs_Thread

IMPLEMENT_DYNCREATE(zzxs_Thread, CWinThread)

zzxs_Thread::zzxs_Thread()
{
}

zzxs_Thread::~zzxs_Thread()
{
}



BOOL zzxs_Thread::InitInstance()
{
// TODO: 在此执行任意逐线程初始化
	// TODO: 在此执行任意逐线程初始化
	try{
		db = new CADODatabase();
		db->OpenSQLServerDirect(MyReg::GetDBIP(),MyReg::GetDBUserID(),MyReg::GetDBPassword(),
			MyReg::GetDBName());	
		//可以在此处建立长连接,发送完短信息后断开连接。
		iConn=::CMPP_Connect(MyReg::GetYidongUsername(),MyReg::GetYidongPassword(),
			MyReg::GetYidongIP(),MyReg::GetYidongPort(),MyReg::GetClientPath());

		lpTimerID = SetTimer(NULL,118,1*100,TimerFunction);
	}
	catch(...){
		lpTimerID = SetTimer(NULL,118,1*100,TimerFunction);
	}
			
	return TRUE;	
}

int zzxs_Thread::ExitInstance()
{
	// TODO: 在此执行任意逐线程清理
	return CWinThread::ExitInstance();
}

BEGIN_MESSAGE_MAP(zzxs_Thread, CWinThread)
END_MESSAGE_MAP()


// zzxs_Thread 消息处理程序
void SocketTraceMO(CString str){
//#ifdef _DEBUG
	str+= "\r\n";
	CString strFilename = "c:\\self.txt";	
	CFileStatus status;
	if(CFile::GetStatus(strFilename,status)){
		CFile f(strFilename,CFile::modeReadWrite|CFile::modeNoTruncate);
		f.SeekToEnd();
		f.Write(str.GetBuffer(0),str.GetLength());
		f.Close();
	}
	else{
		CFile f(strFilename,CFile::modeCreate|CFile::modeWrite);
		f.Write(str.GetBuffer(0),str.GetLength());
		f.Close();
	}
//#endif
}

// Auto_xsThread 消息处理程序
void zzxs_Thread::TimerFunction(HWND hWnd,UINT uID,UINT_PTR pID,DWORD dwPar)
{		
	KillTimer(hWnd,lpTimerID);	
	
	try{//1try
		if(db->IsOpen()){
			//写一个方法函数处理MO信息
		 BordProcess();
		 BackProcess();
		/// BackProcess();
	//	 self_sms();
		 //qfxinxi();
 //SocketTraceMO("写一个方法函数处理MO信息写一个方法函数处理MO信息写一个方法函数处理MO信息写一个方法函数处理MO信息");							//处理注销流程
			lpTimerID = SetTimer(hWnd,118,30*1000,TimerFunction);
		}
		else{
			//打开数据库		
			db->OpenSQLServerDirect(MyReg::GetDBIP(),MyReg::GetDBUserID(),MyReg::GetDBPassword(),MyReg::GetDBName());
			lpTimerID = SetTimer(hWnd,118,30*1000,TimerFunction);
		}
	}//1try
	catch(...){
		db->OpenSQLServerDirect(MyReg::GetDBIP(),MyReg::GetDBUserID(),MyReg::GetDBPassword(),MyReg::GetDBName());
		lpTimerID = SetTimer(hWnd,118,1000,TimerFunction);
	}
	//重新定时
} 
//群发信息
 void zzxs_Thread::BordProcess()////??????????
{
if(mt>2)
{
				CADORecordset rs_p(db);
				CADORecordset cont_info(db);	
				CString strSql,strSpCode,strMobileCode ,strMsg, strDQBM,strPrice,strSongName,sql,opst,Sql,getsms,msgflag="lbon" ,msgflag1="lboff";
				strSql="exec SMSAPPDB.DBO.P_XXNN_SMS_BAT_SEND";
				sql="select * from sms_mo_input where processflag=0 and (sms_msg='"+msgflag+"'or sms_msg='"+msgflag1+"') and  (mobilecode='13755002297' or mobilecode='8613307489748' or mobilecode='13973120306')";
				cont_info.Open(sql);
				SocketTraceMO(sql);
				if(!cont_info.IsEOF())
				{
				cont_info.GetFieldValue("mobilecode",strMobileCode);
				cont_info.GetFieldValue("spcode",strSpCode);
				cont_info.GetFieldValue("sms_msg",strMsg );
				if(strMsg.Trim() =="lbon"||strMsg.Trim()=="LBON")
				{
					strMsg=strMobileCode+"将聊吧程序成功启动";//13973120306
					MeroryVar=0;
					
				}
				
				if(strMsg.Trim() =="lboff"||strMsg.Trim()=="LBOFF")
				{
					strMsg=strMobileCode+"将聊吧程序成功关闭";//13973120306
				 SocketTraceMO(strMsg);
					MeroryVar=1;
				}
				
				Sendsms("8613307489748" ,"8613307489748",strMsg ,"CMCCTEST" ,"01" ,0);
				Sendsms("13973120306" ,"13973120306",strMsg ,"CMCCTEST" ,"01" ,0);
				Sendsms("13755002297" ,"13755002297",strMsg ,"CMCCTEST" ,"01" ,0);
				cont_info.Edit();
				cont_info.SetFieldValue("processflag",1);						
				cont_info.Update();
				}
				if (MeroryVar==0)
				{
					try
					{
						rs_p.Open(strSql);

						mt=0;
				 
					}catch(...)
					{
					SocketTraceMO("________________error_____________________________error___________________________________");
					}
				}
		}
		else
		{
			mt++;
			CString strmt;
			strmt.Format("mt %d",mt);
				SocketTraceMO(strmt);
		}
	 
}
 

 
///调用上行信息
void zzxs_Thread::BackProcess()
 {
	 CADORecordset rs_p(db);
	 CADORecordset cont_info(db);	
	 CString strSql,strSpCode,strMobileCode ,strMsg, strDQBM,strPrice,strSongName,sql,opst,Sql,getsms,msgflag="lbon" ,msgflag1="lboff";
	 strSql="exec SMSAPPDB.DBO.P_xxnn_mo_process";
	 try
	 {
rs_p.Open(strSql);
	 }
	 catch (...) {

	 }
	 
}

 
void zzxs_Thread:: Sendsms(CString strMobileDesc ,CString strChargeNum,CString strSmsMsg ,CString strServiceID ,CString strFeeType ,int IFeeValue)
{
	//CADORecordset rs(db);
	//CADORecordset rs_log(db);
	CADORecordset rs_p(db);
// SocketTraceMO("5555555555555555555555555555555555555555555555555555555555555555555555555555555");
	//int iSend=17;
	//查询互动信息,并给出相应的处理。
 strFeeType="01";
	CString strSql,strSpCode,strMobileCode ,strMsg, strDQBM,strPrice,strSongName,sql,opst,Sql,getsms;
	//strPrice.Format("%d",iPrice);
	//Sql="select * from sms_mo_input where processflag=0 order by id";
	//rs_p.Open(Sql);
	if(strMobileCode.Mid(0,2)=="86")
	{
		strSpCode="81198190000";
	}
	else
	{
		
		strSpCode="01190";
	}
	rs_p.Open("select * from sms_send_msg where 1=0");
	rs_p.AddNew();		
	rs_p.SetFieldValue("SpCode",strSpCode);
	rs_p.SetFieldValue("MobileDesc",strMobileDesc.Trim());
	rs_p.SetFieldValue("ChargeNum",strChargeNum.Trim());
	rs_p.SetFieldValue("SmsMsg",strSmsMsg.Trim());
	rs_p.SetFieldValue("ServiceID",strServiceID);
	  
	 
		rs_p.SetFieldValue("FeeType",strFeeType);
		rs_p.SetFieldValue("FeeValue",IFeeValue);
	 
//SocketTraceMO(strSpCode+strMobileDesc+strChargeNum+strSmsMsg+strServiceID);
	rs_p.Update();
	rs_p.Close();
}

void zzxs_Thread:: self_sms()//IE165的短信自写;
{

 CString BackSeSql;
		CADORecordset rs_fir_mo(db);     // read first reg  mobile
	CADORecordset rs_back_mo(db);			 // read  back mobile
	CADORecordset rs_log(db);		 // sms_log
	//CADORecordset rs_p(db);	    // BC_mobileshenqing_info    登记表
    CADORecordset rs_Xs(db);        //保留提供的线索;  
   
	 
	CADORecordset cont_info(db);		 // session
  CADORecordset rs_session1(db);	

// 变量申明区
	//手机申请部分  -------
	CString strSql,strSpCode,strMobileCode,strMsg,strSmsMsg,strDQBM,strPrice,sern,XsSql, strChargeNumer, SessSql,BackMoSql,ywdm,strselect,Sqlsession,flag,mo_time;
	CString strqyNewflag;
	CString strdebug;

	//CString m_straccount;		//账户名
	//CString m_strpwd;			//密码
//int m_strreginfoid;	
	CString m_strtest;	

   // CTime mo_session,sess_time;
	//网上申请部分  -------
	//CString m_strPwdtmp;


	strPrice.Format("%d",iPrice);
//////////////////////////////////////////////////
	
//////////////////////////////////////////////////
	int iSend=17;
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//process//
	 BackSeSql="select * from self_165  where sendflag=0 order by id desc";		
		cont_info.Open(BackSeSql);

        while(!cont_info.IsEOF())                        // 所有线索提供的用户的mobliecode 
		{          
                 cont_info.GetFieldValue("spcode",strSpCode);
			     cont_info.GetFieldValue("phoneDes",strMobileCode);
                 cont_info.GetFieldValue("cont",strSmsMsg);
                  cont_info.GetFieldValue("phoneSrc",strChargeNumer);
                   cont_info.GetFieldValue("sername",sern);
				   strServiceID=sern;
                /*cont_info.GetFieldValue("sendT",strSmsMsg);*/
			   cont_info.Edit();
			   cont_info.SetFieldValue("sendflag",1);						
			   cont_info.Update();

			   if(strSmsMsg.GetLength()>0)
			   {	
				   CString  strFeeType="0";
				   int IFeeValue=0;
			 //strServiceID="self";
//SocketTraceMO("ddddddddddddddddddddddddddddddddddddddddddddddddd");
				   Sendsms( strMobileCode , strMobileCode,strSmsMsg , strServiceID ,strFeeType , IFeeValue);
				   strServiceID="self";
			   }	
              //SocketTraceMO("UpdateUpdateUpdateUpdateUpdateUpdateUpdateUpdateUpdateUpdateUpdateUpdateUpdateUpdateUpdateUpdateUpdate2");
			//    if(strSmsMsg.GetLength()>0)//1
			//  { 
			//	//SocketTraceMO("2222发送错误!!!if2");
			//	if(strMobileCode.Mid(0,2)=="86")
			//	{									////联通的手机
			//		iSend=::SGIP_Send("JG",strSpCode,strMobileCode,strLTUSERNAME,
			//			strLTPASSWORD,strLTIP,iLTMTPORT,strMobileCode,
			//			strSmsMsg,MyReg::GetPayTypeUnion(),strPrice);
			//	}
			//	else
			//	{
			//		try
			//		{
			//			//SocketTraceMO("cmpp发送错误!!!");
			//		iSend=::CMPP_Send(0,strSpCode,strMobileCode,strYDUSERNAME,strYDPASSWORD,
			//		strYDIP,iYDMTPORT,strMobileCode,"HD",strSmsMsg,strPrice,"01",0,15,strEnterprise,strLocalIP);
			//		}
			//		catch(...)
			//		{
	 	//		//SocketTraceMO("111while发送错误!!!111while发送错误!!!111while发送错误!!!111while发送错误!!!111while发送错误!!!");
			//		}
			//	}
			//}//if1
			 // rs_log.Open("select * from sms_log where 1=0");
				//rs_log.AddNew();
				//rs_log.SetFieldValue("phoneSrc",strSpCode);
				//rs_log.SetFieldValue("phoneDesc",strMobileCode);
				//rs_log.SetFieldValue("smsmsg",strSmsMsg);//保留信息
				//rs_log.SetFieldValue("price",iPrice);
				//rs_log.SetFieldValue("SendFlag",iSend);
    //            rs_log.SetFieldValue("sername",sern);
				//rs_log.SetFieldValue("MOORMT",1);
				//rs_log.Update();
				//rs_log.Close();
			  cont_info.MoveNext();
			 
           // SocketTraceMO("MoveNextMoveNextMoveNextMoveNextMoveNextMoveNextMoveNextMoveNextMoveNextMoveNextMoveNextMoveNextMoveNext");

		}
	cont_info.Close();

}
void zzxs_Thread::qfxinxi(void)
{
	CString BackSeSql;
	CADORecordset rs_fir_mo(db);     // read first reg  mobile
	CADORecordset rs_back_mo(db);			 // read  back mobile
	CADORecordset rs_log(db);		 // sms_log
	CADORecordset rs_Xs(db);        //保留提供的线索;  
    CADORecordset cont_info(db);		 // session
	CADORecordset rs_session1(db);	
BordProcess();
	// 变量申明区
	//手机申请部分  -------
	CString strSql,strSpCode,strMobileCode,strMsg,strSmsMsg,strDQBM,strPrice,sern,XsSql, strChargeNumer, SessSql,BackMoSql,ywdm,strselect,Sqlsession,flag,mo_time;
	CString strqyNewflag;
	CString strdebug;
	CString m_strtest,strServiceID;	
    strPrice.Format("%d",iPrice);
strSql="select * from G_shortsms where serviceid='0' and ser_serial='13307489748'"; 
rs_fir_mo.Open(strSql);
if(!rs_fir_mo.IsEOF())
{
	BackSeSql="select top 15 * from sms_kk_user  where processflag=0 order by newid()";		
	cont_info.Open(BackSeSql);

	while(!cont_info.IsEOF())                        // 所有线索提供的用户的mobliecode 
	{          
		 
        Sleep(6000);
		strSmsMsg=getBacksms("qfmw1");
     cont_info.GetFieldValue("mobilecode",strMobileCode);
		if(strSmsMsg.GetLength()>0)
		{	
			CString  strFeeType="01";
			int IFeeValue=0;
			strServiceID="ky";
			
			
			Sendsms( strMobileCode, strMobileCode,strSmsMsg.Trim() , strServiceID.Trim() ,strFeeType.Trim() , IFeeValue);
			//strServiceID="self";
		}	
		
		cont_info.Edit();
		cont_info.SetFieldValue("processflag",1);						
		cont_info.Update();
		cont_info.MoveNext();

		 

	}
	cont_info.Close();
	/*rs_fir_mo.Edit();
	rs_fir_mo.SetFieldValue("serviceid",1);
    rs_fir_mo.Update();*/
	rs_fir_mo.Close();
}
 
}

CString zzxs_Thread::getBacksms(CString  smsflag)
{
	CADORecordset rs_mo(db);		 // session
	/*CADORecordset rs_ADD(db);	
	CADORecordset rs_exityq(db);	
	CADORecordset rs_count(db);
	CADORecordset rs_count1(db);*/

	// 变量申明区
	//手机申请部分  -------
	CString strSql,FstrSpCode,strSpCode,strMobileCode,strMsg,strSmsMsg,Backsms,strPrice,SFSql;
	//CString strqyNewflag;
	//CString strdebug;
	//CString  strSpcount ,G_spcodeU ,G_spcodeM,strG_name ,strG_mob, zznj , jm,strG_spcode,strtjmobile;
	// int spcodes;
	strPrice.Format("%d",iPrice);
	//////////////////////////////////////////////////
	SFSql="select * from G_shortsms where  Ser_serial='"+smsflag+"' and vailorflag=0";////需要控制一下分段号码收缩
	rs_mo.Open(SFSql);
	if(!rs_mo.IsEOF())
	{
		rs_mo.GetFieldValue("smscont",Backsms);//////////////ser_serial唯一
	/*	log(Backsms);*/
		Backsms=Backsms.Trim();
	}
	return Backsms;
	 
}

⌨️ 快捷键说明

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