Skip to content

Commit

Permalink
add guanyiauth support
Browse files Browse the repository at this point in the history
  • Loading branch information
lyhiving committed Nov 6, 2021
1 parent 46b343e commit 94ba0ec
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/guanyierp.php
Original file line number Diff line number Diff line change
Expand Up @@ -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; //原始数据
Expand Down
35 changes: 29 additions & 6 deletions src/guanyiweb.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class guanyiweb
public $total; //内容的总数量
public $url;
public $path;
public $guanyiauth;


public function __construct($config = [])
Expand All @@ -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 = [];
Expand All @@ -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']){
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 94ba0ec

Please sign in to comment.