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

📄 thread2.cpp

📁 电信短信应用smgp1.3协议网关,中兴开发包
💻 CPP
📖 第 1 页 / 共 2 页
字号:
							m_recordset->Close();
							command.Format("select*from T_gwdx_service where destId='%s' and command='%s'",destPhone,serviceTemp);
							hr=m_recordset->Open(command.GetBuffer(0), _variant_t((IDispatch*)m_pDlg->m_connection,true),adOpenStatic,adLockOptimistic,adCmdText);
							if(!m_recordset->adoEOF) i=5;
						}
					}
				////type='a'(可变长号段)
					if(i==0)
					{
						m_recordset->Close();
						hr=m_recordset->Open("select*from T_gwdx_service where type='a'", _variant_t((IDispatch*)m_pDlg->m_connection,true),adOpenStatic,adLockOptimistic,adCmdText);
						if(!m_recordset->adoEOF) 
							while(!m_recordset->adoEOF)
							{
								dbTemp.Empty();
								if(m_recordset->GetCollect("destId").vt != VT_NULL) dbTemp=m_recordset->GetCollect("destId").bstrVal;
								j=dbTemp.GetLength();
								if(j<destPhone.GetLength())//old if(j>4)
								{
									if(destPhone.Mid(0,j).Compare(dbTemp.GetBuffer(0))==0)
									{
										i=4;
										server.Empty();
										if(m_recordset->GetCollect("server").vt != VT_NULL) server=m_recordset->GetCollect("server").bstrVal;
										server_table.Empty();
										if(m_recordset->GetCollect("server_table").vt != VT_NULL) server_table=m_recordset->GetCollect("server_table").bstrVal;
										if(server_table=="")server_table="T_gwdx_wdwGW";
										m_recordset->Close();
										break;
									}
								}
								m_recordset->MoveNext();
							}//while
					}
				////////从内存表匹配
					if(i==0&&strlen(serviceTemp)>0)
					{
						k=0;
						dbTemp.Empty();
						dbTemp=serviceTemp;
						while(strlen(sybase_command[k].destId)>0&&k<100)
						{
							if(destPhone==sybase_command[k].destId&&(strlen(serviceTemp)>strlen(sybase_command[k].command)))
								if(dbTemp.Mid(0,strlen(sybase_command[k].command))==sybase_command[k].command)
								{
									serviceTemp[strlen(sybase_command[k].command)]=0;
									m_recordset->Close();
									command.Format("select*from T_gwdx_service where destId='%s' and command='%s'",destPhone,serviceTemp);
									hr=m_recordset->Open(command.GetBuffer(0), _variant_t((IDispatch*)m_pDlg->m_connection,true),adOpenStatic,adLockOptimistic,adCmdText);
									if(!m_recordset->adoEOF) i=6;
									break;
								}
							k++;
						}
					}
					if(i==0&&strlen(serviceTemp)>0)rec_command=0;
				//////////////
					if(i!=4)
						if(!m_recordset->adoEOF)
						{
							server.Empty();
							if(m_recordset->GetCollect("server").vt != VT_NULL) server=m_recordset->GetCollect("server").bstrVal;
							server_table.Empty();
							if(m_recordset->GetCollect("server_table").vt != VT_NULL) server_table=m_recordset->GetCollect("server_table").bstrVal;
							if(server_table=="")server_table="T_gwdx_wdwGW";
							commandType.Empty();
							if(m_recordset->GetCollect("type").vt != VT_NULL) commandType=m_recordset->GetCollect("type").bstrVal;
							serviceID.Empty();
							if(m_recordset->GetCollect("service_id").vt != VT_NULL) serviceID=m_recordset->GetCollect("service_id").bstrVal;
							service.Empty();
							if(m_recordset->GetCollect("service_name").vt != VT_NULL)service=m_recordset->GetCollect("service_name").bstrVal;
							fixedFee.Empty();
							if(m_recordset->GetCollect("fixedfee").vt != VT_NULL) fixedFee=m_recordset->GetCollect("fixedfee").bstrVal;
							content1.Empty();
							if(m_recordset->GetCollect("content_ok").vt != VT_NULL)content1=m_recordset->GetCollect("content_ok").bstrVal;
							content_err.Empty();
							if(m_recordset->GetCollect("content_err").vt != VT_NULL)content_err=m_recordset->GetCollect("content_err").bstrVal;							
							m_recordset->Close();
							content1.Replace("'","''");
							content_err.Replace("'","''");
							service.Replace("'","''");
							if(commandType=="2"&&server=="1")//订阅
							{
								i=5;
								if(content_err=="")content_err="您已经订阅过"+service;
								if(content1=="")content1="您已成功订阅"+service;
								command.Empty();
								command.Format("select*from T_gwdx_subscribe where srcPhone='%s' and service_id='%s'",srcPhone,serviceID);
								hr=m_recordset->Open(command.GetBuffer(0), _variant_t((IDispatch*)(m_pDlg->m_connection),true),adOpenStatic,adLockOptimistic,adCmdText);	
								if(!m_recordset->adoEOF)//订阅过
								{
									dbTemp.Empty();
									if(m_recordset->GetCollect("flag").vt != VT_NULL) flag=m_recordset->GetCollect("flag").bstrVal;
									m_recordset->Close();
									command.Empty();
									if(flag=="0")//正在订阅
									{
										command.Format("insert into  T_gwdx_send_xlt values(0,3,0,'%s','%s','00','0','0','%s','%s','%s','%s',getdate())",serviceID,service,destPhone,srcPhone,srcPhone,content_err);
										server_table.Empty();
									}
									else//已取消订阅
									{
										command.Format("update  T_gwdx_subscribe set origTime=getdate(),flag='0'  where srcPhone='%s' and service_id='%s'",srcPhone,serviceID);
										hr=m_recordset->Open(command.GetBuffer(0), _variant_t((IDispatch*)(m_pDlg->m_connection),true),adOpenStatic,adLockOptimistic,adCmdText);	
										command.Empty();
										command.Format("insert into  T_gwdx_send_xlt values(0,3,0,'%s','%s','00','0','0','%s','%s','%s','%s',getdate())",serviceID,service,destPhone,srcPhone,srcPhone,content1);
									}
									hr=m_recordset->Open(command.GetBuffer(0), _variant_t((IDispatch*)(m_pDlg->m_connection),true),adOpenStatic,adLockOptimistic,adCmdText);						
								}
								else//第一次订阅
								{
									m_recordset->Close();
									command.Empty();
									command.Format("insert into T_gwdx_subscribe values('%s','%s','%s',null,null,'02','%s',dateadd(day,3,getdate()),getdate(),'0','0')",srcPhone,serviceID,service,fixedFee);
									hr=m_recordset->Open(command.GetBuffer(0), _variant_t((IDispatch*)(m_pDlg->m_connection),true),adOpenStatic,adLockOptimistic,adCmdText);	
									command.Empty();
									command.Format("insert into  T_gwdx_send_xlt values(0,3,0,'%s','%s','00','0','0','%s','%s','%s','%s',getdate())",serviceID,service,destPhone,srcPhone,srcPhone,content1);
									hr=m_recordset->Open(command.GetBuffer(0), _variant_t((IDispatch*)(m_pDlg->m_connection),true),adOpenStatic,adLockOptimistic,adCmdText);	
								}
							}//订阅
							if(commandType=="3"&&server=="1")//取消订阅
							{
								command.Empty();
								command.Format("select  datediff(hour,getdate(),subTime) m_time,flag_1 from T_gwdx_subscribe where srcPhone='%s' and service_id='%s' and flag='0'",srcPhone,serviceID);
								hr=m_recordset->Open(command.GetBuffer(0), _variant_t((IDispatch*)m_pDlg->m_connection,true),adOpenStatic,adLockOptimistic,adCmdText);
								command.Empty();
								if(!m_recordset->adoEOF)//有订阅
								{
									j=0;
									if(m_recordset->GetCollect("m_time").vt != VT_NULL) j=m_recordset->GetCollect("m_time").lVal;
									flag_1.Empty();
									if(m_recordset->GetCollect("flag_1").vt != VT_NULL) flag_1=m_recordset->GetCollect("flag_1").bstrVal;
									m_recordset->Close();
									if(content1=="")content1="您已成功取消"+service;
									if(flag_1!="0")j=1;
									if(j<=0)//超过3天且还未交费
									{
										command.Format("update T_gwdx_subscribe set subTime=dateadd(month,1,subTime),flag='1'  where srcPhone='%s' and service_id='%s'",srcPhone,serviceID);
										hr=m_recordset->Open(command.GetBuffer(0), _variant_t((IDispatch*)(m_pDlg->m_connection),true),adOpenStatic,adLockOptimistic,adCmdText);					
										command.Format("insert into T_gwdx_unsubscribe values('%s','%sBY','%s','02','%s',getdate())",srcPhone,serviceID,service,fixedFee);
										hr=m_recordset->Open(command.GetBuffer(0), _variant_t((IDispatch*)(m_pDlg->m_connection),true),adOpenStatic,adLockOptimistic,adCmdText);					
										command.Empty();
										command.Format("insert into  T_gwdx_send_xlt values(0,4,0,'%sBY','%s','02','0','%s','%s','%s','%s','%s',getdate())",serviceID,service,fixedFee,destPhone,srcPhone,srcPhone,content1);
									}
									else
									{
										if(j>0&&j<72)//不足三天
										{
											command.Format("delete from T_gwdx_subscribe  where srcPhone='%s' and service_id='%s'",srcPhone,serviceID);
											hr=m_recordset->Open(command.GetBuffer(0), _variant_t((IDispatch*)m_pDlg->m_connection,true),adOpenStatic,adLockOptimistic,adCmdText);
										}
										if(j>=72)//超过3天已交费
										{
											command.Format("update T_gwdx_subscribe set flag='1'  where srcPhone='%s' and service_id='%s'",srcPhone,serviceID);
											hr=m_recordset->Open(command.GetBuffer(0), _variant_t((IDispatch*)(m_pDlg->m_connection),true),adOpenStatic,adLockOptimistic,adCmdText);					
										}
										command.Empty();
										command.Format("insert into  T_gwdx_send_xlt values(0,3,0,'%s','%s','00','0','0','%s','%s','%s','%s',getdate())",serviceID,service,destPhone,srcPhone,srcPhone,content1);
									}	
									hr=m_recordset->Open(command.GetBuffer(0), _variant_t((IDispatch*)(m_pDlg->m_connection),true),adOpenStatic,adLockOptimistic,adCmdText);													
								}
								else //没有订阅
								{
									m_recordset->Close();
									if(content_err=="")content_err="您没有订阅"+service;
									command.Format("insert into  T_gwdx_send_xlt values(0,3,0,'%s','%s','00','0','0','%s','%s','%s','%s',getdate())",serviceID,service,destPhone,srcPhone,srcPhone,content_err);
									hr=m_recordset->Open(command.GetBuffer(0), _variant_t((IDispatch*)(m_pDlg->m_connection),true),adOpenStatic,adLockOptimistic,adCmdText);				
								}
							}//取消订阅
							/*
							command.Empty();
							command.Format("insert into  Sms_sp_bill values('%s','%s','%s','%s','%s','%s',%d)",srcPhone,destPhone,time1,serviceID,content,feetype,atoi(feecode));
							hr=send_recordset->Open(command.GetBuffer(0), _variant_t((IDispatch*)(m_pDlg->m_connection),true),adOpenStatic,adLockOptimistic,adCmdText);				
							*/		
						}//m_recordset->adoEOF
						else
						{
							m_recordset->Close();
							command.Empty();
							command.Format("insert into  T_gwdx_send_xlt values(0,3,0,'0','0','00','0','0','1186168','%s','%s','对不起,没有与您的发送代码相符的信息,请确定您的发送内容是否有误.',getdate())",srcPhone,srcPhone);
							hr=m_recordset->Open(command.GetBuffer(0), _variant_t((IDispatch*)(m_pDlg->m_connection),true),adOpenStatic,adLockOptimistic,adCmdText);								
						}
						memset(m_http,0,8);
						if(server_table.GetLength()>7)
						{
							memcpy(m_http,server_table.GetBuffer(0),7);
							memcpy(m_http,_strupr(m_http),strlen(m_http));
						}
						if(server!="1"&&server_table!=""&&(strcmp(m_http,"HTTP://")!=0))
						{
							command.Empty();
							command.Format("insert into  %s  values('%s','%s','%s','%s','%s','%s',getdate(),'%d')",server_table,srcPhone,destPhone,serviceTemp,serviceID,content,time1,i);
							hr=m_recordset->Open(command.GetBuffer(0), _variant_t((IDispatch*)(m_pDlg->m_connection),true),adOpenStatic,adLockOptimistic,adCmdText);								
						}
						if(server=="1"&&commandType=="2"&&server_table!=""&&(strcmp(m_http,"HTTP://")!=0))
						{
							command.Empty();
							command.Format("insert into  %s  values('%s','%s','%s','%s','%s','%s',getdate(),'d')",server_table,srcPhone,destPhone,serviceTemp,serviceID,content,time1);
							hr=m_recordset->Open(command.GetBuffer(0), _variant_t((IDispatch*)(m_pDlg->m_connection),true),adOpenStatic,adLockOptimistic,adCmdText);					
						}
						if(strcmp(m_http,"HTTP://")==0)
						{
							command.Empty();
							command.Format("insert into  T_gwdx_HttpGW  values('%s','%s','%s','%s','%s','%s','%s',getdate(),'1')",srcPhone,destPhone,serviceTemp,serviceID,server_table,content,time1);
							hr=m_recordset->Open(command.GetBuffer(0), _variant_t((IDispatch*)(m_pDlg->m_connection),true),adOpenStatic,adLockOptimistic,adCmdText);					
						}
						sprintf(f_name,"log/2Thread%d%02d%02dok.txt",t.GetYear(),t.GetMonth(),t.GetDay());
						buffer.Format("%s,%s,%s,%s,%d\n",time1,srcPhone,destPhone,content,i);
						if((file=fopen(f_name,"a"))==NULL) continue;
						fwrite(buffer.GetBuffer(0),sizeof(char),buffer.GetLength(),file);
						fclose(file);
					}//try
					catch(_com_error e)
 					{
						m_pDlg->AddString("Thread2操作数据库失败");	
						if(m_recordset->State)m_recordset->Close();
						sprintf(f_name,"log/2Thread%d%02d%02dfail.txt",t.GetYear(),t.GetMonth(),t.GetDay());
						if((file=fopen(f_name,"a"))==NULL) continue;
						buffer.Empty();
						buffer.Format("%s,%s,%s,%s,%s,%d\n",time1,srcPhone,destPhone,content,command,i);
						fwrite(buffer.GetBuffer(0),sizeof(char),buffer.GetLength(),file);
						fclose(file);
						isdbConnect=1;
 					}
			}//res=1;
			/*
			if(res==4)//reoprt
			{
				sprintf(f_name,"log/2Thread%d%02d%02dreport.txt",t.GetYear(),t.GetMonth(),t.GetDay());
				buffer.Format("%s,%s,%s,%s,%d\n",time1,srcPhone,destPhone,content,res);
				if((file=fopen(f_name,"a"))==NULL) continue;
				fwrite(buffer.GetBuffer(0),sizeof(char),buffer.GetLength(),file);
				fclose(file);
			}
			*/
		}
	}//while(!m_stop_state)
if(m_recordset->State)m_recordset->Close();
m_recordset=NULL;
m_pDlg->AddString("thread2退出");
//m_thread1->m_stop_state=true;
return 0;
}

⌨️ 快捷键说明

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