PHP code example of maxsky / qq-openapi

1. Go to this page and download the library: Download maxsky/qq-openapi 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/ */

    

maxsky / qq-openapi example snippets


// Server Name 默认为正式,测试时使用 https://openapi.sparta.html5.qq.com
$openApi = (new OpenAPIv3('AppID', 'AppKey'))->setServerName('https://openapi.tencentyun.com');

// 请求的接口路由地址一定是左斜杠 '/' 开头
$route = '/v3/user/get_info';

try {
    $result = $openApi->api($route, 'POST', $params);
} catch (Throwable $e) {
    print_r('Error Message: ' . $e->getMessage());
    print_r('Error Code: ' . $e->getCode());

    if ($e instanceof ClientException) {
        print_r($e->getResponse());
    } elseif ($e instanceof BadResponseException) {
        print_r(json_decode($e->getResponse()->getBody(), true));
    }

    die;
}

/** @var string $result */
print_r($result);

$result = $openApi->api('/route/path', 'POST', [
    'param1' => 'value1',
    'param2' => 'value2'
], [
    'Accept' => 'application/json',
    'Content-Type' => 'application/x-www-form-urlencoded'
]);