diff --git a/src/guanyierp.php b/src/guanyierp.php index 4e092e9..92c9eae 100644 --- a/src/guanyierp.php +++ b/src/guanyierp.php @@ -7,7 +7,7 @@ class guanyierp /** 配置文件 */ public $config = []; public $data; - public $url = 'https://v2.api.guanyierp.com/rest/erp_open'; + public $url = 'http://v2.api.guanyierp.com/rest/erp_open'; private $_error; //详细代码信息 private $_errno; //出错代码编号 public $orgi; //原始数据 diff --git a/src/guanyiweb.php b/src/guanyiweb.php index bc1ab0b..b3bd239 100644 --- a/src/guanyiweb.php +++ b/src/guanyiweb.php @@ -16,6 +16,7 @@ class guanyiweb public $total; //内容的总数量 public $url; public $path; + public $guanyiauth; public function __construct($config = []) @@ -25,6 +26,11 @@ public function __construct($config = []) } } + public function setAuth($auth){ + $this->guanyiauth = $auth; + return $auth; + } + public function config($config){ if(!is_array($config)){ $_config = []; @@ -38,17 +44,23 @@ public function config($config){ return $this; } - public function initWeb($string) + public function initWeb($cookie='') { - if(!$string){ + if($this->guanyiauth){ + $cookie = $this->guanyiauth->cache(); + if (!$cookie) { + $cookie = $this->guanyiauth->login(); + } + } + if(!$cookie){ $this->setErr('WEB参数未配备'); return false; } - $config = json_decode($string, true); - if(isset($config['Cookie'])){ - $this->config($config); + $configs = json_decode($cookie, true); + if($configs && isset($configs['Cookie'])){ + $this->config($configs); }else{ - $this->config($string); + $this->config($cookie); } $config = $this->get('config'); if(!isset($config['Cookie'])||!$config['Cookie']){ @@ -106,10 +118,21 @@ public function setOK() */ public function getTo($method, $data, $filed = null) { + $this->data = $data; $this->path = $method; $result = $this->webPost(); + if($this->guanyiauth){ + if(!$this->body && !$result){ + $cookie = $this->guanyiauth->login(); + if (!$cookie) { + return $this->handler($result, $filed); + } + $this->initWeb($cookie); + $result = $this->webPost(); + } + } return $this->handler($result, $filed); }