light / apistore
百度API商品免费接口封装
0.1.5
2016-01-07 13:59 UTC
Requires (Dev)
- phpunit/phpunit: ^4.0|^5.1
README
百度APIStore免费接口封装
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist light/apistore "*"
or add
"light/apistore": "*"
to the require section of your composer.json
file.
Usage
Once the extension is installed, simply use it in your code by :
$store = new light\apistore\ApiStore('your key');
$api = $store->phone;
$result = $api->get('15292312331');
if ($result['errcode'] == 0) {
var_dump($result['data']);
} else {
echo 'Get error: ', $result['errmsg'];
}
目前可用接口:
- 手机号码归属地查询
$store->phone
- 身份证查询
$store->idcard
- 翻译接口
$store->translate
- IP地址查询
$sotre->ip
- 汇率转换
$sotre->currency
- pullword在线分词服务
$sotre->pullword
- 测距
$sotre->distance
如何添加新接口
如果你发现需要的接口目前没有,可以发起pull request进行提交.
流程是在src/apis
建立新的接口调用类,新的接口需要继承自light\apistore\apis\Api
, 大概如下:
class Sms extends Api
{
private $address = 'http://apiurl';
public function get($params)
{
return $this->fetch($this->address . http_build_query($params));
}
}