Skip to content

Commit

Permalink
补全通用卡接口 (#575)
Browse files Browse the repository at this point in the history
* 补全通用卡接口

* codacy fix

* styleci fix

* StyleCI fix

* fix testcase
  • Loading branch information
xleliu authored and overtrue committed Jan 19, 2017
1 parent 6c9646e commit 7063079
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
28 changes: 23 additions & 5 deletions src/Card/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,17 @@ class Card extends AbstractAPI
const API_UPDATE_CODE = 'https://api.weixin.qq.com/card/code/update';
const API_DELETE_CARD = 'https://api.weixin.qq.com/card/delete';
const API_DISABLE_CARD = 'https://api.weixin.qq.com/card/code/unavailable';
const API_ACTIVATE_CARD = 'https://api.weixin.qq.com/card/membercard/activate';
const API_ACTIVATE_USER_FORM = 'https://api.weixin.qq.com/card/membercard/activateuserform/set';
const API_ACTIVATE_MEMBER_CARD = 'https://api.weixin.qq.com/card/membercard/activate';
const API_ACTIVATE_MEMBER_USER_FORM = 'https://api.weixin.qq.com/card/membercard/activateuserform/set';
const API_GET_MEMBER_USER_INFO = 'https://api.weixin.qq.com/card/membercard/userinfo/get';
const API_UPDATE_MEMBER_CARD_USER = 'https://api.weixin.qq.com/card/membercard/updateuser';
const API_CREATE_SUB_MERCHANT = 'https://api.weixin.qq.com/card/submerchant/submit';
const API_UPDATE_SUB_MERCHANT = 'https://api.weixin.qq.com/card/submerchant/update';
const API_GET_SUB_MERCHANT = 'https://api.weixin.qq.com/card/submerchant/get';
const API_LIST_SUB_MERCHANT = 'https://api.weixin.qq.com/card/submerchant/batchget';
const API_GET_CATEGORIES = 'https://api.weixin.qq.com/card/getapplyprotocol';
const API_ACTIVATE_GENERAL_CARD = 'https://api.weixin.qq.com/card/generalcard/activate';
const API_UPDATE_GENERAL_CARD_USER = 'https://api.weixin.qq.com/card/generalcard/updateuser';

/**
* 获取卡券颜色.
Expand Down Expand Up @@ -633,9 +635,13 @@ public function disable($code, $cardId = '')
*
* @return \EasyWeChat\Support\Collection
*/
public function activate($info = [])
public function activate($info = [], $cardType = 'member_card')
{
return $this->parseJSON('json', [self::API_ACTIVATE_CARD, $info]);
if ($cardType === 'general_card') {
return $this->parseJSON('json', [self::API_ACTIVATE_GENERAL_CARD, $info]);
}

return $this->parseJSON('json', [self::API_ACTIVATE_MEMBER_CARD, $info]);
}

/**
Expand All @@ -651,7 +657,7 @@ public function activateUserForm($cardId, array $requiredForm = [], array $optio
{
$params = array_merge(['card_id' => $cardId], $requiredForm, $optionalForm);

return $this->parseJSON('json', [self::API_ACTIVATE_USER_FORM, $params]);
return $this->parseJSON('json', [self::API_ACTIVATE_MEMBER_USER_FORM, $params]);
}

/**
Expand Down Expand Up @@ -684,6 +690,18 @@ public function updateMemberCardUser(array $params = [])
return $this->parseJSON('json', [self::API_UPDATE_MEMBER_CARD_USER, $params]);
}

/**
* 更新通用员信息.
*
* @param array $params
*
* @return \EasyWeChat\Support\Collection
*/
public function updateGeneralCardUser(array $params = [])
{
return $this->parseJSON('json', [self::API_UPDATE_GENERAL_CARD_USER, $params]);
}

/**
* 添加子商户.
*
Expand Down
4 changes: 2 additions & 2 deletions tests/Card/CardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ public function testActivate()
];

$result = $card->activate($activate);
$this->assertStringStartsWith(Card::API_ACTIVATE_CARD, $result['api']);
$this->assertStringStartsWith(Card::API_ACTIVATE_MEMBER_CARD, $result['api']);
$this->assertEquals($activate, $result['params']);
}

Expand Down Expand Up @@ -575,7 +575,7 @@ public function testActivateUserForm()
];

$result = $card->activateUserForm($cardId, $requiredForm, $optionalForm);
$this->assertStringStartsWith(Card::API_ACTIVATE_USER_FORM, $result['api']);
$this->assertStringStartsWith(Card::API_ACTIVATE_MEMBER_USER_FORM, $result['api']);
$this->assertEquals($cardId, $result['params']['card_id']);
}

Expand Down

0 comments on commit 7063079

Please sign in to comment.