123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?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;
- private $clientSecret;
- private $apiVersion='3.0.0';
- private $authorityId;
- private $methodlist=[
- "youzan.item.update.listing",
- "youzan.item.incremental.update",
- "youzan.retail.open.spu.update",
- "youzan.retail.open.sku.update.price",
- "youzan.item.sku.batch.update",
- "youzan.item.delete",
- "youzan.item.search",
- "youzan.item.update",
- "youzan.item.add",
- "youzan.itemcategories.get",
- "youzan.item.detail.get",
- "youzan.item.full.sku.update",
- "youzan.item.update.delisting",
- "youzan.item.sku.update",
- "youzan.retail.open.category.create",
- "youzan.retail.open.brand.add",
- "youzan.retail.open.sku.query",
- "youzan.items.onsale.get",
- "youzan.retail.open.brand.delete",
- "youzan.retail.open.category.query",
- "youzan.retail.open.brand.querypage"
- ];
- public function __construct()
- {
- $this->clientId =env('yz.clientid');
- $this->clientSecret=env('yz.clientsecret');
- $this->authorityId =env('yz.authorityid');
- $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['access_token'])&& $token['access_token']!=''){
- return $token['access_token'];
- }
- $token =$this->Token->getSelfAppToken($this->authorityId,["refresh"=>true]);
- Cache::set("YouZanToken",$token,3500);
- return $token['access_token'];
- }
- }
|