dyj.php
3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
include_once "print.class.php";
include_once "HttpClient.class.php";
class Dyj
{
//365打印机
public static function dy($deviceNo,$content,$key)
{
$selfMessage = array(
'deviceNo' => $deviceNo,
'printContent' => $content,
'key' => $key,
'times' => 1
);
$url = "http://open.printcenter.cn:8080/addOrder";
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded ",
'method' => 'POST',
'content' => http_build_query($selfMessage),
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
return $result;
}
//易联云打印机
public static function ylydy($api,$token,$yy_id,$mid,$content)
{
$print = new Yprint();
$apiKey = $api;
$msign = $token;
$partner = $yy_id;
$machine_code = $mid;
$result = $print->action_print( $partner,$machine_code,$content,$apiKey,$msign);
return $result;
}
//飞蛾打印机
public static function fedy($fezh,$fe_ukey,$fe_dycode,$content,$times)
{
header("Content-type: text/html; charset=utf-8");
define('USER', $fezh); //*必填*:飞鹅云后台注册账号
define('UKEY', $fe_ukey); //*必填*: 飞鹅云注册账号后生成的UKEY
define('SN', $fe_dycode); //*必填*:打印机编号,必须要在管理后台里添加打印机或调用API接口添加之后,才能调用API
//以下参数不需要修改
define('IP','api.feieyun.cn'); //接口IP或域名
define('PORT',80); //接口IP端口
define('PATH','/Api/Open/'); //接口路径
define('STIME', time()); //公共参数,请求时间
define('SIG', sha1(USER.UKEY.STIME));
if(is_array($fe_dycode)) {
$res = '';
foreach ($fe_dycode as $key => $value) {
$res .= self::wpPrint($value, $content, $times);
}
return $res;
} else {
return self::wpPrint($fe_dycode,$content,$times);
}
}
/**
* @param $printer_sn
* @param $orderInfo
* @param $times
*/
static function wpPrint($printer_sn,$orderInfo,$times)
{
$content = array(
'user' => USER,
'stime' => STIME,
'sig' => SIG,
'apiname' => 'Open_printMsg',
'sn' => $printer_sn,
'content' => $orderInfo,
'times' => $times//打印次数
);
$client = new HttpClient(IP,PORT);
if (!$client->post(PATH,$content)) {
return 'error';
} else {
//服务器返回的JSON字符串,建议要当做日志记录起来
return $client->getContent();
}
}
//喜讯
public static function postData($url, $data)
{
$ch = curl_init();
$timeout = 300;
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转 (很重要)
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_REFERER, "115.28.15.113/"); //构造来路
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
//ob_start();
$handles = curl_exec($ch); //获取返回结果
curl_close($ch);
return $handles;
}
}