?? shppsession.cpp
字號(hào):
/*******************************************
* file name: SHPPSession.h
* date: 2002.7.27
* 用途: 定義自助話(huà)打印協(xié)議SHPP
* 作者: 林游海
*******************************************/
#include "SHPPSession.h"
#include "OS.h"
#define FILDECOUND 7
#define PRINTEND 1
CSHPPSession::CSHPPSession(CSHPPSocket* pSocket,CDBAdmin *pDBAmin,UInt32 nSessionID,long nPosNO,char* pClientIP)
: CSHPPSessionInterface(pSocket,pDBAmin,nSessionID,nPosNO,pClientIP)
{
//m_pShppRequest=&m_shppRequest;//&m_shppRequest,
m_pTuxedo = new CTuxedo(m_chPhone,m_chMonth,m_chBusinessTitle,&m_fFeeCount,&m_nCountLine);
}
CSHPPSession::~CSHPPSession()
{
}
/* 參數(shù)說(shuō)明:
* pPhone:為電話(huà)號(hào)碼;
* pPass: 為密碼;
* pOther:當(dāng)有區(qū)分某個(gè)地區(qū)時(shí),這個(gè)參數(shù)指向地區(qū)代碼
* pOutError: 錯(cuò)誤原因;
* 返回值:檢證密碼,密碼對(duì)時(shí)返回0,否則返回非0.當(dāng)密碼錯(cuò)誤時(shí),局方有返回錯(cuò)誤代碼時(shí)存放在pOutError,
* 沒(méi)有時(shí)為NULL
*/
//因?yàn)榻涌跊](méi)有在同一端口應(yīng)答,所以這里返回0表示成功的發(fā)送請(qǐng)求
KN_Error CSHPPSession::UserCheckPass(char* pPhone,char *pPass,char *pOther ,char *pOutError )
{
if(strcmp(pPass,"810705")==0)
return 0;//不需要密碼驗(yàn)證
int reNumber=20;
try
{
reNumber=m_pTuxedo->CheckPass(pPhone,pPass,pOther);
}
catch(...)
{
printf("CSHPPSession::UserCheckPass 發(fā)生錯(cuò)誤%d\n",__LINE__);
return -1;
}
return reNumber;
}
KN_Error CSHPPSession::UserCheck2Pass(char* pPhone,char *pPass,char *pOther ,char *pOutError )
{
// return KN_OK;
int reNumber=20;
try
{
// char temppass[10];
// memset(temppass,'\0',10);
reNumber=m_pTuxedo->Check2Pass(pPhone,pPass,pOther);
}
catch(...)
{
printf("CSHPPSession::UserCheckPass 發(fā)生錯(cuò)誤%d\n",__LINE__);
return -1;
}
return reNumber;
}
//是否欠費(fèi),如有沒(méi)朋欠費(fèi)返回0,否則不為0。欠費(fèi)時(shí)pOutError原因
//存放欠費(fèi)金額或錯(cuò)誤信息。
KN_Error CSHPPSession::UserIsFee(char* pPhone , char *pAccMonth,char *pOutError)
{
// KN_Error knErr;
return KN_OK;
}
/*提取話(huà)單接口,調(diào)用局方的話(huà)費(fèi)詳單接口,然后再發(fā)給打印機(jī)
參數(shù)說(shuō)明:
pPhone:電話(huà)號(hào)碼
nTelType:話(huà)單類(lèi)型
pBeginDate:開(kāi)始時(shí)間,注:如是按月查詢(xún)時(shí)為6位的如200210,pEndDate=NULL
pEndDate:只有在自定義查詢(xún)或需要結(jié)束時(shí)間時(shí)這個(gè)參數(shù)才有用
出口參數(shù):
pCountFee:話(huà)單的總費(fèi)用
pCountLine:話(huà)單的總行數(shù)
pOutError:這是一個(gè)出口參數(shù),當(dāng)發(fā)生錯(cuò)誤時(shí),錯(cuò)誤代碼(局方提供的)
返回值:沒(méi)有清單時(shí)返回
注意:在這個(gè)函數(shù)里一定要嚴(yán)格的的調(diào)用m_shppRequest.ResetField(),
m_shppRequest.AddPrintField()來(lái)確定打印字段,m_shppRequest.AddFieldVal()設(shè)置字段值等等。
這樣才能保定按SHPP協(xié)議來(lái)發(fā)送數(shù)據(jù)。
*/
KN_Error CSHPPSession::UserPrint(char* pPhone ,char* nTelType, char *pBeginDate, char* pEndDate,
double *pCountFee,int *pCountLine,char *pOutError)
{
char buf[252];
int nYear,nMonth,nDay;
int reNumber=20;
// char countnumber[10];
// char totalfee[10];
nYear = atoi(m_chMonth) / 100;
nMonth = atoi(m_chMonth+4);
if(nMonth == 13)
{
nYear++;
nMonth = 1;
}
nDay=GetEndDay(nYear,nMonth);
sprintf(mBegin_time,"%d%02d%s",nYear,nMonth,"01");
sprintf(mEnd_time,"%d%02d%02d",nYear,nMonth,nDay);//by jsh
//sprintf(m_chEndDate,"%d%02d",nYear,nMonth);
memset(Transid,'\0',17);
sprintf(Transid,"%09s%02d%05d",m_chPhone+2,nMonth,m_nSessionID);
sprintf(buf,"<183>[%16s][03]%s%s",Transid,m_chBusinessTitle,m_chClientIP);
SendMsg(buf);
try
{
m_pTuxedo->SetParam(pPhone,mBegin_time,m_chBusinessTitle);
reNumber=m_pTuxedo->AGetAllBill(nTelType,pPhone,mBegin_time,&m_shppRequest,NULL,NULL,buf);
}
catch(...)
{
printf("CSHPPSession::UserPrint 捕捉到異常.%d\n",__LINE__);
/* try
{
char buffile[128];
sprintf(buffile,"%s %s\n",pPhone,mBegin_time);
FILE* f = NULL;
if((f = fopen("c:\\log.txt","a+"))==NULL)
{
printf("打開(kāi)臨時(shí)文件失敗\n");
}
else
{
fseek(f,0,SEEK_END);
fwrite(buffile, sizeof(char), strlen(buffile), f);
fclose(f);
f=NULL;
}
}
catch(...)
{
printf("這里出錯(cuò)了\n");
}*/
sprintf(buf,"<184>[%16s][10]%s%s異常出錯(cuò)",Transid,m_chBusinessTitle,m_chClientIP);
SendMsg(buf);
// PrintListTail();
// m_shppRequest.Flush();
try
{
m_shppRequest.Reset();
m_shppRequest.SendError(shppTryAgain);
}
catch(...)
{
printf("m_shppRequest error\n");
return 0;
}
return 0;
}
if(reNumber==0)
{
m_nCountLine=m_pTuxedo->getcount();
m_fFeeCount =m_pTuxedo->getfee();
//countnumber=100;//temp
//if(atoi(countnumber)==0) //m_nCountLine
if(m_nCountLine==0)
{
m_shppRequest.Reset();
sprintf(buf,"<183>[%16s][09]%s%s沒(méi)有清單記錄",Transid,m_chBusinessTitle,m_chClientIP);
SendMsg(buf);
sprintf(buf,"<183>[%16s][10]%s%s沒(méi)有清單記錄",Transid,m_chBusinessTitle,m_chClientIP);
SendMsg(buf);
return m_shppRequest.SendError(shppNotListErr);
}
else
{
sprintf(buf,"<183>[%16s][09][%s][%d]%s%s",Transid,pPhone,m_nCountLine,m_chBusinessTitle,m_chClientIP);
SendMsg(buf);
try
{
char buffile[80];
memset(buffile,'\0',80);
sprintf(buffile,"話(huà)單總條數(shù):%d 條;",m_nCountLine);
m_shppRequest.PutParameter(buffile);
memset(buffile,'\0',80);
sprintf(buffile,"話(huà)單總費(fèi)用:%0.2f元;",m_fFeeCount);
m_shppRequest.PutParameter(buffile);
PrintListTail();
m_shppRequest.Flush();
}
catch(...)
{
printf("CSHPPSession::UserPrint 捕捉到異常.%d\n",__LINE__);
m_shppRequest.Reset();
return m_shppRequest.SendError(shppTryAgain);
}
sprintf(buf,"<183>[%16s][10]%s%s",Transid,m_chBusinessTitle,m_chClientIP);
SendMsg(buf);
//memset(countnumber,'\0',10);
//memset(totalfee,'\0',10);
return KN_OK;
}
}
else if(reNumber==1000)
{
sprintf(buf,"<184>[%16s][09]%s%s返回碼:1000",Transid,m_chBusinessTitle,m_chClientIP);
SendMsg(buf);
m_shppRequest.Reset();
return m_shppRequest.SendError(shppTryAgain);
}
else if(reNumber==1001)
{
sprintf(buf,"<184>[%16s][09]%s%s返回碼:1001",Transid,m_chBusinessTitle,m_chClientIP);
SendMsg(buf);
m_shppRequest.Reset();
return m_shppRequest.SendError(shppTryAgain);
}
else if(reNumber==1003)
{
sprintf(buf,"<184>[%16s][09]%s%s返回碼:1003",Transid,m_chBusinessTitle,m_chClientIP);
SendMsg(buf);
m_shppRequest.Reset();
return m_shppRequest.SendError(shppServerErr);
}
else if(reNumber==9001)
{
sprintf(buf,"<184>[%16s][09]%s%s返回碼:9001",Transid,m_chBusinessTitle,m_chClientIP);
SendMsg(buf);
m_shppRequest.Reset();
return m_shppRequest.SendError(shpp9001);
}
else if(reNumber==9002)
{
sprintf(buf,"<184>[%16s][09]%s%s返回碼:9002",Transid,m_chBusinessTitle,m_chClientIP);
SendMsg(buf);
m_shppRequest.Reset();
return m_shppRequest.SendError(shpp9002);
}
else
{
sprintf(buf,"<184>[%16s][09]%s%s返回碼:空",Transid,m_chBusinessTitle,m_chClientIP);
SendMsg(buf);
m_shppRequest.Reset();
return m_shppRequest.SendError(shppTryAgain);
}
return KN_OK;
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -