Package COM. jadyer. util; import Java. io. bytearrayoutputstream; import Java. io. ioexception; import Java. io. inputstream; import Java. io. outputstream; import java.net. inetsocketaddress; import java.net. socket; import Java. util. hashmap; import Java. util. map;/*** use your ocket to write the tool class for sending TCP requests * @ see there is a mina tool class like: http://blog.csdn.net/jadyer/article/details/8088068 * @ see to query related properties of scoket: http://blog.csdn.net/jadyer/ Article/details/8788272 * @ create Apr 5, 2013 9:25:34 * @ author Xuan Yu
The following is the test code.
Public static void main (string [] ARGs) {string reqdata = "0003721000510110199201209222240000020120922000069347814303000700000813'' China Unicom recharge account: 18655228826 recharge account: 100.00 RMB 'udp1209222238312219411 '000000' '000000' chinaunicom-payfeeonline 'utf-8' 10000 'md5 '20180101' 02 '20180101' 20120922020103806276 '20180101' boco _ B2C ''' http: // 192.168.20.2: 5545/ecpay/pay/elecchnlfrontpayrspbackaction. action '1' pay now, transaction successful '"; string IP =" 127.0.0.1 "; string port =" 9901 "; string reqcharset =" gb18030 "; Map <string, string> respmap = sendtcprequest (IP, port, reqdata, reqcharset); system. out. println ("========================================== ========================================================== "); system. out. println ("the request message is as follows"); system. out. println (respmap. get ("reqdata"); system. out. println ("========================================== ========================================================== "); system. out. println ("response packet as follows"); system. out. println (respmap. get ("respdata"); system. out. println ("========================================== ========================================================== "); system. out. println ("The hexadecimal response is as follows"); system. out. println (respmap. get ("respdatahex"); system. out. println ("========================================== ========================================================== ");}
Below is the console output
// The console outputs the following: // =================================================== ========================================================== ===/// the request message is as follows // 0003721000510110199201209222240000020120922000069347814303000700000813 ''China Unicom recharge Bill'': 18655228826 recharge your account: 100.00 RMB 'udp1209222238312219411 '000000' '000000' chinaunicom-payfeeonline 'UTF -8 '000000' MD5 '000000' 1 '02' 20120922223831 '000000' 20120922020103806276 'boco _ B2C ''' http: // 192.168.20.2: 5545/ecpay/pay/elec Chnlfrontpayrspbackaction. action '1' pay now, transaction successful '// ======================================================== ========================================================== ==// the response message is as follows // 00015800000000 order result notification: the merchant system failed to receive the notification, you need to continue to notify 6717356649614827173120130405201628201304051 '// ====================================== ========================================================== ====/// the response hexadecimal format is as follows /// -------------------------------------------------------------------------- // 0000: 30 30 30 31 35 38 30 30 30 30 30 30 30 B6 A9 | 00015800000000 order // 0010: b5 A5 BD E1 B9 fb cd A8 D6 AA 3A C9 cc bb A7 CF | ticket result notification: Merchant's Department // 0020: b5 CD B3 ce B4 B3 C9 B9 A6 BD D3 ca D5 B5 bd cd |? Failed to receive connection // 0030: A8 D6 AA 2C D0 E8 D2 aa bc cc D0 F8 CD A8 D6 AA |? Notice, continue to notice // 0040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | // 0050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | // 0060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | // 0070: 00 00 36 37 31 37 33 35 36 34 39 36 31 34 38 | 67173566496148 // 0080: 32 37 31 37 33 31 32 30 31 33 30 34 30 35 32 30 | 2717312013040520 // 0090: 31 36 32 38 32 30 31 33 30 30 35 31 60 | 1628201304051 '// then // ====================== ========================================================== ================================== //