juffalow/finstatclient

1.0.1 2017-01-11 21:26 UTC

This package is not auto-updated.

Last update: 2024-09-23 06:33:35 UTC


README

Packagist Packagist

FinStat 服务提供的 API 客户端。

技术

此解决方案使用 CURL。但如果你必须使用其他方式来进行 HTTP POST 操作,也没有问题

<?php

require __DIR__ . '/vendor/autoload.php';

class NonCurlApiCall extends \juffalow\finstatclient\CurlApiCall {
    protected function httpPost($url, $params) {
        $options = array(
            'http' => array(
                'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
                'method'  => 'POST',
                'content' => http_build_query($params)
            )
        );
        $context  = stream_context_create($options);
        $result = file_get_contents($url, false, $context);
        if($result === false) {
            throw \Exception('Error!');
        }
        return $result;
    }
}

$client = new juffalow\finstatclient\Client('<your API key>', '<your private key>', null, null, new NonCurlApiCall());

示例

这是请求公司详细信息的基本示例。

<?php

require __DIR__ . '/vendor/autoload.php';

$client = new juffalow\finstatclient\Client('<your api key>', '<your private key>');

try {
    $detail = $client->getCompanyDetail('35757442');
} catch(\Exception $e) {
    print_r($e);
}

你可以在 示例页面 中看到更多。