|
@@ -0,0 +1,164 @@
|
|
|
|
+package com.yh.saas.plugin.yiliangyiyun.controller;
|
|
|
|
+
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.io.InputStream;
|
|
|
|
+import java.io.PrintWriter;
|
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
|
+import java.net.URLEncoder;
|
|
|
|
+
|
|
|
|
+import javax.servlet.ServletException;
|
|
|
|
+import javax.servlet.http.HttpServlet;
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+import org.apache.commons.codec.binary.Base64;
|
|
|
|
+
|
|
|
|
+//import net.sf.json.JSONObject;
|
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+
|
|
|
|
+@RequestMapping("/httpServletlx")
|
|
|
|
+public class HttpServletlx extends HttpServlet {
|
|
|
|
+ static int a=0;
|
|
|
|
+ /**
|
|
|
|
+ * The doGet method of the servlet. <br>
|
|
|
|
+ *
|
|
|
|
+ * This method is called when a form has its tag value method equals to get.
|
|
|
|
+ *
|
|
|
|
+ * @param request the request send by the client to the server
|
|
|
|
+ * @param response the response send by the server to the client
|
|
|
|
+ * @throws ServletException if an error occurred
|
|
|
|
+ * @throws IOException if an error occurred
|
|
|
|
+ */
|
|
|
|
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
|
|
|
|
+ throws ServletException, IOException {
|
|
|
|
+
|
|
|
|
+ doPost(request,response);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * The doPost method of the servlet. <br>
|
|
|
|
+ *
|
|
|
|
+ * This method is called when a form has its tag value method equals to post.
|
|
|
|
+ *
|
|
|
|
+ * @param request the request send by the client to the server
|
|
|
|
+ * @param response the response send by the server to the client
|
|
|
|
+ * @throws ServletException if an error occurred
|
|
|
|
+ * @throws IOException if an error occurred
|
|
|
|
+ */
|
|
|
|
+ @PostMapping("/api/doPost")
|
|
|
|
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
|
|
|
|
+ throws ServletException, IOException {
|
|
|
|
+ System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
|
|
|
|
+ InputStream in=request.getInputStream();
|
|
|
|
+ int size=request.getContentLength();
|
|
|
|
+ String charset=null;
|
|
|
|
+ getPostData(in,size,charset);
|
|
|
|
+
|
|
|
|
+ response.setCharacterEncoding("gb2312");
|
|
|
|
+
|
|
|
|
+ //返回相机抬杆 及 相机透传 “一体箱语音”
|
|
|
|
+ String jsonStr ="{\"Response\": {\"barrier_control\": {\"action\": \"open\"},"
|
|
|
|
+ + "\"trigger_data\": {\"action\": \"\"},"
|
|
|
|
+ + "\"rs485_data\": [{\"delay_time\": 100,\"data\": \"/gAAF5lz/QAPAQBbbjJdufNKUjg0RzExTQ==\"},"
|
|
|
|
+ + "{\"delay_time\": 400,\"data\": \"/pgAbJdUAAAAAAAAAAAAAQEB/lxLiVkAAAAxAABsuUYAAAAwMDAwMDAwMDIsCQQAMDEwMTAxOTkxMjMxEwAAAFWqAAA3MjIxMTEAAAgAEAABEQASAAAA0rvN+87evMr/AAEAAQABAGd8///Wi88=\"}],"
|
|
|
|
+ + "\"whitelist_data\": [{\"action\": \"add\",\"plate_number\": \"粤B12345F\",\"create_time\": \"2019-01-01 12:12:21\","
|
|
|
|
+ + "\"start_time\": \"2019-01-01 12:12:21\",\"end_time\": \"2023-01-01 12:12:21\",\"is_black_list\": \"no\",\"time_match\": \"enable\"},"
|
|
|
|
+ + "{\"action\":\"delete\",\"plate_number\":\"京A12345\"}]}}";
|
|
|
|
+
|
|
|
|
+ System.out.println(jsonStr);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ PrintWriter out = response.getWriter();
|
|
|
|
+
|
|
|
|
+ out.print(jsonStr);
|
|
|
|
+ out.close();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /*************************************************base64解码数据*******************************************************************/
|
|
|
|
+ public static byte[] m_decode(String bytes) {
|
|
|
|
+ return Base64.decodeBase64(bytes);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+/*************************************************JSON解析数据*******************************************************************/
|
|
|
|
+
|
|
|
|
+ public static void show_json(String m_str)
|
|
|
|
+ {
|
|
|
|
+// //获取设备名称
|
|
|
|
+// JSONObject Json = JSONObject.fromObject(m_str);
|
|
|
|
+// String deviceName= Json.getJSONObject("AlarmInfoPlate").getString("deviceName");
|
|
|
|
+// System.out.println(deviceName);
|
|
|
|
+//
|
|
|
|
+// //设备IP地址
|
|
|
|
+// String ipaddr= Json.getJSONObject("AlarmInfoPlate").getString("ipaddr");
|
|
|
|
+// System.out.println(ipaddr);
|
|
|
|
+// //获取识别车牌号
|
|
|
|
+// String license= Json.getJSONObject("AlarmInfoPlate").getJSONObject("result").getJSONObject("PlateResult").getString("license");
|
|
|
|
+// System.out.println(license);
|
|
|
|
+//
|
|
|
|
+// //获取并保存识别结果大图
|
|
|
|
+// String imageFile=Json.getJSONObject("AlarmInfoPlate").getJSONObject("result").getJSONObject("PlateResult").getString("imageFile");
|
|
|
|
+// int imageFileLen=Json.getJSONObject("AlarmInfoPlate").getJSONObject("result").getJSONObject("PlateResult").getInt("imageFileLen");
|
|
|
|
+// if(imageFileLen!=0)
|
|
|
|
+// m_savetxt.m_fwrite(m_decode(imageFile),"D:/imageFile.gif");
|
|
|
|
+//
|
|
|
|
+// //获取并保存识别结果小图
|
|
|
|
+// String imageFragmentFile=Json.getJSONObject("AlarmInfoPlate").getJSONObject("result").getJSONObject("PlateResult").getString("imageFragmentFile");
|
|
|
|
+// int imageFragmentFileLen=Json.getJSONObject("AlarmInfoPlate").getJSONObject("result").getJSONObject("PlateResult").getInt("imageFragmentFileLen");
|
|
|
|
+// if(imageFragmentFileLen!=0)
|
|
|
|
+// m_savetxt.m_fwrite(m_decode(imageFragmentFile),"D:/imageFragmentFile.gif");
|
|
|
|
+//
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/*************************************************获取数据*******************************************************************/
|
|
|
|
+ public static String getPostData(InputStream in, int size, String charset) {
|
|
|
|
+ if (in != null && size > 0) {
|
|
|
|
+ int readCount = 0; // 已经成功读取的字节的个数
|
|
|
|
+ int nRead = 0;
|
|
|
|
+ byte[] buf = new byte[size];
|
|
|
|
+ try {
|
|
|
|
+ while (readCount < size) {
|
|
|
|
+ nRead = in.read(buf, readCount, size - readCount);
|
|
|
|
+ if( nRead == -1) // 到末尾
|
|
|
|
+ {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ readCount += nRead;
|
|
|
|
+ //readCount += in.read(buf, readCount, size - readCount);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ((charset == null || charset.length() == 0) && (size ==readCount))
|
|
|
|
+ {
|
|
|
|
+ //m_savetxt.m_fwrite(buf,"D:/newfile.txt");
|
|
|
|
+ //选择utf-8乱码时
|
|
|
|
+ String tmp = new String(buf, "UTF-8");
|
|
|
|
+ //选择gb2312乱码是
|
|
|
|
+ //String tmp = new String(buf, "gb2312");
|
|
|
|
+
|
|
|
|
+ System.out.println(tmp);
|
|
|
|
+ if (a==0){
|
|
|
|
+ m_savetxt.m_fwrite(buf,"E:/newfile.txt");
|
|
|
|
+ show_json(new String(buf)); //对接口接收数据做处理
|
|
|
|
+ a+=1;
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ m_savetxt.m_fwrite(buf,"E:/newfile1.txt");
|
|
|
|
+ a=0;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|