一,要發送的報文,轉化成16進制的,報文以下socket
"\x01\x52"//報文長度338 "\x60\x00\x24\x00\x00"//TPDU "\x60\x22\x00\x17\x04\x02"//報文頭 "\x02\x00"//應用數據 "\x70\x24\x06\xC0\x20\xC0\x9A\x31"//位圖2,3,4,11,14,22,23,25,26,35,41,42,49,52,53,55,59,60,64 "\x19"//域2長度 "<借記卡號>"//域2 6225683621000897490 \x62\x25\x68\x36\x21\x00\x08\x97\x49\x00 "\x00\x00\x00"//域3 "\x00\x00\x00\x00\x00\x25"//域4 "<系統跟蹤號>"//域11 流水號 \x02\x02\x34 "\x28\x08"//域14卡有效期 有效期不校驗 "\x05\x10"//域22 "\x00\x01"//域23 "\x00"//域25 "\x12"//域26 "\x37"//域35長度 "\x62\x25\x68\x36\x21\x00\x08\x97\x49\x3D\x28\x08\x22\x01\x47\x00\x00\x01\x00"//域35 核心第二磁道是否校驗 \x62\x14\x62\x21\x43\x00\x00\x88\x28\x3D\x28\x08\x22\x01\x47\x00\x00\x01\x00 "\x31\x31\x30\x30\x30\x30\x30\x31"//域41* 11000001 "\x33\x30\x36\x35\x38\x38\x32\x36\x33\x30\x30\x30\x30\x30\x31"//域42 306588263000001 "\x31\x35\x36"//域49 "\x5A\xB1\xBA\xA5\xBE\x55\xC0\xCE"//域52 PIN 核心校驗 "\x26\x00\x00\x00\x00\x00\x00\x00"//域53 2帶主帳號的加密方式 "\x01\x38"//域55長度 "\x9F\x26\x08\x82\xCD\xFB\x9F\x42\xB3\x51\xF2\x9F\x27\x01\x80\x9F\x10\x13\x07\x01" "\x01\x03\xA0\xA0\x04\x01\x0A\x01\x00\x00\x00\x00\x00\x16\xEB\xF0\x9B\x9F\x37\x04" "\xF4\x3E\x4C\x87\x9F\x36\x02\x00\xF1\x95\x05\x08\x00\x04\x60\x00\x9A\x03\x17\x05" "\x03\x9C\x01\x00\x9F\x02\x06\x00\x00\x00\x00\x00\x25\x5F\x2A\x02\x01\x56\x82\x02" "\x7C\x00\x9F\x1A\x02\x01\x56\x9F\x33\x03\xE0\xF0\xC8\x9F\x34\x03\x02\x03\x00\x9F" "\x35\x01\x22\x84\x08\xA0\x00\x00\x03\x33\x01\x01\x01\x9F\x09\x02\x00\x20\x9F\x1E" "\x08\x38\x34\x36\x37\x36\x39\x35\x39\x9F\x03\x06\x00\x00\x00\x00\x00\x00"//域55 ARQC校驗 交換校驗IC卡芯片是否爲僞芯片 "\x00\x62"//域59長度 "\x41\x32\x30\x35\x37\x30\x31\x30\x30\x32\x30\x32\x30\x32\x30\x30\x38\x38\x34\x36" "\x37\x36\x39\x35\x39\x30\x33\x30\x30\x36\x30\x38\x38\x32\x38\x33\x30\x34\x30\x30" "\x38\x20\x20\x20\x20\x20\x20\x20\x20\x30\x35\x30\x30\x38\x31\x37\x30\x34\x30\x32\x20\x20"//域59 "\x00\x19"//域60長度 "\x22\x00\x00\x05\x00\x05\x03\x00\x10\x00"//域60 \x22【\x00\x00\x01批次號每次測試都要改】\x00\x05\x0【3\x00\x1】0\x00 \x22\x00\x00\x01\x00\x05\x09\x00\x10\x00 "\x4D\x1B\x8D\xD9\x04\xF2\xA7\xA8"//域64 MAC 卡交換和核心都校驗 如上3001這次改造點
ACTION編寫的腳本以下:測試
#include "lrs.h" typedef long time_t; struct _timeb { time_t time; unsigned short millitm; short timezone; short dstflag; }; struct _timeb SendTime ; int toHexString(char* OutStr,char* InStr,int len); static int ef_millitm=0; static int quchong=1; Action() { int rc = 888; int SndBufLen; int RecBufLen; char *RecBuf; double trans_time; int opt_value; char tmp[30]={0}; char res[30]={0}; char ACC[45]={0}; ftime(&SendTime); //lr_error_message("time:%d,millitm:%d,ip:%s",SendTime.time,SendTime.millitm,lr_eval_string("<IP_PORT>")); if(ef_millitm==SendTime.millitm) { sprintf(tmp,"%03d%03d",(SendTime.time%1000),(SendTime.millitm+quchong)); quchong++; } else { sprintf(tmp,"%03d%03d",(SendTime.time%1000),SendTime.millitm); quchong=1; } ef_millitm=SendTime.millitm; //lr_error_message("SendTime.time = %d",SendTime.millitm); //lr_error_message("SendTime.time = %d",SendTime.time%1000); toHexString(res,tmp,6); toHexString(ACC,lr_eval_string("<AC_1>"),20); //lr_error_message("tes = %s",tmp); lr_save_string(res,"系統跟蹤號"); lr_save_string(ACC,"借記卡號"); // 創建發送通道鏈接 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lr_start_transaction("消費"); // 發送報文 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lr_start_transaction("消費_發送報文"); rc = lrs_send(lr_eval_string("<p_Socket>"), "SendBuf1", LrsLastArg); if(rc == 0) { lr_end_transaction("消費_發送報文", LR_PASS); } else { lr_end_transaction("消費_發送報文", LR_FAIL); lr_end_transaction("消費", LR_FAIL); lr_error_message("消費_發送報文失敗;錯誤碼是:%d;", rc); // lrs_disable_socket(lr_eval_string("<p_Socket>"), DISABLE_SEND_RECV); // lrs_close_socket(lr_eval_string("<p_Socket>")); lr_exit(LR_EXIT_ITERATION_AND_CONTINUE, LR_FAIL); } rc = 888; //RecBuf = (char*)calloc(1024, sizeof(char)); // 接收報文 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=+++++++++++++++++++++++++ lr_start_transaction("消費_接收報文"); rc = lrs_receive(lr_eval_string("<p_Socket>"), "ReceiveBuf1", LrsLastArg); trans_time=lr_get_transaction_duration("消費"); if(trans_time>10) { lr_error_message("消費響應時間爲:%f,請求流水號爲:%s",trans_time,res); } if((rc == 0)||(rc == 9101)) { lrs_get_last_received_buffer(lr_eval_string("<p_Socket>"), &RecBuf, &RecBufLen); if(RecBufLen == 0) { lr_end_transaction("消費_接收報文", LR_FAIL); lr_end_transaction("消費", LR_FAIL); //lr_error_message("交易出錯!出錯的流水號是:%s",lr_eval_string("<DateTime><VuserID><Number>")); lr_error_message("消費 未接收到返回,卡號:%s,流水號:%s",lr_eval_string("<AC_1>"),tmp); lr_exit(LR_EXIT_ITERATION_AND_CONTINUE, LR_FAIL); } else if(RecBufLen != 257) { lrs_save_param(lr_eval_string("<p_Socket>"),NULL,"rsp_code_1",68,12); lr_end_transaction("消費_接收報文", LR_FAIL); lr_end_transaction("消費", LR_FAIL); lrs_free_buffer(RecBuf); lr_error_message("消費返回報文不正確,長度:%d,流水號:%s,應答碼:%s,ip:%s",RecBufLen,tmp,lr_eval_string("<rsp_code_1>"),lr_eval_string("<IP_PORT>")); lr_exit(LR_EXIT_ITERATION_AND_CONTINUE, LR_FAIL); } lrs_save_param_ex(lr_eval_string("<p_Socket>"), "user", RecBuf, 0, RecBufLen, "ascii", "NewRecBuf"); //判斷卡是否正常 須要刪除 // lrs_save_param(lr_eval_string("<p_Socket>"),NULL,"rsp_code_1",74,10); // if(strcmp(lr_eval_string("<rsp_code_1>"),"00")!= 0) // { // lr_error_message("出錯報文定位的報文是:%s,卡號:%s,流水號:%s", lr_eval_string("<rsp_code_1>"),lr_eval_string("<AC_1>"),res); // } // lrs_save_param(lr_eval_string("<p_Socket>"),NULL,"rsp_code",77,2); //lr_save_var(lr_eval_string("<NewRecBuf>")+182,2,0,"ret"); //lr_error_message("======定位的報文是:%s", lr_eval_string("<rsp_code>")); if(strcmp(lr_eval_string("<rsp_code>"),"00")==0) { lr_end_transaction("消費_接收報文", LR_PASS); lr_end_transaction("消費", LR_PASS); } else { lr_end_transaction("消費_接收報文", LR_FAIL); lr_end_transaction("消費", LR_FAIL); //lr_error_message("交易出錯!出錯的流水號是:%s",lr_eval_string("<DateTime><VuserID><Number>")); lr_error_message("交易出錯!卡號:%s,流水號是:%s",lr_eval_string("<AC_1>"),tmp); } } else { lr_end_transaction("消費_接收報文", LR_FAIL); lr_end_transaction("消費", LR_FAIL); lr_error_message("消費_接收報文失敗;錯誤碼是:%d,流水號:%s", rc,res); lrs_free_buffer(RecBuf); lr_exit(LR_EXIT_ITERATION_AND_CONTINUE, LR_FAIL); } lrs_free_buffer(RecBuf); return 0; } //將字符串轉換成16進制 //855071 變爲\x85\x50\x71 int toHexString(char* OutStr,char* InStr,int len) { int i=0; for(;i<len;i++) { if((i==0)||(i%2==0)) { sprintf(OutStr+2*i,"%s%c","\\x",(unsigned char)InStr[i]); } else { sprintf(OutStr+2*i+1,"%c",(unsigned char)InStr[i]); } } return 0; }