dyj.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php
  2. include_once "print.class.php";
  3. include_once "HttpClient.class.php";
  4. class Dyj
  5. {
  6. //365打印机
  7. public static function dy($deviceNo,$content,$key){
  8. $selfMessage = array(
  9. 'deviceNo'=>$deviceNo,
  10. 'printContent'=>$content,
  11. 'key'=>$key,
  12. 'times'=>'1'
  13. );
  14. $url = "http://open.printcenter.cn:8080/addOrder";
  15. $options = array(
  16. 'http' => array(
  17. 'header' => "Content-type: application/x-www-form-urlencoded ",
  18. 'method' => 'POST',
  19. 'content' => http_build_query($selfMessage),
  20. ),
  21. );
  22. $context = stream_context_create($options);
  23. $result = file_get_contents($url, false, $context);
  24. return $result;
  25. }
  26. //易联云打印机
  27. public static function ylydy($api,$token,$yy_id,$mid,$content){
  28. $print = new Yprint();
  29. $apiKey = $api;
  30. $msign = $token;
  31. $partner=$yy_id;
  32. $machine_code=$mid;
  33. $result =$print->action_print( $partner,$machine_code,$content,$apiKey,$msign);
  34. return $result;
  35. }
  36. //飞蛾打印机
  37. public static function fedy($fezh,$fe_ukey,$fe_dycode,$content){
  38. header("Content-type: text/html; charset=utf-8");
  39. define('USER', $fezh); //*必填*:飞鹅云后台注册账号
  40. define('UKEY', $fe_ukey); //*必填*: 飞鹅云注册账号后生成的UKEY
  41. define('SN', $fe_dycode); //*必填*:打印机编号,必须要在管理后台里添加打印机或调用API接口添加之后,才能调用API
  42. //以下参数不需要修改
  43. define('IP','api.feieyun.cn'); //接口IP或域名
  44. define('PORT',80); //接口IP端口
  45. define('PATH','/Api/Open/'); //接口路径
  46. define('STIME', time()); //公共参数,请求时间
  47. define('SIG', sha1(USER.UKEY.STIME));
  48. function wp_print($printer_sn,$orderInfo,$times){
  49. $content = array(
  50. 'user'=>USER,
  51. 'stime'=>STIME,
  52. 'sig'=>SIG,
  53. 'apiname'=>'Open_printMsg',
  54. 'sn'=>$printer_sn,
  55. 'content'=>$orderInfo,
  56. 'times'=>$times//打印次数
  57. );
  58. $client = new HttpClient(IP,PORT);
  59. if(!$client->post(PATH,$content)){
  60. echo 'error';
  61. }
  62. else{
  63. //服务器返回的JSON字符串,建议要当做日志记录起来
  64. echo $client->getContent();
  65. }
  66. }
  67. wp_print(SN,$content,1);
  68. }
  69. }