<?php
namespace Wechat;
use Wechat\Lib\Common;
use Wechat\Lib\Tools;
class WechatHardware extends Common
{
const DEVICE_AUTHORIZE_DEVICE = '/device/authorize_device?'; const DEVICE_GETQRCODE = '/device/getqrcode?'; const DEVICE_CREATE_QRCODE = '/device/create_qrcode?'; const DEVICE_GET_STAT = '/device/get_stat?'; const DEVICE_TRANSMSG = '/device/transmsg?'; const DEVICE_COMPEL_UNBINDHTTPS = '/device/compel_unbind?';
public function deviceCompelUnbindhttps($data)
{
if (!$this->access_token && !$this->getAccessToken()) {
return false;
}
$result = Tools::httpPost(self::API_BASE_URL_PREFIX . self::DEVICE_COMPEL_UNBINDHTTPS . "access_token={$this->access_token}", Tools::json_encode($data));
if ($result) {
$json = json_decode($result, true);
if (empty($json) || !empty($json['errcode'])) {
$this->errCode = isset($json['errcode']) ? $json['errcode'] : '505';
$this->errMsg = isset($json['errmsg']) ? $json['errmsg'] : '无法解析接口返回内容!';
return $this->checkRetry(__FUNCTION__, func_get_args());
}
return $json;
}
return false;
}
public function transmsg($data)
{
if (!$this->access_token && !$this->getAccessToken()) {
return false;
}
$result = Tools::httpPost(self::API_BASE_URL_PREFIX . self::DEVICE_TRANSMSG . "access_token={$this->access_token}", Tools::json_encode($data));
if ($result) {
$json = json_decode($result, true);
if (empty($json) || !empty($json['errcode'])) {
$this->errCode = isset($json['errcode']) ? $json['errcode'] : '505';
$this->errMsg = isset($json['errmsg']) ? $json['errmsg'] : '无法解析接口返回内容!';
return $this->checkRetry(__FUNCTION__, func_get_args());
}
return $json;
}
return false;
}
public function getQrcode($product_id)
{
if (!$this->access_token && !$this->getAccessToken()) {
return false;
}
$result = Tools::httpGet(self::API_BASE_URL_PREFIX . self::DEVICE_GETQRCODE . "access_token={$this->access_token}&product_id=$product_id");
if ($result) {
$json = json_decode($result, true);
if (empty($json) || !empty($json['errcode'])) {
$this->errCode = isset($json['errcode']) ? $json['errcode'] : '505';
$this->errMsg = isset($json['errmsg']) ? $json['errmsg'] : '无法解析接口返回内容!';
return $this->checkRetry(__FUNCTION__, func_get_args());
}
return $json;
}
return false;
}
public function deviceAuthorize($data)
{
if (!$this->access_token && !$this->getAccessToken()) {
return false;
}
$result = Tools::httpPost(self::API_BASE_URL_PREFIX . self::DEVICE_AUTHORIZE_DEVICE . "access_token={$this->access_token}", Tools::json_encode($data));
if ($result) {
$json = json_decode($result, true);
if (empty($json) || !empty($json['errcode'])) {
$this->errCode = isset($json['errcode']) ? $json['errcode'] : '505';
$this->errMsg = isset($json['errmsg']) ? $json['errmsg'] : '无法解析接口返回内容!';
return $this->checkRetry(__FUNCTION__, func_get_args());
}
return $json;
}
return false;
}
public function getDeviceQrcode($data)
{
if (!$this->access_token && !$this->getAccessToken()) {
return false;
}
$result = Tools::httpPost(self::API_BASE_URL_PREFIX . self::DEVICE_CREATE_QRCODE . "access_token={$this->access_token}", Tools::json_encode($data));
if ($result) {
$json = json_decode($result, true);
if (empty($json) || !empty($json['errcode'])) {
$this->errCode = isset($json['errcode']) ? $json['errcode'] : '505';
$this->errMsg = isset($json['errmsg']) ? $json['errmsg'] : '无法解析接口返回内容!';
return $this->checkRetry(__FUNCTION__, func_get_args());
}
return $json;
}
return false;
}
public function getDeviceStat($device_id)
{
if (!$this->access_token && !$this->getAccessToken()) {
return false;
}
$result = Tools::httpGet(self::API_BASE_URL_PREFIX . self::DEVICE_GET_STAT . "access_token={$this->access_token}&device_id=$device_id");
if ($result) {
$json = json_decode($result, true);
if (empty($json) || !empty($json['errcode'])) {
$this->errCode = isset($json['errcode']) ? $json['errcode'] : '505';
$this->errMsg = isset($json['errmsg']) ? $json['errmsg'] : '无法解析接口返回内容!';
return $this->checkRetry(__FUNCTION__, func_get_args());
}
return $json;
}
return false;
}
}