刷新Eaby Token

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

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

ebay的api的开发技术笔记参考链接:https://blog.csdn.net/weixin_30855761/article/details/99252179

    /**
     * @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;
                }
            }
        }
    }

 

 
posted @ 2021-04-16 19:45  爱家家的卡卡  阅读(90)  评论(0编辑  收藏  举报