乐趣区

关于打印功能:飞鹅云-php-sdk

class Feieyun
{
    /**
     * @var string
     */
    protected $host = 'http://api.feieyun.cn/Api/Open/';

    /**
     * @var
     */
    protected $config=['username'=>'','uKey'=>'',];

    /**
     * Feieyun constructor.
     * @param $config
     */
    public function __construct(array $config)
    {$this->config = array_merge($this->config,$config);
    }



    /**
     * 增加打印机
     * @return mixed
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function add(array $private_params = [])
    {// TODO: Implement add() method.
        return $this->request($private_params, 'Open_printerAddlist');
    }

    /**
     * 更新打印机
     * @param array $private_params
     * @return mixed
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function update($private_params = [])
    {// TODO: Implement update() method.
        return $this->request($private_params, 'Open_printerEdit');
    }

    /**
     * 删除打印机
     * @param array $private_params
     * @return mixed
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function delete($private_params = [])
    {// TODO: Implement delete() method.
        return $this->request($private_params, 'Open_printerDelList');
    }

    /**
     * 清空待打印队列
     * @param array $private_params
     * @return mixed
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function clear($private_params = [])
    {// TODO: Implement clear() method.
        return $this->request($private_params, 'Open_delPrinterSqs');
    }

    /**
     * 打印机状态
     * @param array $private_params
     * @return mixed
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function status($private_params = [])
    {// TODO: Implement status() method.
        return $this->request($private_params, 'Open_queryPrinterStatus');
    }


    /**
     * @param array $private_params
     * @param string $type
     * @return string
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function outputOrder($private_params = [], $type = '')
    {if ($type == 'lable')
            return $this->outputLabelMsg($private_params);
        return $this->outputMsg($private_params);
    }

    /**
     * 打印订单
     * @param array $private_params
     * @return string
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function outputMsg($private_params = [])
    {return $this->request($private_params, 'Open_printMsg');
    }

    /**
     * 标签机打印订单
     * @param array $private_params
     * @return string
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function outputLabelMsg($private_params = [])
    {return $this->request($private_params, 'Open_printLabelMsg');
    }

    /**
     * 查问订单是否打印胜利
     * @param array $private_params
     * @return string
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function orderStatus($private_params = [])
    {return $this->request($private_params, 'Open_queryOrderState');
    }

    /**
     * 查问指定打印机某天的订单统计数
     * @param array $private_params
     * @return string
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function orderCount($private_params = [])
    {return $this->request($private_params, 'Open_queryOrderState');
    }

    /**
     * @param array $private_params
     * @param string $apiname
     * @return string
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function request(array $private_params, string $apiname)
    {
        $public_params = ['user' => $this->config['username'],
            'stime' => $this->getTime(),
            'sig' => $this->getSig(),
            'apiname' => $apiname,
        ];
        $params = array_filter(array_merge($public_params, $private_params));
        return $this->post($this->config['host'] ?? $this->host, $params);
    }

    /**
     * @param string $url
     * @param array $params
     * @param array $headers
     * @return string
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    protected function post(string $url, array $params = [], array $headers = [])
    {$resp = (new \GuzzleHttp\Client())->request('post', $url, [
            'headers' => $headers,
            'form_params' => $params,
        ]);;
        return $resp->getBody()->getContents();
    }

    /**
     * @return string
     */
    protected function getSig()
    {return sha1($this->config['username'] . $this->config['uKey'] . $this->getTime());
    }

    /**
     * @return int
     */
    protected function getTime()
    {return time();
    }
}
退出移动版