YouzanApi.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * Created by 浙江小趣信息技术有限公司.
  4. * User: yqj
  5. * Date: 2017/5/16
  6. * Time: 11:03
  7. */
  8. namespace App\Lib\Youzan;
  9. class YouzanApi
  10. {
  11. private $client ;
  12. private static $_instance = null;
  13. private function __construct($app_id,$app_secret)
  14. {
  15. $this->client = new \YZSignClient($app_id,$app_secret);
  16. }
  17. /**
  18. * @param $params
  19. * @param array $files
  20. * @param string $methodVersion
  21. * @return array
  22. */
  23. public function addProduct($params,$files=[],$methodVersion='1.0.0'){
  24. return $this->getHttp('kdt.item.add', $params, $files,$methodVersion);
  25. }
  26. /**
  27. * @param $params
  28. * @param array $files
  29. * @param string $methodVersion
  30. * @return array
  31. */
  32. public function updateProduct($params,$files=[],$methodVersion='1.0.0'){
  33. return $this->getHttp('kdt.item.update', $params, $files,$methodVersion);
  34. }
  35. /**
  36. * 更新商品Sku 信息
  37. */
  38. public function updateSkuInfos($params,$methodVersion='1.0.0'){
  39. return $this->getHttp('kdt.item.sku.update',$params,[],$methodVersion);
  40. }
  41. public function getProduct($params,$files=[],$methodVersion='1.0.0'){
  42. return $this->getHttp('kdt.item.get', $params, $files,$methodVersion);
  43. }
  44. public function getCategory(){
  45. }
  46. /**
  47. * @param $method
  48. * @param $params
  49. * @param array $files
  50. * @param string $methodVersion
  51. * @return array
  52. */
  53. private function getHttp($method,$params,$files=[],$methodVersion='1.0.0'){
  54. $result = $this->client->post($method, $methodVersion, $params, $files);
  55. if(isset($result['error_response'])){
  56. return ['code'=>$result['error_response']['code'],'msg'=>$result['error_response']['msg']] ;
  57. }
  58. return ['code'=>200,'msg'=>"操作成功!",'response'=>$result['response']];
  59. }
  60. /**
  61. * @param $app_id
  62. * @param $app_secret
  63. * @return YouzanApi|null
  64. */
  65. public static function getInstance($app_id,$app_secret)
  66. {
  67. if (is_null ( self::$_instance ) || isset ( self::$_instance ))
  68. {
  69. self::$_instance = new self ($app_id,$app_secret);
  70. }
  71. return self::$_instance;
  72. }
  73. }