首页 > 其他分享 >kaufland平台api

kaufland平台api

时间:2023-02-28 17:47:19浏览次数:50  
标签:ch 平台 uri header api time kaufland curl CURLOPT

 class KauflandapiController extends YbController{


     public $header, $url, $secretKey, $ClientKey;

     /**
      * GetDiscussionMailListResponse constructor.
      * @param $response
      */
     public function __construct()
     {
         $this->secretKey = "2ac36025d9dbf5a1c2e0869b8a2e";
         $this->ClientKey = "b2c4666dc9cf64b1cf29";
         $header = array();
         $header[] = 'Accept:application/json';
         $header[] = 'Content-Type:application/json';
         $header[] = 'HM-Client:'.$this->ClientKey;
         $this->header = $header;
         $this->url = "https://www.kaufland.de";
     }

     /**
      * description: 所有需要用到的调用接口地址信息统一管理
      */
     public function getUrl($url_code)
     {
         $urls = [
             'categories' => '/api/v1/categories',
             'update_product' => '/api/v1/product-data/',
             'report_list' => '/api/v1/reports/seller',
             'report_info' => '/api/v1/reports/',
             'account_listing' => '/api/v1/reports/account-listing',
             'get_units_listing' => '/api/v1/units/seller',
             'get_units' => '/api/v1/units/',
         ];
         return $this->url ? $this->url . $urls[$url_code] : '';
     }

     /**
      * description: 所有需要用到的调用接口地址信息
      */
     public function signRequest($method, $uri, $body, $timestamp, $secretKey)
     {
         $string = implode("\n", [
             $method,
             $uri,
             $body,
             $timestamp,
         ]);
         echo $string;
         return hash_hmac('sha256', $string, $secretKey);
     }

     /**
      * description: 分类接口内容调用
      * @throws CException
      * url:/services/yunyi/Kauflandapi/categorier
      */
     public function actionCategorier()
     {
         $uri = $this->getUrl("categories");
         $time = time();
         $hash_sign = $this->signRequest("GET", $uri, "", $time , $this->secretKey);
         $header = $this->header;
         $header[] = "HM-Signature:".$hash_sign;
         $header[] = "HM-Timestamp:".$time;
         //$result = $this->cur_get($uri,$header);
         $result = $this->cur_request($uri,"GET","",$header);
         echo "<pre>";
            print_r($result);
            exit;
     }

     /**
      * description: 获取报告列表
      * @throws CException
      * url:/services/yunyi/Kauflandapi/getreportlist
      */
     public function actionGetreportlist()
     {
         $uri = $this->getUrl("report_list");
         $time = time();
         $hash_sign = $this->signRequest("GET", $uri, "", $time , $this->secretKey);
         $header = $this->header;
         $header[] = "HM-Signature:".$hash_sign;
         $header[] = "HM-Timestamp:".$time;
         //$result = $this->cur_get($uri,$header);
         $result = $this->cur_request($uri,"GET","",$header);
         echo "<pre>";
         echo $uri."\n";
         print_r($result);
         exit;
     }

     /**
      * description: 获取报告信息
      * @throws CException
      * url:/services/yunyi/Kauflandapi/getreportinfo
      */
     public function actionGetreportinfo()
     {
         $report_id = "4041098";
         $uri = $this->getUrl("report_info").$report_id;
         $time = time();
         $hash_sign = $this->signRequest("GET", $uri, "", $time , $this->secretKey);
         $header = $this->header;
         $header[] = "HM-Signature:".$hash_sign;
         $header[] = "HM-Timestamp:".$time;
         //$result = $this->cur_get($uri,$header);
         $result = $this->cur_request($uri,"GET","",$header);
         echo "<pre>";
         echo $uri."\n";
         print_r($result);
         exit;
     }

     /**
      * description: 获取账号listing 信息
      * @throws CException
      * url:/services/yunyi/Kauflandapi/getaccountlist
      */
     public function actionGetaccountlist()
     {
         $uri = $this->getUrl("account_listing");
         $time = time();
         $hash_sign = $this->signRequest("POST", $uri, "", $time , $this->secretKey);
         $header = $this->header;
         $header[] = "HM-Signature:".$hash_sign;
         $header[] = "HM-Timestamp:".$time;
         //$result = $this->cur_get($uri,$header);
         $result = $this->cur_request($uri,"POST","",$header);
         echo "<pre>";
         echo $uri."\n";
         print_r($result);
         exit;
     }

     /**
      * description: 获取单个商品信息
      * @throws CException
      * url:/services/yunyi/Kauflandapi/getproduct
      */
     public function actionGetproduct()
     {
         $ean = "9062609283155";
         $uri = $this->getUrl("update_product").$ean;
         $time = time();
         $hash_sign = $this->signRequest("GET", $uri, "", $time , $this->secretKey);
         $header = $this->header;
         $header[] = "HM-Signature:".$hash_sign;
         $header[] = "HM-Timestamp:".$time;
         //$result = $this->cur_get($uri,$header);

         $result = $this->cur_request($uri,"GET","",$header);
         echo "<pre>";
         echo $uri."\n";
         print_r($result);
         exit;
     }

     /**
      * description: 获取单个unit信息
      * @throws CException
      * url:/services/yunyi/Kauflandapi/getunitinfo
      */
     public function actionGetunitinfo()
     {
         $id_unit = "384536239807";
         $uri = $this->getUrl("get_units").$id_unit;
         $time = time();
         $hash_sign = $this->signRequest("GET", $uri, "", $time , $this->secretKey);
         $header = $this->header;
         $header[] = "HM-Signature:".$hash_sign;
         $header[] = "HM-Timestamp:".$time;
         //$result = $this->cur_get($uri,$header);
         $result = $this->cur_request($uri,"GET","",$header);
         echo "<pre>";
         echo $uri."\n";
         print_r($result);
         exit;
     }

     /**
      * description: 更新单个unit信息
      * @throws CException
      * url:/services/yunyi/Kauflandapi/updateunits
      */
     public function actionUpdateunits()
     {
         $id_unit = "384536239807";
         $uri = $this->getUrl("get_units").$id_unit;;
         $time = time();
         $body = [
             "condition"=>"new",
             "listing_price"=>6392,
             "minimum_price"=>6392,
             "amount"=> 200,
             "id_offer"=> "00001670-01",
             "note"=> "",
             "delivery_time"=> "e",
             "delivery_time_min"=> 4,
             "delivery_time_max"=> 20,
             "shipping_group"=> "jiekecang",
             "location"=> "CN",
             "warehouse"=> "Shenzhenshi runxi keji",
             "reference_price"=> 0
         ];
         //$uri = $uri."?id_unit=$id_unit";
         $body_jsonstr = json_encode($body);
         $hash_sign = $this->signRequest("PATCH", $uri, $body_jsonstr, $time , $this->secretKey);
         $header = $this->header;
         $header[] = "HM-Signature:".$hash_sign;
         $header[] = "HM-Timestamp:".$time;
         //$result = $this->cur_get($uri,$header);
         $result = $this->cur_request($uri,"PATCH",$body_jsonstr,$header);
         echo "<pre>";
         echo $uri."\n";
         print_r($header);
         print_r($result);
         exit;
     }

     /**
      * description: 获取unit listing信息
      * @throws CException
      * url:/services/yunyi/Kauflandapi/getunitlisting
      */
     public function actionGetunitlisting()
     {
         $uri = $this->getUrl("get_units_listing");
         $time = time();
         $body["id_offer"] = "3505-006140-09U0A";
         $body["id_item"] = 2147483647;
         $body["ean"] = "9072609509223";
         $body["limit"] = 300;
         $body["offset"] = 1;
         $body["embedded"] = "item";
         //$url=$uri."?limit=30&offset=0&id_offer=3505-006140-09U0A&ean=9072609509223";
         $url=$uri."?limit=30&offset=1";
         $hash_sign = $this->signRequest("GET", $url, "", $time , $this->secretKey);
         $header = $this->header;
         $header[] = "HM-Signature:".$hash_sign;
         $header[] = "HM-Timestamp:".$time;
         //$result = $this->cur_get($uri,$header);
         $result = $this->cur_request($url,"GET","",$header);
         echo "<pre>";
         echo $uri."\n";
         print_r($header);
         print_r($result);
         exit;
     }

     /**
      * description: 进行更新产品数据
      * @throws CException
      * url:/services/yunyi/Kauflandapi/updateproduct
      */
     public function actionUpdateproduct()
     {
         $ean = "";
         $uri = $this->getUrl("categories").$ean;
         $time = time();
         $params = [
             "ean"=>[""],
             "title"=>[""],
             "category"=>[""],
             "additional_categories"=>[""],
             "description"=>[""],
             "short_description"=>[""],
             "mpn"=>[""],
             "list_price"=>[""],
             "picture"=>[""],
             "additional_attributes"=>[["attribute"=>"","value"=>[""]]],
         ];
         echo json_encode($params);exit;
         $hash_sign = $this->signRequest("PATCH", $uri, $body, $time , $this->secretKey);
         $header = $this->header;
         $header[] = "HM-Signature:".$hash_sign;
         $header[] = "HM-Timestamp:".$time;
         //$result = $this->cur_get($uri,$header);
         $result = $this->cur_request($uri,"PATCH","",$header);
         echo "<pre>";
         print_r($result);
         exit;
     }

    // 请求方法的封装
     public function cur_request($URL,$type,$params,$headers){
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $URL);
         if($headers!=""){
             curl_setopt ($ch, CURLOPT_HTTPHEADER, $headers);
         }else {
             curl_setopt ($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
         }
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
         curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 30);
         switch ($type){
             case "GET" : curl_setopt($ch, CURLOPT_HTTPGET, true);break;
             case "POST": curl_setopt($ch, CURLOPT_POST,true);
                 curl_setopt($ch, CURLOPT_POSTFIELDS,$params);break;
             case "PUT" : curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, "PUT");
                 curl_setopt($ch, CURLOPT_POSTFIELDS,$params);break;
             case "PATCH": curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
                 curl_setopt($ch, CURLOPT_POSTFIELDS, $params);break;
             case "DELETE":curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
                 curl_setopt($ch, CURLOPT_POSTFIELDS,$params);break;
         }
         $file_contents = curl_exec($ch);//获得返回值
         $responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
         curl_close($ch);
         return [$responseCode,json_decode($file_contents,true)];
     }

     //POST 请求数据
     public function cur_post($url, $post_data, $header)
     {
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
         curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
         curl_setopt($ch, CURLOPT_POST, 1);
         if (!$post_data) {
             $post_data = "{}";
         }
         curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         $response = curl_exec($ch);
         if (curl_errno($ch)) {
             return array("ack" => 0, "result" => "ERROR:" . curl_error($ch));
         }
         curl_close($ch);
         return json_decode($response,true);
     }

     //GET 请求数据
     public function cur_get($url,$header)
     {
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
         curl_setopt($ch, CURLOPT_TIMEOUT, 30);
         curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
         curl_setopt($ch, CURLOPT_POST, 0);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         $response = curl_exec($ch);
         if (curl_errno($ch)) {
             return array("ack" => 0, "result" => "ERROR:" . curl_error($ch));
         }
         curl_close($ch);
         return json_decode($response,true);
     }
 }

 

标签:ch,平台,uri,header,api,time,kaufland,curl,CURLOPT
From: https://www.cnblogs.com/xiangshihua/p/17165316.html

相关文章

  • openApi 使用
    1、先登录获取token  2、调用标准的费用报销单接口  {"api":"cpbcOpenAPI_importBill","data":["4A44F49F",[{"overAmountDesc":"1111","bosType":"4A44F49F","is......
  • 使用 “apifm-wxapi” 快速开发小程序
    步骤一、安装apifm-wxapi1、npminit初始化项目先你需要检查一下你的小程序项目是否支持npm,判断标准很简单,你看一下你的小程序根目录下有没有“package.json”......
  • 助力企业数字化转型!低代码开发平台公司都有哪些产品?
    当前,自动化办公环境逐渐宽松和丰富。数据资源也成为很多企业非常看重的内部资源。毕竟,做好数据管理,可以链接企业各部门内部信息,也可以给企业高层做好发展决策创造基础条件......
  • scheduler API All In One
    schedulerAPIAllInOneschedulerAPI/专用的调度程序APIhttps://wicg.github.io/scheduling-apis/#dom-windoworworkerglobalscope-schedulerSchedulerAPI:......
  • 直播平台源代码,CSS 修改滚动条样式、信封边框样式
    直播平台源代码,CSS修改滚动条样式、信封边框样式CSS全局修改滚动条样式  ::-webkit-scrollbar{ /*滚动条整体样式*/ width:4px; /*高宽分别对应横竖滚动条......
  • ChatGPT API 简单使用
    关于ChatGPT和API获取我:请你做一个自我介绍ChatGPT:当然可以!您好,我是ChatGPT,是一款由OpenAI训练的大型语言模型。我可以回答各种各样的问题,包括但不限于自然语言......
  • dingo api passport
    配置阿里源composerconfig-grepo.packagistcomposerhttps://mirrors.aliyun.com/composer/创建项目composercreate-project--prefer-distlaravel/laravel=6.*......
  • 10. Laravel api 认证
    Laravelapi认证配套视频地址:https://www.bilibili.com/video/av74879198?p=3原理注册:用户注册成功后,随机生成长字符串作为token,原生token返回给用户。哈希后的......
  • 连接Windows 平台 KingbaseES异常
    概述应用连接Windows平台的KingbaseES数据库,报错“com.kingbase8.util.KSQLException:致命错误:用户"system"Password认证失败(kbjdbc:autodetectedserver-encoding......
  • 使用MetaWeblog api自动上传文章图片到cnblog
    由于我日常习惯用Typora来写笔记和博客,文章中的图片保存在本地,在发布文章到cnblog之前,希望能有一个自动化工具可以自动上传文章引用的图片到cnblog,获取图片链接,替换掉......