memberCode = $memberCode; $this->deviceID = $deviceID; $this->apiKey = $apiKey; } /** * 添加打印机设备 */ public function adddev() { $postData = [ 'reqTime' => msectime(), 'securityCode' => md5($this->memberCode.msectime().$this->apiKey.$this->deviceID), 'memberCode' => $this->memberCode, 'deviceID' => $this->deviceID, 'devName' => '千鸟云商', ]; $apiUrl = $this->apiUrl.'adddev'; $reponse = request($apiUrl, $postData); if($reponse['httpcode'] != 200){ return ResultWrapper::fail('请求外部系统接口报错', ErrorCode::$apiNotResult); }else{ $reponseData = json_decode($reponse['content'], true); if( isset($reponseData['code']) && $reponseData['code'] != 1){ return ResultWrapper::fail($reponseData['msg'], $reponseData['code']); } return ResultWrapper::success(['devID'=>$reponseData['devID']]); } } /** * 发送信息到打印机 * @param $params * @return ResultWrapper */ public function sendMsg($params) { $postData = [ 'reqTime' => msectime(), 'securityCode' => md5($this->memberCode.$this->deviceID.msectime().$this->apiKey), 'memberCode' => $this->memberCode, 'deviceID' => $this->deviceID, 'mode' => 2, 'msgDetail' => $params ]; $apiUrl = $this->apiUrl.'sendMsg'; $reponse = request($apiUrl, $postData); if($reponse['httpcode'] != 200){ return ResultWrapper::fail('请求外部系统接口报错', ErrorCode::$apiNotResult); }else{ $reponseData = json_decode($reponse['content'], true); Logger::logs(E_USER_ERROR,'打印机返回信息',__CLASS__,__LINE__,$reponseData); if( isset($reponseData['code']) && $reponseData['code'] != 0){ return ResultWrapper::fail($reponseData['msg'], $reponseData['code']); } return ResultWrapper::success(['devID'=>$reponseData['devID']]); } } /** * 查询打印机状态 * @param $deviceID * @param $selectAll * @return ResultWrapper */ public function getStatus($deviceID, $selectAll) { $postData = [ 'reqTime' => msectime(), 'securityCode' => md5($this->memberCode.msectime().$this->apiKey), 'memberCode' => $this->memberCode, 'deviceID' => $this->deviceID, ]; if($deviceID) $postData['deviceID'] = $deviceID; if($selectAll) unset($postData['deviceID']); $apiUrl = $this->apiUrl.'getStatus'; $reponse = request($apiUrl, $postData); if($reponse['httpcode'] != 200){ return ResultWrapper::fail('请求外部系统接口报错', ErrorCode::$apiNotResult); }else{ $reponseData = json_decode($reponse['content'], true); if( isset($reponseData['code']) && $reponseData['code'] != 1){ return ResultWrapper::fail($reponseData['msg'], $reponseData['code']); } return ResultWrapper::success($reponseData['statusList']); } } /** * 查询打印机状态 * @param $deviceID * @param $selectAll * @return ResultWrapper */ public function setVolume($num) { $postData = [ 'reqTime' => msectime(), 'securityCode' => md5($this->memberCode.msectime().$this->apiKey.$this->deviceID), 'memberCode' => $this->memberCode, 'deviceID' => $this->deviceID, 'volume' => $num ]; $apiUrl = $this->apiUrl.'sendVolume'; $reponse = request($apiUrl, $postData); if($reponse['httpcode'] != 200){ return ResultWrapper::fail('请求外部系统接口报错', ErrorCode::$apiNotResult); }else{ $reponseData = json_decode($reponse['content'], true); if( isset($reponseData['code']) && $reponseData['code'] != 1){ return ResultWrapper::fail($reponseData['msg'], $reponseData['code']); } return ResultWrapper::success(['devID'=>$reponseData['devID']]); } } }