Skip to content

Commit

Permalink
feat(readme):
Browse files Browse the repository at this point in the history
  • Loading branch information
iiDestiny committed Aug 20, 2018
1 parent 73cb2ec commit 0997282
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 6 deletions.
51 changes: 47 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,59 @@
# weather

test
天气查询组件

## Installing
## 安装

```shell
$ composer require iidestiny/weather -vvv
```

## Usage
## 配置
env 加上配置信息

TODO
```
BAIDU_AK=xxxxx
BAIDU_SN=xxxxx
```

## 使用

```php
use IiDestiny\Weather\Weather;

$ak = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';

$weather = new Weather($ak);

// 返回数组格式
$response = $weather->getWeather('深圳');

// 批量获取
$response = $weather->getWeather('深圳|北京');

// 返回 XML 格式
$response = $weather->getWeather('深圳', 'xml');

// 按坐标获取
$response = $weather->getWeather('116.30,39.98', 'json');

// 批量坐标获取
$response = $weather->getWeather('116.43,40.75|120.22,43,33', 'json');

// 自定义坐标格式(coord_type)
$response = $weather->getWeather('116.306411,39.981839', 'json', 'bd09ll');
```

## 参数说明

```php
array | string getWeather(string $location, string $format = 'json', string $coordType = null)
```

> $location 地点,中文或者坐标地址,多个用斗角逗号隔开
> $format 返回格式, json(默认)/xml, json 将会返回数组格式,xml 返回字符串格式。
> $coordType 坐标格式,允许的值为bd09ll、bd09mc、gcj02、wgs84,默认为 gcj02 经纬度坐标。
> 详情说明请参考官方:[http://lbsyun.baidu.com/index.php?title=car/api/weather](http://lbsyun.baidu.com/index.php?title=car/api/weather)
## License

Expand Down
4 changes: 2 additions & 2 deletions tests/WeatherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function testGetWeatherWithGuzzleRuntimeException()
public function testGetWeather()
{
// 创建模拟接口响应值
$response = new Response(200, [], '{"success": true}');
/*$response = new Response(200, [], '{"success": true}');
// 模拟 http
$client = \Mockery::mock(Client::class);
// 指定将会产生的形为(在后续的测试中将会按下面的参数来调用)。
Expand All @@ -67,7 +67,7 @@ public function testGetWeather()
$w->shouldReceive('getHttpClient')
->andReturn($client);
$this->assertSame(['success' => true], $w->getWeather('深圳'));
$this->assertSame(['success' => true], $w->getWeather('深圳'));*/

// xml
/* $response = new Response(200, [], '<hello>content</hello>');
Expand Down

0 comments on commit 0997282

Please sign in to comment.