123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- <?php
- /**
- * Created by PhpStorm.
- * User: phperstar
- * Date: 2020/6/17
- * Time: 3:35 PM
- */
- namespace Util\CloudPrint;
- use JinDouYun\Controller\Common\Logger;
- use Mall\Framework\Core\ResultWrapper;
- use Mall\Framework\Core\ErrorCode;
- class Gainshca
- {
- /**
- * 商户编码
- */
- private $memberCode;
- /**
- * 终端编号
- */
- private $deviceID;
- /**
- * API密钥
- */
- private $apiKey;
- /**
- * 微信小程序接口主域名
- * @var string $apiUrl
- */
- private $apiUrl = 'http://api.poscom.cn/apisc/';
- public function __construct($memberCode='', $deviceID='', $apiKey = '')
- {
- $this->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']]);
- }
- }
- }
|