Browse Source

Drucker remote

robert 2 years ago
parent
commit
4947bbc78f
2 changed files with 38 additions and 3 deletions
  1. 12 3
      api/controllers/RequestController.php
  2. 26 0
      printer/main.py

+ 12 - 3
api/controllers/RequestController.php

@@ -320,11 +320,20 @@ class RequestController
         // $ptr = printer_open("POS-58");
         // printer_set_option($ptr, PRINTER_MODE, "raw");
 		$ptr = "/dev/usb/lp0";
-		printer_write($ptr, $this->printFormat($result));
+		// printer_write($ptr, $this->printFormat($result));
+		$url = "https://pos58.global-cube.online/";
+		$payload = array('data' => $this->printFormat($result));
+
+		$curl = curl_init($url);
+		curl_setopt($curl, CURLOPT_POST, true);
+		curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
+		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+		$response = curl_exec($curl);
+		curl_close($curl);
 
         // printer_close($ptr);
 
-        return $result;
+        return $response;
     }
 
 	private function printFormat ($data)
@@ -346,7 +355,7 @@ class RequestController
         $result[] = str_pad(number_format($data['total'], 2, ",", "."), 31, " ", STR_PAD_LEFT);
 
         $result[] = $this->project['print_footer'];
-        $result[] = str_repeat("\n", 7);
+        $result[] = str_repeat("\n", 4);
 		return implode("\n", $result);
 	}
 

+ 26 - 0
printer/main.py

@@ -0,0 +1,26 @@
+import os
+from flask import Flask, request
+
+
+app = Flask(__name__)
+
+
+@app.route('/', methods=['POST'])
+def main():
+    data = request.get_data(as_text=True)
+    data = data[data.find('\n***'):data.rfind('\n---')]
+    pos58_print(data)
+    # print(data)
+    return '!'
+
+
+@app.route('/test/<data>', methods=['GET'])
+def pos58_print(data):
+    with open('/dev/usb/lp0', 'w') as lpr:
+        lpr.write(data + '\n')
+    return '!'
+
+
+if __name__ == '__main__':
+    app.secret_key = os.urandom(24)
+    app.run(host='0.0.0.0', port='8099', debug=True)