From 94ba0ec7edb4daf24c741e40130282607bde0eae Mon Sep 17 00:00:00 2001 From: lyhiving Date: Sat, 6 Nov 2021 21:11:18 +0800 Subject: [PATCH] add guanyiauth support --- src/guanyierp.php | 2 +- src/guanyiweb.php | 35 +++++++++++++++++++++++++++++------ 2 files changed, 30 insertions(+), 7 deletions(-) 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); }