sn = $sn; } public function printMsg($content) { $time = time(); //请求时间 $msgInfo = array( 'user' => $this->user, 'stime' => $time, 'sig' => $this->signature($time), 'apiname' => 'Open_printMsg', 'sn' => $this->sn, 'content' => $content, 'times' => $this->times//打印次数 ); $client = new \HttpClient(self::IP, self::PORT); if (!$client->post(self::PATH, $msgInfo)) { //echo 'error'; } else { //服务器返回的JSON字符串,建议要当做日志记录起来 $result = $client->getContent(); //echo $result; } } public function signature($time) { return sha1($this->user . $this->uKey . $time);//公共参数,请求公钥 } //批量添加打印机 shish 20210712 public function addPrint($key, $shopName) { $printerContent = "sn{$this->sn}#{$key}#{$shopName}"; $time = time(); //请求时间 $msgInfo = array( 'user' => $this->user, 'stime' => $time, 'sig' => $this->signature($time), 'apiname' => 'Open_printerAddlist', 'printerContent' => $printerContent ); $client = new \HttpClient(self::IP, self::PORT); if (!$client->post(self::PATH, $msgInfo)) { return false; } $content = $client->getContent(); $respond = json_decode($content, true); if (isset($respond['data']['ok']) && !empty($respond['data']['ok'])) { return true; } $no = $respond['data']['no'][0] ?? ''; if (strstr($no, "已被添加过")) { return true; } return false; } //查询打印机状态 shish 20210714 public function queryPrinterStatus($sn) { $time = time(); //请求时间 $msgInfo = array( 'user' => $this->user, 'stime' => $time, 'sig' => $this->signature($time), 'apiname' => 'Open_queryPrinterStatus', 'sn' => $sn ); $client = new \HttpClient(self::IP, self::PORT); if (!$client->post(self::PATH, $msgInfo)) { echo 'error'; } $client->getContent(); } }