123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace app\common;
- use think\facade\Cache;
- class Youzan {
- private $Client;
- private $clientId;
- private $clientSecret;
- private $apiVersion='3.0.0';
- private $authorityId;
- private $methodlist = [
- 'item_online' => 'youzan.item.update.listing',
- 'item_update' => 'youzan.item.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',
- 'item_add' => 'youzan.item.add',
- 'cat_list' => 'youzan.itemcategories.get',
- 'cat_v4_list' => 'youzan.category.listchildren',
- 'item_detail' => 'youzan.item.detail.get',
- 'youzan.item.full.sku.update',
- 'item_delisting' => 'youzan.item.update.delisting',
- 'youzan.item.sku.update',
- 'youzan.retail.open.category.create',
- 'youzan.retail.open.sku.query',
- 'youzan.items.onsale.get',
- 'youzan.retail.open.brand.delete',
- 'category' => 'youzan.retail.open.category.query',
- 'brand_list' => 'youzan.retail.open.brand.querypage',
- 'express_list' => 'youzan.logistics.express.get',
- 'regions_list' => 'youzan.regions.get',
- 'img_upload' => 'youzan.materials.storage.platform.img.upload',
- 'sku_get' => 'youzan.item.sku.get',
- 'logistics'=>'youzan.logistics.online.confirm',
- 'logistics_update'=>'youzan.logistics.online.update',
- 'querybyorderno'=>'youzan.trade.dc.query.querybyorderno',
- 'getUserInfo'=>'youzan.users.info.query',
- 'promocode'=>'youzan.ump.promocode.add',
- 'promocode_delete'=>'youzan.ump.voucheractivity.delete',
- 'promocode_query'=>'youzan.ump.voucheractivity.query',
- "coupon_search"=>"youzan.ump.voucheractivity.manage.info.search"
- ];
-
-
-
- public function __construct()
- {
- $this->clientId =env('yz.clientid');
- $this->clientSecret=env('yz.clientsecret');
- $this->authorityId =env('yz.authorityid');
- $this->Client = new \Youzan\Open\Client($this->getToken());
- }
- public function getToken(){
- $cache =Cache::store("redis2");
- $token = $cache->get('YouZanToken'.$this->authorityId);
- if(!isset($token['access_token'])|| $token['access_token']==''){
- $yzToken = new \Youzan\Open\Token($this->clientId,$this->clientSecret);
- $token =$yzToken->getSelfAppToken($this->authorityId,['refresh'=>true]);
- $cache->set('YouZanToken'.$this->authorityId,$token,(new \DateTime($token['expires']/100))->format("Y-m-d H:i:s"));
- }
- return $token['access_token'];
- }
- public function getData($method,$params=[],$version=''){
- if($version!=='') $this->apiVersion=$version;
- return $this->Client->post($this->methodlist[$method]??$method,$this->apiVersion, $params);
- }
- }
|