1234567891011121314151617181920212223242526272829303132333435363738 |
- <?php
- namespace app\admin\common;
- use think\facade\Cache;
- use Youzan\Open\Client;
- use Youzan\Open\Token;
- class YouZan
- {
- private $Client;
- private $Token;
- private $clientId='deaaebe6484c129787';
- private $clientSecret='3c654aa2fbc1b5da788ffdba45fb96f0';
- private $method='https://open.youzanyun.com/api/';
- private $apiVersion='3.0.0';
- private $authorityId='109334129';
- public function __construct()
- {
- $this->Token =new Token($this->clientId,$this->clientSecret);
- $this->Client=new Client($this->GetToken());
- }
- public function GetData($method,$params=[]){
- return $this->Client->post($method,$this->apiVersion, $params);
- }
- private function GetToken(){
- $token = Cache::get("YouZanToken");
- if(isset($token)&& $token!=""){
- return $token['access_token'];
- }
- $token =$this->Token->getSelfAppToken($this->authorityId,["refresh"=>true]);
- Cache::set("YouZanToken",$token,3500);
- return $token['access_token'];
- }
- }
|