前段时间遇到一个前后台数据交互偶现的bug。为了方便调试,需要每次发请求的回包都能是遇到问题时的数据包。一起做终端的同学对网络抓包工具不是很熟,学习使用太费时,就临时用PHP封装了一个回包的demo。
###用法:
###代码:
<?php
//设置http头,取决于业务的需求,以下两个字段为SDK的前后台交互需要设置的agent
header('Content-Length:2344');
header('Content-Type:text/html;charset=UTF-8');
//抓包获取到的16进制的包内容
$hex = "";
function Hex2String($hex){
$string='';
for ($i=0; $i < strlen($hex)-1; $i+=2){
$string .= chr(hexdec($hex[$i].$hex[$i+1]));
}
return $string;
}
print Hex2String($hex);
?>
其中hex的值为对应包的16进制的包内容,任何抓包工具都能获得,
###Demo
下面的内容为SDK的一次网络请求的包内容,只需要把下面的内容拷贝到代码中赋值给$hex即可。
e90e3a3322786b20caead92e57533125b145a8e64383bed2ee4a1027de3097340afa7b04f3525d8cbd1a96bed124df7483a10a712e7e37ffe4edf182e1ded0ee5b620649aedfccd068c9dec40f16a49da664be3dfa1ce959003a64957835a1d89ab04b051ccc03a599cc9a288282ff123a0c66605cb53409043fa858520a5f7cbba4e904d0466296e374d7c271999487e3bf96d84f8979437e04f033510e6b888773f7be7f1adb3b28142c7b34e95acab56ee565cfb5c3df513d56f2ccb9bcc231e0dc39aa0b7eb3aab3aa8515f5e11f87f41cd2bd5231e7b20af540ac42578229fc307fffcaa223eb5138805a62961fae97f51d5b507de2c346d2d7b0507851f89c86ea9a769bb6cd3db5b112684cf0eb76d10ef03740bdd17dc53c1c8e96d9795b3cc4107bc7ed7f136c2b5c794bf5c1e01794bec406ddc5ccef5f85e35ad40add0df4847c57f71578a3b09e9e3643c863e53887dc1b921e6ec98e773b74a932e1d80201c07c0a27efa69e0fef83a92c60b72d98bd0d2e6d7a75177f0eca2ec4161336acaf4715bbba382501116d8827f4c7183a335746e4a725dfb6b8dfe1aad4e5bc622180c02ef3f95563f31ad1d3839a80ec869a20e5e3bac1a72d8aaaf5eb12c5b34a8671578e166b984892833da158d339e088f398794c2bbce2ed2612f0d552213095e76d5e5a2f6f194572278ad23c75d899fe960854cfaa127309c9db9d5dab68360af2918ea1bcc2896153ea8abf287c4da26774f533380a2c9d5a582a0b06bb609e7b3f5c4f41c296851cf479b6f17ff9a226d8ac738e73863a2a9f4b17ce265f9e672962930b5ff58b3872661dca3d441fb07f67bb8105cac9ac856c99d4c94655be1237c069528bbc4cde4b9d5aa4f19a0e90d3708da0bcf425dbe7542cabeb479cf5ea7922f9652553d682de5ac60f2781113baff783b8c88a803b29fcbc756dcc6c9f8e360ef847d685a64783605cb0029023a5b6cdd57ac2d924325ffcb2551afc38da70a366f6fe89abfa8d9b88fde6e3b4b58d8f672383b04a0bb2d771b05a1009f3049eb5fca911f8556ea6e7c43602180eb29dc3a49e4f6e163aaf96fdba13dd31be2b51d6bbdc22c6ab357cbf8f1a6a3767688bae97cdee1734bebbb4a16471eb8aac9291ec4fc1fc85776752883127c9a4996e76e2709c0d6850fbb6dbe42985d563892961a032da2c1648bdd6c171ae0165f2036c1bab2178d3850e71963479615704d0f79c9deff29b6b8183ef798ffeaa1e8ea20f9630cd4a5cfbaef6fcf0b6fc4008ef82faab070b52437f85d0aeb6f0d88e124aa6f80dc67afcfd85ecd5c062cf79ec954ec956e801ee158da2ff363d7095669548669cdb4c3056de25cc7f6cf8bbff2229a9f8c95b1734714f782780cf90c87b77a27319566b39f03d615bd48767ca0c91ddfc40dd244c9c2bcf5b523aa6db72911f9a9e18efb292eb509d220511a3ad33914ff8dd4d06af09c9ea0e51eabf06f1a6720044c4ab6940a9dccf8fb82c4eb0820ce2558660704ce2c0ee1d2407e4ab45d016139ad14fe07d3044a419a64493c354b925d025f91b7977c3035c7cc1ce5bffffe3714f00c3188003164f3f90735786234fd49c08a4183cd3ed0231dea78e6c489adfc8fd9e6eece50e15dd050f3ae3e9ce1f8076e347059997792bbf7c685fa9d9d2b2bf440750eb50030b9f6c48e29e8a69ef35bfde807f5024d6819a581b1da89fe0c0288decee37e4318d329b2e86deca904af790ce736fa0040e17e350868f7e20094a4258ed3c5201fecf5f47ffca223eb217c0312088d16f61293df606da4cb4173b410c69caa335e72584970ff53010c08e950212ca6fb847354e0f509d06cc53ae19f1fb8e9ea6576bb0c289f53f4218a9a9d07eaa9d9870035355f2b14e808c05ad46ea035ef8ea45b41be343b82097c9b9230b3588a3ae530979eb7c73e5f17b1d5d497871b1e98292b5e54aca32da2822b2d0fbadbaf7f5e1505c7678ca211fc17007fe7432356f8427576cf24039e25287085ae51b050698b18db1c66ab3893c42b4dbddca761514e2191f22f39ffc33990104e85e75a9b8e8cd3fc49a2530a857cf4e9f59fc7ddf1b468fe6d6cc9277927a26af6954e6eecff9a57e6aceea097905c32e05cfc9814c7b01c904c7d303330dd6e46c47f38f297aa6d73ea9651cd5c0b1d6be0c6d3e25ff9746f07dba86b3e1d8344ac077411070de74fa95c5aaecc3b31cac25ae98dc0c6b2849fa6f43ed01664877a30df23d08b3b47456a8c80c01ba615a857e23f0b41f6e06e91aec841fa8f1b764b3276597ec33940899b276cc1273bf36136377816576d5c1fb671750b9f6b482cd18beedf5398f4a7309de9654bb28158def4e24bb7b8720b0cac2854216c72197a6e5f0ee4a2c8cccc84aa5f1470fe0d093002666bc52d602a9ec63483086adf77a17aea85dceeee5b6485c2cbb75afaa594793e930cf622bdf854b5d93fb7fa1c210e168fc5ff801ff61968c41f7f33b68331b26993a9d9bb84e817a6e3a956352bd25e5b3426bc620043cd812f3a6b84387e84dec0ce69dad8275ce891fee3118f53090c6f90262c6d0108ee59970191ecf4819dfb20626c2690fd1a2b5a0ff47b31482a37349ca7eb3c094f12e59b07308a0d8a4a2257a71273617a958d1b97e02c9379b40a7871486dcab2decdd2963330450f7d2561d8362b9340fc437bc711e34038518db19c909e7317048edae2e6b201ab746e912012337bd94eedffc035908e55866f6c031887c2e969afbde4132fda01c6966a780f5b2270d75e6fb5d9d49db25a39a1f65c2287def8704f9e66f72d08d06e91e404fda558d0ae8a1dd3dc94a13ed73c3707769e7038b09e06e74316e90e48e679cb355b640fc41e32e0bfd0f30e7347880a80282e68f18696a1e97d2eb56263b5d8bd9cefaf44ea63dd3d5773c7972c42427a1363de94595c5a534295ddcbb8eff26c56a1434265145ceee3b7f001abc6c2c34a15e286a6150b581ff1e2e74de8285d9719665d00fbc4f7259a3a74457e0a854064ad0530613063b366e478d451e149936886427b40362de7abda809ba3afce733003b2f12631b1103a5a8c666ff0e8633ba78a266ef4daf809d00275a09e9c74970a971516dc5221a4d32db7362acfc1a6d71ea4753aeb836ad206bd9c7e1b458d47105d9351fd867a6c407831281c25bb9f848b8d2a02a834beee76a59356adff6c39a2f57a9a112fb87da7f8afb1b9cf372fdd37a1dfb7a5845b34982fdd6259cb4152de0db1fb9dcba99328e62ac6cf6e1d42629709c2132