background
I saw a drug management system on a certain treasure, and he had a cloud drug store. With a scan gun, you can get detailed information about the drug. It can save the trouble of input text when adding basic information of drugs. When I worked in my previous company, I was also engaged in drug ERP, and it was very troublesome for customers to add basic information such as drugs with our ERP, so I advocated making such a thing in ERP, but it was not popular for various reasons. One of the important reasons is that the user wants to use it, but there is too little information, so I grab this software to see if I can get his database, and then I can climb down and use it in a similar system. There were some problems along the way, which I wrote down.
The first caught
Go to the software entry, enter the bar code, search to see the package information in the network card, and use Wireshark
It is obvious that HTTP can be adjusted to fetch information, but the return value should be “encrypted”, why encrypted? Is it to prevent people from grabbing it? I thought it was, but it looks like it’s base64 encrypted. I looked for an online decryption base64 on the website first, as expected can decrypt. But there are garbled characters in Chinese, and the appearance of garbled characters should be the problem of character encoding.
In order to see the concrete Chinese content, only Java to write a fetch data and decoding Base64 and character encoding things.
The second Java crawls the data and decodes Base64
Java decoding c++, base64 encoded data, from base64 decoded data to the original look of the process encounter a little trouble, is jdk1.8 in the base64 codec, is not with newline compliance, and this crawls down the data are newline symbols. The following is not available through a search,
java.util.Base64.getDecoder();
Copy the code
Use JDK1.7 or third party Commons-Codec
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.14</version>
</dependency>
Copy the code
org.apache.commons.codec.binary.Base64
Copy the code
With this you can decode Base64
String url="http://116.255.186.7:9000";
HashMap<String, String> hashMap = new HashMap<>();
hashMap.put( "Content-Type"."application/x-www-form-urlencoded");
hashMap.put("Accept"."text/html, */*");
hashMap.put("User-Agent"."Mozilla / 3.0 (compatible; Indy Library)");
Map map =new HashMap();
map.put("YPACT"."YPGET");
map.put("barcode"."12343");
try {
byte rs[]= OkHttpUtil.postb(url, map,hashMap);
JSONObject jsonObject =JSON.parseObject(new String(rs));
String encode = jsonObject.getString("rmtdset");
System.out.println(encode);
byte []xm =encode.getBytes();
byte[] dbm= Base64.decodeBase64(xm);
String dcodeg=new String(dbm);
System.out.println(dcodeg);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Copy the code
But Chinese is garbled
Third analysis why Chinese gibberish
Why does Java print garbled when decoded from Base64? For c++, c#, or more specifically, Windows, the default is GBK, and for Java, utf-8. That is to say,When base64 is encoded in WIN system, the GBK encoded string is changed into byte array and then base64 string 'base64String'.
In the network transmission is ‘base64String’, Java side after receiving, decoding base64String with Base64, decoding into byte array, that array, the corresponding encoding is GBK. So the decoded string is constructed in GBK mode,That’s the code.
After analyzing to this, I understand why he does not directly use string transmission in this system, but to base64 encrypted string transmission, because base64 encrypted string is all ASC code string, there will be no coding error. And decoding, just return the byte array to parse GBK string, can be used correctly. So it can be concluded that base64 encryption on, not real encryption, just for the convenience of passing data.
Finally, let’s look at what the correct data looks like
[{
"id": "248727"."c1_id": "0"."c2_id": ""."c1": "Candy Line"."c2": ""."name": "Long dry lollipop"."pinyin": "ZGBBT"."spec": ""."unit": "支"."approval_number": ""."location": "M&g Stationery Store"."barcode": "091361712343"."zhuzhi": ""."explain_book": "(Memo)"."replenish": ""."logo": ""."is_otc": ""."is_del": ""."c_time": ""."datasource": "External"."storename": "Wellcome Hall Pharmacy"."oper": "Power user"."uploadipaddr": "116.255.186.7"."inserttime": "The 2019-08-30 0:30:01"."rows": "1"
}, {
"id": "280240"."c1_id": "0"."c2_id": ""."c1": ""."c2": ""."name": "2000"."pinyin": "2000"."spec": ""."unit": ""."approval_number": ""."location": "No"."barcode": "12343"."zhuzhi": ""."explain_book": "(Memo)"."replenish": ""."logo": ""."is_otc": ""."is_del": ""."c_time": ""."datasource": "External"."storename": "Luannan County Tuo Li Town Kangcheng Pharmacy"."oper": "Power user"."uploadipaddr": "116.255.186.7"."inserttime": "The 2020-02-03 2:03:45"."rows": "2"
}, {
"id": "222533"."c1_id": "0"."c2_id": ""."c1": "Electrical"."c2": ""."name": "Computer power cord 5m 250V"."pinyin": "DNDYX 5M 250V"."spec": "5m"."unit": "The root"."approval_number": ""."location": "Super 5"."barcode": "1234356574543"."zhuzhi": ""."explain_book": "(Memo)"."replenish": ""."logo": ""."is_otc": ""."is_del": ""."c_time": ""."datasource": "External"."storename": "Guan County Huichuntang Pharmacy Second Branch"."oper": "Power user"."uploadipaddr": "116.255.186.7"."inserttime": "The 2019-06-11 4:58:50"."rows": "3"
}, {
"id": "78460"."c1_id": "0"."c2_id": ""."c1": ""."c2": ""."name": "Vikang 2000 (125)"."pinyin": "WK2000(125)"."spec": "125ml"."unit": "Box"."approval_number": ""."location": "Weicon"."barcode": "6919021123435"."zhuzhi": ""."explain_book": "(Memo)"."replenish": ""."logo": ""."is_otc": ""."is_del": ""."c_time": ""."datasource": "External"."storename": "Dongshanda Pharmacy"."oper": "Power user"."uploadipaddr": "61.237.136.125"."inserttime": "The 2018-11-01 17:21:48"."rows": "4"
}, {
"id": "322118"."c1_id": "0"."c2_id": ""."c1": "7001"."c2": ""."name": "Taoxiang Sweet (Cooked) Salted Duck Eggs"."pinyin": "TXT(S)XYD"."spec": "65g"."unit": "Package"."approval_number": ""."location": ""."barcode": "6921234300855"."zhuzhi": ""."explain_book": "(Memo)"."replenish": ""."logo": ""."is_otc": ""."is_del": ""."c_time": ""."datasource": "External"."storename": "Chain store."."oper": "Power user"."uploadipaddr": "116.255.186.7"."inserttime": "The 2020-06-06 14:01:48"."rows": "5"
}, {
"id": "343515"."c1_id": "0"."c2_id": ""."c1": ""."c2": ""."name": "Alcohol"."pinyin": "JJ"."spec": ""."unit": ""."approval_number": ""."location": ""."barcode": "6921723712343"."zhuzhi": ""."explain_book": "(Memo)"."replenish": ""."logo": ""."is_otc": ""."is_del": ""."c_time": ""."datasource": "External"."storename": "Fu Shan Clinic, Ng Chau Cheung Chau"."oper": "Power user"."uploadipaddr": "116.255.186.7"."inserttime": "The 2020-07-07 1:50:34"."rows": "6"
}, {
"id": "54075"."c1_id": "0"."c2_id": ""."c1": "0203 care"."c2": ""."name": "Patent Cassia seed Tea."."pinyin": "ZLPJMZC"."spec": "240g"."unit": "Box"."approval_number": ""."location": "The ningxia"."barcode": "6924564712343"."zhuzhi": ""."explain_book": "(Memo)"."replenish": ""."logo": ""."is_otc": ""."is_del": ""."c_time": ""."datasource": "External"."storename": "XXXXX Pharmacy"."oper": "Power user"."uploadipaddr": "61.237.136.147"."inserttime": "The 2018-10-12 1:49:14"."rows": "Seven"
}, {
"id": "189861"."c1_id": "3"."c2_id": ""."c1": "Chinese medicine yinpian"."c2": ""."name": "Black Wolfberry"."pinyin": "HGQ(YZY)"."spec": "80g"."unit": "Bucket"."approval_number": ""."location": "Anhui Medicine knows the source"."barcode": "6926919123439"."zhuzhi": ""."explain_book": "(Memo)"."replenish": ""."logo": ""."is_otc": ""."is_del": ""."c_time": ""."datasource": "External"."storename": Changbanpo Pharmacy Ganxi Store."oper": "Power user"."uploadipaddr": "116.255.186.7"."inserttime": "The 2019-02-28 2:11:23"."rows": "8"
}, {
"id": "155311"."c1_id": "0"."c2_id": ""."c1": "New drug"."c2": ""."name": Senna leaf."pinyin": "FXY"."spec": "40 g"."unit": ""."approval_number": ""."location": "Anhui province"."barcode": "6933371234375"."zhuzhi": ""."explain_book": "(Memo)"."replenish": ""."logo": ""."is_otc": ""."is_del": ""."c_time": ""."datasource": "External"."storename": "New Century Pharmacy"."oper": "Power user"."uploadipaddr": "61.237.136.98"."inserttime": "The 2018-12-13 13:24:16"."rows": "9"
}]
Copy the code
I am who I am, a tech enthusiast!