francis-schiavo / blizzard_api
Blizzard网络API的PHP客户端
v0.2.0
2023-04-16 06:54 UTC
Requires
- ext-curl: *
- ext-mbstring: *
- ext-redis: *
Requires (Dev)
- phpunit/phpunit: ^9.6.7
This package is auto-updated.
Last update: 2024-09-16 10:08:42 UTC
README
此库是Blizzard API的接口。
有关更多信息,请参阅https://develop.battle.net/。
安装
此库需要PHP 8.1或更高版本,并以下模块:
- mbstring
- curl
- redis(仅当使用Redis缓存接口时)
您可以通过在compose.json
中将francis-schiavo/blizzard_api
作为需求添加到您的项目来添加此库。
或者从命令行
php composer.phar require francis-schiavo/blizzard_api
配置
您必须使用有效的凭据对包进行配置。您可以从这里获得它们: https://develop.battle.net/access/clients
以下代码示例展示了如何配置库。
<?php use BlizzardApi\Enumerators\Region; BlizzardApi\Configuration::$apiKey = '<YOUR APPLICATION ID>'; BlizzardApi\Configuration::$apiSecret = '<YOUR APPLICATION SECRET>'; BlizzardApi\Configuration::$region = Region::US;
基本用法
这是获取所有可用的魔兽世界可玩种族列表的方法
$api_client = new \BlizzardApi\Wow\GameData\PlayableRace(); $data = $api_client->index(); echo(print_r($data));
您可以将RedisCache实例传递以使用Redis在本地缓存API请求
# PHP Redis module $redis = new Redis(); $redis->connect('127.0.0.1', 6379); $redis->select(8); # BlizzardApi\Cache use BlizzardApi\Cache\RedisCache; $cache = new RedisCache($redis); # Pass the constructor `cache` parameter. $api_client = new \BlizzardApi\Wow\GameData\PlayableRace(cache: $cache); $data = $api_client->index();
高级搜索界面
对于某些魔兽世界端点,有一个可用的search
方法,您可以轻松地像下面这样构建一个有效的查询
# Pass the constructor `cache` parameter. $api_client = new \BlizzardApi\Wow\GameData\Item(cache: $cache); $data = $api_client->search(function($queryOptions) { $searchOptions->where('name.en_US', 'Booterang')->order_by('id'); });