惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Jina AI
Jina AI
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
B
Blog
T
The Blog of Author Tim Ferriss
量子位
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - Franky
小众软件
小众软件
Recent Announcements
Recent Announcements
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
I
InfoQ
美团技术团队
G
Google Developers Blog
Engineering at Meta
Engineering at Meta
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
V
Visual Studio Blog
云风的 BLOG
云风的 BLOG
博客园 - 【当耐特】
IT之家
IT之家
Microsoft Security Blog
Microsoft Security Blog
博客园 - 聂微东
Last Week in AI
Last Week in AI
H
Hackread – Cybersecurity News, Data Breaches, AI and More
H
Help Net Security

博客园 - 天心PHP

去除文件夹下面所有xlsx的样式脚本 php 上传视频到阿里云OSS (不用SDK) 升级版本 断点续传 php 上传视频到阿里云OSS (不用SDK) SHEIN 开放平台授权 mercadolibre 美卡多 拉取listing Amazon SP API批量更新价格 JSON_LISTINGS_FEED Ozon API接口 Wildberries API接口 沃尔玛拉取listing和库存 沃尔玛修改促销价格 Amazon SP API 拉取产品详情和修改产品属性 Amazon SP API拉取分类,五点,描述和关键字 Amazon SP API拉取日期范围报告和分类树 PHP 提取PDF文件内容 常用sql(1.分组取最新的 N 条数据; 2.删除重复数据 ) kaufland平台api mercadolibre 美卡多 本土授权(PKCE) go mod Amazon SP API拉取listing 和 批量调价
Allegro API接口
天心PHP · 2025-04-23 · via 博客园 - 天心PHP
<?php
class AllegroModel extends YbModel {

    protected $access_token = null;
    protected $client_id = null;
    protected $client_secret = null;
    protected $host_url = null;
    /**
     * db config key
     *
     * @return string
     */
    public function getDbKey() {
        return 'db';
    }

    public function __construct($account){
        $this->host_url = 'https://api.allegro.pl/';
        $this->access_token = $account['access_token'];
        $this->client_id = $account['client_id'];
        $this->client_secret = $account['client_secret'];
    }

    public function get_customer_returns($data)
    {
        foreach ($data as $key=>$val){
            $url.=$key.'='.$val.'&';
        }
        $params = rtrim($url,"&");
        $url = $this->host_url.'order/customer-returns';
        if($params){
            $url = $url.'?'.$params;
        }
        $headers[] = "Accept: application/vnd.allegro.beta.v1+json";
        $headers[] = "Authorization: Bearer " . $this->access_token;
        $headers[] = "Content-Type: application/vnd.allegro.beta.v1+json";
        $res = $this->cur_request($url, 'GET', '', $headers);
        return $res;
    }

    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/x-www-form-urlencoded'));
        }
        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)];
    }
}