Skip to content

Commit

Permalink
完善注释
Browse files Browse the repository at this point in the history
  • Loading branch information
klgd committed Mar 16, 2017
1 parent 6e0b934 commit eba3293
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 23 deletions.
4 changes: 0 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# Changelog

All Notable changes to `bankcard` will be documented in this file.

Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles.

## NEXT - YYYY-MM-DD

### Added
Expand Down
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
[![Quality Score][ico-code-quality]][link-code-quality]
[![Total Downloads][ico-downloads]][link-downloads]

根据银行卡号识别所属银行以及卡类型
根据银行卡号识别所属银行以及卡类型
目前支持两种识别方式:阿里API和正则,默认使用阿里的API


## 安装
Expand All @@ -23,9 +24,13 @@ $ composer require scolib/bankcard

``` php
$bankcard = new Sco\Bankcard\Bankcard();
//$bankcard = new Sco\Bankcard\Bankcard(new Sco\Bankcard\Providers\RegexProvider());

// 返回一个Sco\Bankcard\Info实例
// 如果未识别 抛出异常 Sco\Bankcard\Exceptions\ValidationException
$info = $bankcard->info($cardNo);

// 所有银行卡信息
// 银行卡信息(数组)
$info->getBankInfo();

// 所属银行代号
Expand All @@ -34,7 +39,7 @@ $info->getBankCode();
// 所属银行名称
$info->getBankName();

// 所属银行icon(如果有值
// 所属银行icon(如果有
$info->getBankIcon();

// 卡类型代号
Expand All @@ -46,7 +51,7 @@ $info->getCardTypeName();

## Change log

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
[更新日志](CHANGELOG.md)

## Testing

Expand Down
3 changes: 3 additions & 0 deletions src/Bankcard.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Sco\Bankcard\Contracts\Provider as ProviderContract;
use Sco\Bankcard\Providers\AlipayProvider;

/**
* @method Contracts\Info info(string $cardNo)
*/
class Bankcard implements FactoryContract
{
/**
Expand Down
35 changes: 33 additions & 2 deletions src/Contracts/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,46 @@

interface Info
{
/**
* 银行卡信息
*
* @return array
*/
public function getBankInfo();

/**
* 所属银行代号
*
* @return string
*/
public function getBankCode();

/**
* 所属银行名称
*
* @return string
*/
public function getBankName();

/**
* 所属银行icon(如果有)
* 一般是一个图片url
*
* @return string
*/
public function getBankIcon();

public function getBankInfo();

/**
* 卡类型代号
*
* @return string
*/
public function getCardType();

/**
* 卡类型名称
*
* @return string
*/
public function getCardTypeName();
}
10 changes: 5 additions & 5 deletions src/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public function __construct(array $attributes)
$this->attributes = $attributes;
}

public function getBankInfo()
{
return $this->getAttributes();
}

public function getBankCode()
{
return $this->getAttribute('bankCode');
Expand All @@ -30,11 +35,6 @@ public function getBankIcon()
return $this->getAttribute('bankIcon');
}

public function getBankInfo()
{
return $this->getAttributes();
}

public function getCardType()
{
return $this->getAttribute('cardType');
Expand Down
11 changes: 8 additions & 3 deletions src/Providers/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@

abstract class AbstractProvider implements ProviderContract
{
protected $cardTypes = [];

protected $bankLists = [];

/**
* 通过卡号获取银行卡信息.
Expand All @@ -29,6 +26,9 @@ abstract protected function getBankInfoByCardNo($cardNo);
*/
abstract protected function mapInfoToObject(array $bankInfo);

/**
* @inheritdoc
*/
public function info($cardNo = null)
{
if (empty($cardNo) || !is_numeric($cardNo)) {
Expand All @@ -42,6 +42,11 @@ public function info($cardNo = null)
return $info;
}

protected function getBankIcon($bankCode)
{
return '';
}

/**
* Return array item by key.
*
Expand Down
6 changes: 6 additions & 0 deletions src/Providers/AlipayProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

class AlipayProvider extends AbstractProvider
{
/**
* @inheritdoc
*/
protected function getBankInfoByCardNo($cardNo)
{
$url = "https://ccdcapi.alipay.com/validateAndCacheCardInfo.json"
Expand All @@ -28,6 +31,9 @@ protected function getBankInfoByCardNo($cardNo)
return $bankInfo;
}

/**
* @inheritdoc
*/
protected function mapInfoToObject(array $bankInfo)
{
$bankCode = $this->arrayItem($bankInfo, 'bank');
Expand Down
11 changes: 6 additions & 5 deletions src/Providers/RegexProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -1888,6 +1888,9 @@ class RegexProvider extends AbstractProvider
],
];

/**
* @inheritdoc
*/
protected function getBankInfoByCardNo($cardNo)
{
foreach ($this->patterns as $val) {
Expand All @@ -1904,6 +1907,9 @@ protected function getBankInfoByCardNo($cardNo)
throw new ValidationException();
}

/**
* @inheritdoc
*/
protected function mapInfoToObject(array $bankInfo)
{
return new Info([
Expand All @@ -1914,9 +1920,4 @@ protected function mapInfoToObject(array $bankInfo)
'cardTypeName' => CardType::get($bankInfo['cardType']),
]);
}

protected function getBankIcon($bankCode)
{
return '';
}
}

0 comments on commit eba3293

Please sign in to comment.