YouZan.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace app\admin\common;
  3. use think\facade\Cache;
  4. use Youzan\Open\Client;
  5. use Youzan\Open\Token;
  6. class YouZan
  7. {
  8. private $Client;
  9. private $Token;
  10. private $clientId;
  11. private $clientSecret;
  12. private $apiVersion='3.0.0';
  13. private $authorityId;
  14. private $methodlist=[
  15. "youzan.item.update.listing",//上架商品
  16. "youzan.item.incremental.update",//增量更新商品信息接口
  17. "youzan.retail.open.spu.update",//更新单个商品库商品信息
  18. "youzan.retail.open.sku.update.price",//更新商品价格
  19. "youzan.item.sku.batch.update",//批量更新sku信息
  20. "youzan.item.delete",//删除商品
  21. "youzan.item.search",//分页查询微商城销售中和已售罄商品列表
  22. "youzan.item.update",//更新商品信息
  23. "youzan.item.add",//商品新建
  24. "youzan.itemcategories.get",//商品类目二维列表
  25. "youzan.item.detail.get",//单个商品明细
  26. "youzan.item.full.sku.update",//商品sku信息全量更新,
  27. "youzan.item.update.delisting",//商品下架,
  28. "youzan.item.sku.update",//更新sku信息微商城单店
  29. "youzan.retail.open.category.create",//商品分类信息新增,
  30. "youzan.retail.open.brand.add",//新建品牌
  31. "youzan.retail.open.sku.query",//商品查询 sku
  32. "youzan.items.onsale.get",//获取出售中得商品
  33. "youzan.retail.open.brand.delete",//品牌删除
  34. "youzan.retail.open.category.query",//商品分类信息查询
  35. "youzan.retail.open.brand.querypage"//品牌查询接口
  36. ];
  37. public function __construct()
  38. {
  39. $this->clientId =env('yz.clientid');
  40. $this->clientSecret=env('yz.clientsecret');
  41. $this->authorityId =env('yz.authorityid');
  42. $this->Token =new Token($this->clientId,$this->clientSecret);
  43. $this->Client=new Client($this->GetToken());
  44. }
  45. public function GetData($method,$params=[]){
  46. return $this->Client->post($method,$this->apiVersion, $params);
  47. }
  48. private function GetToken(){
  49. $token = Cache::get("YouZanToken");
  50. if(isset($token['access_token'])&& $token['access_token']!=''){
  51. return $token['access_token'];
  52. }
  53. $token =$this->Token->getSelfAppToken($this->authorityId,["refresh"=>true]);
  54. Cache::set("YouZanToken",$token,3500);
  55. return $token['access_token'];
  56. }
  57. }