YouZan.php 2.3 KB

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