YouZan.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. public function __construct()
  16. {
  17. $this->Token =new Token($this->clientId,$this->clientSecret);
  18. $this->Client=new Client($this->GetToken());
  19. }
  20. public function GetData($method,$params=[]){
  21. return $this->Client->post($method,$this->apiVersion, $params);
  22. }
  23. private function GetToken(){
  24. $token = Cache::get("YouZanToken");
  25. if(isset($token)&& $token!=""){
  26. return $token['access_token'];
  27. }
  28. $token =$this->Token->getSelfAppToken($this->authorityId,["refresh"=>true]);
  29. Cache::set("YouZanToken",$token,3500);
  30. return $token['access_token'];
  31. }
  32. }