1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- /**
- * Created by 浙江小趣信息技术有限公司.
- * User: yqj
- * Date: 2017/5/16
- * Time: 11:03
- */
- namespace App\Lib\Youzan;
- class YouzanApi
- {
- private $client ;
- private static $_instance = null;
- private function __construct($app_id,$app_secret)
- {
- $this->client = new \YZSignClient($app_id,$app_secret);
- }
- /**
- * @param $params
- * @param array $files
- * @param string $methodVersion
- * @return array
- */
- public function addProduct($params,$files=[],$methodVersion='1.0.0'){
- return $this->getHttp('kdt.item.add', $params, $files,$methodVersion);
- }
- /**
- * @param $params
- * @param array $files
- * @param string $methodVersion
- * @return array
- */
- public function updateProduct($params,$files=[],$methodVersion='1.0.0'){
- return $this->getHttp('kdt.item.update', $params, $files,$methodVersion);
- }
- /**
- * 更新商品Sku 信息
- */
- public function updateSkuInfos($params,$methodVersion='1.0.0'){
- return $this->getHttp('kdt.item.sku.update',$params,[],$methodVersion);
- }
- public function getProduct($params,$files=[],$methodVersion='1.0.0'){
- return $this->getHttp('kdt.item.get', $params, $files,$methodVersion);
- }
- public function getCategory(){
- }
- /**
- * @param $method
- * @param $params
- * @param array $files
- * @param string $methodVersion
- * @return array
- */
- private function getHttp($method,$params,$files=[],$methodVersion='1.0.0'){
- $result = $this->client->post($method, $methodVersion, $params, $files);
- if(isset($result['error_response'])){
- return ['code'=>$result['error_response']['code'],'msg'=>$result['error_response']['msg']] ;
- }
- return ['code'=>200,'msg'=>"操作成功!",'response'=>$result['response']];
- }
- /**
- * @param $app_id
- * @param $app_secret
- * @return YouzanApi|null
- */
- public static function getInstance($app_id,$app_secret)
- {
- if (is_null ( self::$_instance ) || isset ( self::$_instance ))
- {
- self::$_instance = new self ($app_id,$app_secret);
- }
- return self::$_instance;
- }
- }
|