Completed
Push — master ( 9a89be...b03325 )
by light
38:59
created

IdCard::_parseResponse()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
rs 9.2
cc 4
eloc 10
nc 3
nop 1
1
<?php
2
3
/*
4
 * This file is part of the light/yii2-apistore.
5
 *
6
 * (c) lichunqiang <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace light\apistore\apis;
13
14
/**
15
 * 身份证查询.
16
 *
17
 * @see http://apistore.baidu.com/apiworks/servicedetail/113.html
18
 */
19
class IdCard extends Api
20
{
21
    private $address = 'http://apis.baidu.com/apistore/idservice/id?';
22
23
    /**
24
     * 获取身份证信息.
25
     *
26
     * @param string $id 身份证号
27
     *
28
     * @return array
29
     */
30
    public function get($id)
31
    {
32
        return $this->fetch($this->address . http_build_query(compact('id')));
33
    }
34
35
    /**
36
     * @inheritdoc
37
     */
38
    protected function _parseResponse($result)
39
    {
40
        $result = json_decode($result, true);
41
        // @codeCoverageIgnoreStart
42
        if (!$result || !isset($result['errNum'])) {
43
            return ['errcode' => 1, 'errmsg' => 'fetch data error'];
44
        }
45
        // @codeCoverageIgnoreEnd
46
        if ($result['errNum'] == 0) {
47
            return [
48
                'errcode' => 0,
49
                'errmsg' => 'success',
50
                'data' => $result['retData'],
51
            ];
52
        }
53
54
        return ['errcode' => $result['errNum'], 'errmsg' => $result['retMsg']];
55
    }
56
}
57