ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

刷新Eaby Token

2021-04-16 20:02:01  阅读:213  来源: 互联网

标签:Eaby ebay Token api 刷新 oauth scope com store


Ebay开发者社区  (https://www.ebay.cn/newcms/d_devdocs_apis/4)

Ebay所有API文档:https://developer.ebay.com/docs#Acc

ebay的api的开发技术笔记参考链接:https://blog.csdn.net/nittystone/article/details/38688535?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-0&spm=1001.2101.3001.4242

    /**
     * @title 刷新Eaby Token
     * @author 卡卡
     */
    public function refresh_eaby_tokentime()
    {
        $store = Db::name('store');
        $where['status'] = 1;
        $list = $store->where($where)->field('refresh_token,seller_id,seller_secret,store_id,access_token')->select();
        foreach ($list as $key => $value) {
            $refresh_token = urlencode($value['refresh_token']);
            $clientId = $value['seller_id'];
            $clientSecret = $value['seller_secret'];
            $scope = 'https://api.ebay.com/oauth/api_scope%20https://api.ebay.com/oauth/api_scope/sell.marketing.readonly%20https://api.ebay.com/oauth/api_scope/sell.marketing%20https://api.ebay.com/oauth/api_scope/sell.inventory.readonly%20https://api.ebay.com/oauth/api_scope/sell.inventory%20https://api.ebay.com/oauth/api_scope/sell.account.readonly%20https://api.ebay.com/oauth/api_scope/sell.account%20https://api.ebay.com/oauth/api_scope/sell.fulfillment.readonly%20https://api.ebay.com/oauth/api_scope/sell.fulfillment%20https://api.ebay.com/oauth/api_scope/sell.analytics.readonly%20https://api.ebay.com/oauth/api_scope/sell.finances%20https://api.ebay.com/oauth/api_scope/sell.payment.dispute';

            # 正式
            $url = sprintf("https://api.ebay.com/identity/v1/oauth2/token?grant_type=refresh_token&refresh_token=%s&scope=%s", $refresh_token, $scope);
            $context = stream_context_create(array(
                'http' => array(
                    'method' => 'POST',
                    'ignore_errors' => true,
                    'header' => sprintf("Authorization: Basic %s\r\n", base64_encode($clientId . ':' . $clientSecret)) . "Content-type: application/x-www-form-urlencoded\r\n",
                ),
            ));

            //发送请求
            $response = file_get_contents($url, TRUE, $context);
            $response = json_decode($response);
            $response = object_array($response);
            if (isset($response['error'])) {
                print_r($response);
                echo PHP_EOL;
                print_r('failed的store_id为:' . $value['store_id']);
                echo PHP_EOL;
            } else {
                $save['expires_in'] = time();
                $save['update_time'] = time();
                $save['access_token'] = $response['access_token'];
                $save_where['store_id'] =  $value['store_id'];
                $res = $store->where($save_where)->update($save);
                if ($res) {
                    print_r('success的store_id为:' . $value['store_id']);
                    echo PHP_EOL;
                } else {
                    print_r('failed的store_id为:' . $value['store_id']);
                    echo PHP_EOL;
                }
            }
        }
    }

 

标签:Eaby,ebay,Token,api,刷新,oauth,scope,com,store
来源: https://www.cnblogs.com/kaka0318/p/14668533.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有