BOOL RzxCoreIO::SendPhotoToCenter(LPCSTR lpIdNum,
LPCSTR lpImgPath,
int nImgType,
LPSTR lpRetErrorMsg)
{
//连接服务器
char chost[25]={0};
int nPort = 0;
CRzxProfile objRzxProfile;
if (objRzxProfile.GetCityIp(chost) == FALSE)
return FALSE;
nPort = objRzxProfile.GetCardPort();
Inition();
RzxProtocol objConn;
BOOL rtn=objConn.Connect(chost,nPort);
if(!rtn)
{
printf("Error:Connect server failed!\n");
return FALSE;
}
USER_INFO_GRAPH szPhotoData;
char *pPhotoData = NULL;
memset(&szPhotoData, 0, sizeof(szPhotoData));
objRzxProfile.GetBarId(szPhotoData.szBarId);
if (!PackPhotoInfo(lpIdNum, lpImgPath, nImgType, szPhotoData, lpRetErrorMsg))
{
delete [] szPhotoData.pData;
return FALSE;
}
//发送包头
TPACKHEAD packet;
memset(&packet,0,sizeof(packet));
PackHeadInfo(CMD_SEND_PHOTO_TO_CENTER, ntohl(szPhotoData.lGraphSize)+sizeof(USER_INFO_GRAPH)-sizeof(char *), packet);
if (objConn.Write(&packet, sizeof(TPACKHEAD)) == 0)
{
delete [] szPhotoData.pData;
return FALSE;
}
//发送照片信息头
if (objConn.Write(&szPhotoData, sizeof(USER_INFO_GRAPH)-sizeof(char *)) == 0)
{
delete [] szPhotoData.pData;
return FALSE;
}
//发送照片数据
if (objConn.Write(szPhotoData.pData, ntohl(szPhotoData.lGraphSize)) == 0)
{
delete [] szPhotoData.pData;
return FALSE;
}
delete [] szPhotoData.pData;
//接收中心回应
memset(&packet,0,sizeof(packet));
if(objConn.Read(&packet,sizeof(packet)) == 0)
{
return FALSE;
}
REGIST_ACK stRetAck;
memset(&stRetAck, 0, sizeof(REGIST_ACK));
if(objConn.Read(&stRetAck,sizeof(REGIST_ACK)) == 0)
{
return FALSE;
}
else
{
strcpy(lpRetErrorMsg,stRetAck.result);
if (stRetAck.IsRegist == 1) //图片上传成功
return TRUE;
else
return FALSE;
}
objConn.Close();
WSACleanup();
return TRUE;
}
//通讯包头定义
struct TPACKHEAD
{
unsigned char head; //头标志,为88
unsigned char verifyflag;//为0x0E时,为正确包
unsigned char command; //1--挂失库对时 2--挂失记录个数下载 3--具体挂失记录下载
//4--请求挂失记录上传 5--具体挂失记录上传
//6--数据库中总的挂失记录个数下载
//7--数据库中各个具体挂失记录下载?
//11--请求用户资料上传
//12--具体用户资料上传
//13--请求临时用户资料上传
//14--具体临时用户资料上传
//15--ID卡变化记录个数下载
//16--ID卡具体变化记录下载
//17--ID卡数据库中总的记录个数下载
//18--ID卡数据库中各个具体记录下载?
//19--请求验证ID卡是否已注册
//20--上传用户ID卡信息
//21--下载ID库对时
//32--验证证件是否开过卡 实现一人一卡
//33--发送实名注册请求
unsigned char tail; //尾标志
unsigned int len; //包体的长度
};
typedef struct USER_INFO_GRAPHtag
{
char id_num[19]; //ID卡号码
char szBarId[11]; //单位编号
unsigned char cGraphKind; //图片所属类别(1、照片;2、证件扫描图)
char sGraphClass[4]; //图片格式(如gif,jpg等)
unsigned long lGraphSize; //图片大小
char *pData; //图片数据
}USER_INFO_GRAPH;
struct REGIST_ACK //add by 张海 20060313
{
char IsRegist; //1:成功 2:失败
char result[50]; //是否成功或者失败原因
};