【性能测试】:关于Sockets协议的脚本的开发
一,关于Sockets协议的脚本,首先对报文的解析是一个关键,
报文的解析一般对着接口文档,弄清楚每个字段代表什么意思,如下一段报文,放在data.ws中
"\x00\x00\x01\x5C" // 报文长度348=15c,加上自己总长度 "1" "0" "500001" "0" "AUMS" "IBS " "2018061217982791000000" // 发起方流水,22位 "20180612" // 发起方日期,8位 "179827" // 发起方时间,6位 "G50704" //交易代码 6位 "01" //网关错误标识2 " " // 网关错误代码 7 " " //编码1 " " //重发标志1 " " //保留位1 6 "50704" //交易码5 "20180612" //交易发生日期8 "12:12:12" //交易发生时间8 "17982790034 " //交易流水号22 "20161110" //交易日8 "0" //代理标志1 "0000" //联网行编号4 "8888 " //交易网点10 " " //柜员10 " " //出纳员号4 " " //授权柜员1 10 " " //授权柜员2 10 "3" //交易渠道 1 "0000 " //终端号 10 " " //返回码类型 1 "T" //请求类型 1 "00" //授权级别 2 "1 " //当前第几页 8 "10 " //每页记录数 8 " " //备用1 20 " " //备用2 20 " " //备用3 20 " " //备用4 20 "6225683528000346164 " //银行账号 32 "Au99.99 " //合约代码 10 "4011" //交易类型 4 "00015000" //委托价格 8 2 "1 " // 委托手数 6 "1" // 指令类型 1
二,是关于Sockets通信协议,有必要了解一下长链接,短链接的区别
sockets报文如下
#include "lrs.h" Action() { int rc = 888; int RecBufLen; // 接收报文长度 char *RecBuf = NULL; // 接收报文内容 RecBuf = (char*)calloc(10240, sizeof(char)); lrs_set_connect_timeout(120, 0); lr_start_transaction("01_50704_委托报单"); // 完整事务 lr_start_transaction("01_50704_委托报单_建立发送通道连接"); rc = lrs_create_socket("MySocket","TCP","RemoteHost=21.96.22.56:14000",LrsLastArg); // 黄金系统ip:端口 if(rc == 0) { lr_end_transaction("01_50704_委托报单_建立发送通道连接", LR_PASS); } else { lr_end_transaction("01_50704_委托报单_建立发送通道连接", LR_FAIL); lr_error_message("01_50704_委托报单_建立发送通道连接失败,错误码是:%d", rc); lr_end_transaction("01_50704_委托报单", LR_FAIL); lrs_free_buffer(RecBuf); // 释放空间 lrs_disable_socket("MySocket", DISABLE_SEND_RECV); // 关闭接口 lrs_close_socket("MySocket"); lr_exit(LR_EXIT_ITERATION_AND_CONTINUE, LR_FAIL); } lrs_set_send_timeout(120, 0); lrs_set_recv_timeout(120, 0); lrs_set_recv_timeout2(120, 0); lr_start_transaction("01_50704_委托报单_发送报文"); rc = lrs_send("MySocket", "SendBuf", LrsLastArg); if(rc == 0) { lr_end_transaction("01_50704_委托报单_发送报文", LR_PASS); } else { lr_end_transaction("01_50704_委托报单_发送报文", LR_FAIL); lr_error_message("01_50704_委托报单_发送报文失败;错误码是:%d;", rc); lr_end_transaction("01_50704_委托报单", LR_FAIL); lrs_free_buffer(RecBuf); // 释放空间 lrs_disable_socket("MySocket", DISABLE_SEND_RECV); // 关闭接口 lrs_close_socket("MySocket"); lr_exit(LR_EXIT_ITERATION_AND_CONTINUE, LR_FAIL); } // 接受报文===================================================================== lr_start_transaction("01_50704_委托报单_接收报文"); rc = lrs_receive("MySocket", "ReceiveBuf", LrsLastArg); if((rc == 0)||(rc == 9101)) { lrs_get_last_received_buffer("MySocket", &RecBuf, &RecBufLen); if(RecBufLen>0) { lrs_save_param_ex("MySocket", "user", RecBuf, 0, RecBufLen, "ascii", "NewRecBuf"); // 接收的完整报文 lrs_save_param_ex("MySocket", "user", RecBuf, 112, 1, "ascii", "RetStatus"); // 接收的交易状态 lrs_save_param_ex("MySocket", "user", RecBuf, 85, 7, "ascii", "RetCode"); // 接收的返回码 lrs_save_param_ex("MySocket", "user", RecBuf, 92, 100, "ascii", "RetMsg"); // 接收的返回信息 lrs_save_param_ex("MySocket", "user", RecBuf, 21, 22, "ascii", "RetID"); // 接收返回的流水号 //lr_error_message("======接收的完整报文是:%s", lr_eval_string("<NewRecBuf>")); //lr_error_message("======发送的流水号是:%s", lr_eval_string("<DateTime><VuID><Num>")); //lr_error_message("======接收的流水号是:%s", lr_eval_string("<RetID>")); if (strcmp(lr_eval_string("<RetCode>"),"HJ0000 ") == 0) //if (strcmp(lr_eval_string("<RetStatus>"),"N") == 0) // N-交易成功;E-交易失败;A-需要授权,交易未成功;W-警告(交易成功,返回提示信息);U-表示超时 { if (strcmp(lr_eval_string("<RetID>"),lr_eval_string("<DATE><TIME><VUER><UNIQ>")) == 0) // 发送流水号和接收流水号相同,防止串包 { lr_end_transaction("01_50704_委托报单_接收报文", LR_PASS); lr_end_transaction("01_50704_委托报单", LR_PASS); } else { lr_end_transaction("01_50704_委托报单_接收报文", LR_FAIL); lr_end_transaction("01_50704_委托报单", LR_FAIL); lr_error_message("01_50704_委托报单接收报文串包了!!!发送流水号是:%s,接收流水号是:%s,接收的完整报文是:%s", lr_eval_string("<DateTime><VuID><Num>"),lr_eval_string("<RetID>"),lr_eval_string("<NewRecBuf>")); } } else { lr_end_transaction("01_50704_委托报单_接收报文", LR_FAIL); lr_end_transaction("01_50704_委托报单", LR_FAIL); lr_error_message("01_50704_委托报单接收报文出错!交易状态是:%s,返回码是:%s,返回信息是:%s,接收的完整报文是:%s", lr_eval_string("<RetStatus>"),lr_eval_string("<RetCode>"),lr_eval_string("<RetMsg>"),lr_eval_string("<NewRecBuf>")); } } else { lr_end_transaction("01_50704_委托报单_接收报文", LR_FAIL); lr_end_transaction("01_50704_委托报单", LR_FAIL); lr_error_message("01_50704_委托报单接收报文为空!发送流水号是:%s", lr_eval_string("<DateTime><VuID><Num>")); } } else { lr_end_transaction("01_50704_委托报单_接收报文", LR_FAIL); lr_error_message("01_50704_委托报单_接收报文失败;错误码是:%d;", rc); lr_end_transaction("01_50704_委托报单", LR_FAIL); } lrs_free_buffer(RecBuf); // 释放空间 lrs_disable_socket("MySocket", DISABLE_SEND_RECV); // 关闭接口 lrs_close_socket("MySocket"); return 0; }