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',//批量更新sku信息
- 'youzan.item.delete',//删除商品
- 'youzan.item.search',//分页查询微商城销售中和已售罄商品列表
- 'youzan.item.update',//更新商品信息
- 'item_add' => 'youzan.item.add',//商品新建,1.0.1
- 'cat_list' => 'youzan.itemcategories.get',//商品类目二维列表(v2版本)
- 'cat_v4_list' => 'youzan.category.listchildren',//新版商品类目列表(v4版本)
- 'item_detail' => 'youzan.item.detail.get',//单个商品明细
- 'youzan.item.full.sku.update',//商品sku信息全量更新,
- 'item_delisting' => 'youzan.item.update.delisting',//商品下架,
- 'youzan.item.sku.update',//更新sku信息微商城单店
- 'youzan.retail.open.category.create',//商品分类信息新增,
- 'youzan.retail.open.sku.query',//商品查询 sku
- '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',//通过商品或者skuId查询规格明细
- '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"
- ];
- //youzan.ump.voucheractivity.query.3.0.2 根据活动查询选项查询活动详情信息
- //youzan.ump.voucheractivity.manage.info.search.1.0.1 :查询优惠券/码活动管理信息
- //'youzan.ump.voucheractivity.delete',//优惠码/券删除
- 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);
- }
- }
|