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",//批量更新sku信息
- "youzan.item.delete",//删除商品
- "youzan.item.search",//分页查询微商城销售中和已售罄商品列表
- "youzan.item.update",//更新商品信息
- "youzan.item.add",//商品新建
- "youzan.itemcategories.get",//商品类目二维列表
- "youzan.item.detail.get",//单个商品明细
- "youzan.item.full.sku.update",//商品sku信息全量更新,
- "youzan.item.update.delisting",//商品下架,
- "youzan.item.sku.update",//更新sku信息微商城单店
- "youzan.retail.open.category.create",//商品分类信息新增,
- "youzan.retail.open.brand.add",//新建品牌
- "youzan.retail.open.sku.query",//商品查询 sku
- "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'];
- }
- }
|