PHP code example of sabao / eleme-openapi-sdk

1. Go to this page and download the library: Download sabao/eleme-openapi-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sabao / eleme-openapi-sdk example snippets




use Sabao\Eleme\Api\ShopService;
use Sabao\Eleme\Config\Config;

// 实例化一个配置类
$config = new Config($app_key, $app_secret, false);

// 使用 config 和 token 对象,实例化一个服务对象
// $token 为授权接口返回的对象,包含 access_token 属性
$shop_service = new ShopService($token, $config);

// 调用服务方法,获取资源
$shop = $shop_service->get_shop('12345');



use Sabao\Eleme\Config\Config;
use Sabao\Eleme\OAuth\OAuthClient;

$config = new Config($app_key, $app_secret, false);
$client = new OAuthClient($config);

// 根据 OAuth2.0 中的 state、scope 和 callback_url,获取授权 URL
$auth_url = $client->get_auth_url($state, $scope, $callback_url);

// 通过授权得到的 code,以及正确的 callback_url,获取 token
$token = $client->get_token_by_code($code, $callback_url);



use Sabao\Eleme\Config\Config;
use Sabao\Eleme\OAuth\OAuthClient;

$config = new Config($app_key, $app_secret, false);
$client = new OAuthClient($config);

// 使用授权类获取 token
$token = $client->get_token_in_client_credentials();