#include <stdio.h>
#include "Msg.h"
#include <Winsock2.h>
#include <iostream.h>
#pragma comment (lib,"ws2_32.lib")
DWORD WINAPI RecvProc( LPVOID lpParameter);
DWORD WINAPI SendProc( LPVOID lpParameter);
int g_count = 0;
void main()
{
INMSG* clientMsg = new INMSG;//用于发送服务端的消息(消息头和消息体)
INMSG* lgMsg = new INMSG;
SOCKET client;
sockaddr_in to;
char servername[100] ="192.168.1.72";
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 2, 2 );
err = WSAStartup( wVersionRequested, &wsaData ); //成功则返回0
if ( err != 0 )
return;
if ( LOBYTE( wsaData.wVersion ) != 2 || HIBYTE( wsaData.wVersion ) != 2 )
{
WSACleanup( );
return;
}
client = socket(AF_INET,SOCK_STREAM,0);
to.sin_family = AF_INET;
to.sin_port = htons(5000);
to.sin_addr.s_addr = inet_addr(servername);
int result;
cout<<"正在连接..."<<endl;
result = connect(client,(struct sockaddr *)&to,sizeof(to));
if(result == SOCKET_ERROR)
{
cout<<"对不起,无法连接到目标主机!"<<endl;
closesocket(client);
WSACleanup();
return;
}
else
{
char lgcome[64];//向服务器端发送的BUFFER
char lgbody[512];
char welcome[64];
char welbody[512];
char come[1024];//接收来自于服务器端的BUFFER
char comebody[1024];
/*************************************
消息头
******************************************/
pMsgHeader = new MSGHEADER;
memset(pMsgHeader,0,sizeof(MSGHEADER));
memcpy(pMsgHeader->MsgFromNodeno,"3000",sizeof(pMsgHeader->MsgFromNodeno));
memcpy(pMsgHeader->MsgToNodeno,"0400",sizeof(pMsgHeader->MsgToNodeno));
memcpy(pMsgHeader->MsgType,"0041",sizeof(pMsgHeader->MsgType));//消息类型是开户请求0041
//流水号 = 6位帐务日期+4位银行类别+10位流水号
memcpy(pMsgHeader->MsgStreamNo,"20081100041000000000",sizeof(pMsgHeader->MsgStreamNo));//银行类型是1000
memcpy(pMsgHeader->MsgDateTime,"20081117172238",sizeof(pMsgHeader->MsgDateTime));
memcpy(pMsgHeader->MsgCryptIndex,"0000",sizeof(pMsgHeader->MsgCryptIndex));
memcpy(pMsgHeader->MsgFeeType,"0000",sizeof(pMsgHeader->MsgFeeType));
memcpy(pMsgHeader->MsgLength,"0370",sizeof(pMsgHeader->MsgLength));
memset(clientMsg,0,sizeof(INMSG));
memcpy(clientMsg->pMSGHEADER,pMsgHeader,sizeof(MSGHEADER));
/*****************************************
开户请求包
******************************************/
pOrder_Delivery = new ORDER_DELIVERY;
memset(pOrder_Delivery,'0',sizeof(ORDER_DELIVERY));
memcpy(pOrder_Delivery->BankType,"1000",sizeof(pOrder_Delivery->BankType));//银行类型是1000
memcpy(pOrder_Delivery->BankAreaType,"130311",sizeof(pOrder_Delivery->BankAreaType));
memcpy(pOrder_Delivery->CreditCardType,"2001",sizeof(pOrder_Delivery->CreditCardType));
memcpy(pOrder_Delivery->PaidServiceKey,"0000002091",sizeof(pOrder_Delivery->PaidServiceKey));//(业务键): 2091
memcpy(pOrder_Delivery->CallingNumber1,"9559995599955991",sizeof(pOrder_Delivery->CallingNumber1));
memcpy(pOrder_Delivery->CallingNumber2,"9559995599955992",sizeof(pOrder_Delivery->CallingNumber2));
memcpy(pOrder_Delivery->CallingNumber3,"9559995599955993",sizeof(pOrder_Delivery->CallingNumber3));
memcpy(pOrder_Delivery->CallingNumber4,"9559995599955994",sizeof(pOrder_Delivery->CallingNumber4));
memcpy(pOrder_Delivery->CallingNumber5,"9559995599955995",sizeof(pOrder_Delivery->CallingNumber5));
memcpy(pOrder_Delivery->CallingTotal,"0004",sizeof(pOrder_Delivery->CallingTotal));
memcpy(pOrder_Delivery->ChargeMode,"0",sizeof(pOrder_Delivery->ChargeMode));
memcpy(pOrder_Delivery->EnableBindCall,"1",sizeof(pOrder_Delivery->EnableBindCall));
memcpy(pOrder_Delivery->EnableCreditCall,"1",sizeof(pOrder_Delivery->EnableCreditCall));
memcpy(pOrder_Delivery->EnableRoam,"1",sizeof(pOrder_Delivery->EnableRoam));
memcpy(pOrder_Delivery->ExpectCardNumber,"10002000300040005000",sizeof(pOrder_Delivery->ExpectCardNumber));
memcpy(pOrder_Delivery->InitMoney,"100000000000",sizeof(pOrder_Delivery->InitMoney));
memcpy(pOrder_Delivery->InitPIN,"6666666666",sizeof(pOrder_Delivery->InitPIN));
memcpy(pOrder_Delivery->InterCallLimit,"1",sizeof(pOrder_Delivery->InterCallLimit));
memcpy(pOrder_Delivery->OprType,"0",sizeof(pOrder_Delivery->OprType));
memcpy(pOrder_Delivery->PayMode,"1",sizeof(pOrder_Delivery->PayMode));
memcpy(pOrder_Delivery->RegisterMode,"1",sizeof(pOrder_Delivery->RegisterMode));
memcpy(pOrder_Delivery->Reserved,"1000",sizeof(pOrder_Delivery->Reserved));
memcpy(pOrder_Delivery->ServiceStop,"12345678",sizeof(pOrder_Delivery->ServiceStop));
memcpy(pOrder_Delivery->Signature,"0123456789",sizeof(pOrder_Delivery->Signature));
memcpy(pOrder_Delivery->TopLimit,"100020003000",sizeof(pOrder_Delivery->TopLimit));
memcpy(pOrder_Delivery->TopOverDraft,"100020003000",sizeof(pOrder_Delivery->TopOverDraft));
memcpy(pOrder_Delivery->TotalFee,"100020003000",sizeof(pOrder_Delivery->TotalFee));
/************************************************
签到请求消息
***************************************************/
pLogin = new LOGIN;
memset(pLogin,0,sizeof(LOGIN));
memcpy(pLogin->LoginType , "1", sizeof(pLogin->LoginType));
memcpy(pLogin->SystemNo,"5001", sizeof(pLogin->SystemNo));
while(1)
{
//向服务器端发送消息
//开户0041
memset(welcome, 0, sizeof(welcome));
memcpy(welcome,(char *)clientMsg->pMSGHEADER,sizeof(MSGHEADER));
memset(welbody, 0, sizeof(welbody));
memcpy(welbody,(char *)clientMsg->pMSGHEADER,sizeof(MSGHEADER));
memcpy(&welbody[58],(char *)pOrder_Delivery,sizeof(clientMsg->MsgBuf));
//send(client,welcome,strlen(welcome),0);
send(client,welbody,strlen(welbody),0);
printf("发送消息头\n");
printf("%s",welcome);
printf("\n发送消息体\n");
printf("%s",welbody);
memset(come, 0, sizeof(come));
recv(client,come,sizeof(come),0);
printf("\n接收消息\n");
printf("%s",come);
printf("\n");
/* memset(lgcome, 0, sizeof(lgcome));
memcpy(lgcome,(char *)pMsgHeader,sizeof(MSGHEADER));
memset(lgbody, 0, sizeof(lgbody));
memcpy(lgbody,(char *)pLogin,sizeof(LOGIN));
cout<<"client is to send"<<endl;
send(client,lgcome,strlen(lgcome),0);
send(client,lgbody,strlen(lgbody),0);
printf("发送消息头\n");
printf("%s",lgcome);
printf("\n发送消息体\n");
printf("%s",lgbody);
//接收服务器端消息
memset(comebody, 0, sizeof(comebody));
recv(client,comebody,sizeof(comebody),0);
cout<<"\n接收消息长度"<<endl;
cout<<"接收消息体"<<endl;
printf("%s",comebody);
cout<<endl;
*/
if(g_count++ > 4)
exit(1);
}
}
closesocket(client);
WSACleanup();
}
评论0