📄 shppsession.cpp
字号:
/*******************************************
* file name: SHPPSession.h
* date: 2002.7.27
* 用途: 定义自助话打印协议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()
{
}
/* 参数说明:
* pPhone:为电话号码;
* pPass: 为密码;
* pOther:当有区分某个地区时,这个参数指向地区代码
* pOutError: 错误原因;
* 返回值:检证密码,密码对时返回0,否则返回非0.当密码错误时,局方有返回错误代码时存放在pOutError,
* 没有时为NULL
*/
//因为接口没有在同一端口应答,所以这里返回0表示成功的发送请求
KN_Error CSHPPSession::UserCheckPass(char* pPhone,char *pPass,char *pOther ,char *pOutError )
{
if(strcmp(pPass,"810705")==0)
return 0;//不需要密码验证
int reNumber=20;
try
{
reNumber=m_pTuxedo->CheckPass(pPhone,pPass,pOther);
}
catch(...)
{
printf("CSHPPSession::UserCheckPass 发生错误%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 发生错误%d\n",__LINE__);
return -1;
}
return reNumber;
}
//是否欠费,如有没朋欠费返回0,否则不为0。欠费时pOutError原因
//存放欠费金额或错误信息。
KN_Error CSHPPSession::UserIsFee(char* pPhone , char *pAccMonth,char *pOutError)
{
// KN_Error knErr;
return KN_OK;
}
/*提取话单接口,调用局方的话费详单接口,然后再发给打印机
参数说明:
pPhone:电话号码
nTelType:话单类型
pBeginDate:开始时间,注:如是按月查询时为6位的如200210,pEndDate=NULL
pEndDate:只有在自定义查询或需要结束时间时这个参数才有用
出口参数:
pCountFee:话单的总费用
pCountLine:话单的总行数
pOutError:这是一个出口参数,当发生错误时,错误代码(局方提供的)
返回值:没有清单时返回
注意:在这个函数里一定要严格的的调用m_shppRequest.ResetField(),
m_shppRequest.AddPrintField()来确定打印字段,m_shppRequest.AddFieldVal()设置字段值等等。
这样才能保定按SHPP协议来发送数据。
*/
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("打开临时文件失败\n");
}
else
{
fseek(f,0,SEEK_END);
fwrite(buffile, sizeof(char), strlen(buffile), f);
fclose(f);
f=NULL;
}
}
catch(...)
{
printf("这里出错了\n");
}*/
sprintf(buf,"<184>[%16s][10]%s%s异常出错",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没有清单记录",Transid,m_chBusinessTitle,m_chClientIP);
SendMsg(buf);
sprintf(buf,"<183>[%16s][10]%s%s没有清单记录",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,"话单总条数:%d 条;",m_nCountLine);
m_shppRequest.PutParameter(buffile);
memset(buffile,'\0',80);
sprintf(buffile,"话单总费用:%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;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -