PHP code example of cblink-service / foundation

1. Go to this page and download the library: Download cblink-service/foundation 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/ */

    

cblink-service / foundation example snippets



// 继承基类
class App extends \Cblink\Service\Foundation\Container {
    protected array $providers = [
        // 自定义服务提供者
        \Cblink\Service\Foundation\Providers\AccessTokenServiceProvider::class,
    ];
}

$app = new App([
    // 接口的基础请求地址
    'base_url' => '',
    // 使用 guzzle 时所需要的默认配置
    'guzzle' => [
        'timeout' => 5.0,
        'verify' => false,
    ],
])

# 在Api类中获取配置
class Api extends \Cblink\Service\Foundation\BaseRequestApi {

    public function getOrderLists()
    {
        // 所有的接口请求,默认为json格式返回,返回值将会转换成数组返回
       /* @var array $response */
       $response = $this->httpGet('/url', ['query' => []]); 
       
       // post请求
       $response = $this->httpPost('/url', ['data']); 
       
       // put 请求
       $this->httpPut();
       
       // delete 请求
       $this->httpDelete('/url', ['query']) 
    }
    
    
    // 可以再Api中声明名为 getBaseUrl 的方法,此方法声明后将会覆盖 config 中的 base_url
    public function getBaseUrl()
    {
        return 'http://www.cblink.net';
    }
}