Skip to content

Commit

Permalink
添加微信开发配置接口
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuzf-code committed Nov 22, 2019
1 parent 5d77df0 commit edf371f
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 5 deletions.
64 changes: 64 additions & 0 deletions Src/AddWeChatConfig/AddWeChatConfigParams.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace TPay\AddWeChatConfig;


use TPay\BaseParams;

/**
* @property $appid
* @property $path
* @property $subscribeAppid
* Class AddWeChatConfigParams
* @package TPay\addWeChatConfig
*/
class AddWeChatConfigParams extends BaseParams
{
/**
* @return mixed
*/
public function getAppid()
{
return $this->data['appid'];
}

/**
* @param mixed $appid
*/
public function setAppid($appid): void
{
$this->data['appid'] = $appid;
}

/**
* @return mixed
*/
public function getPath()
{
return $this->data['path'];
}

/**
* @param mixed $path
*/
public function setPath($path): void
{
$this->data['path'] = $path;
}

/**
* @return mixed
*/
public function getSubscribeAppid()
{
return $this->data['subscribeAppid'];
}

/**
* @param mixed $subscribeAppid
*/
public function setSubscribeAppid($subscribeAppid): void
{
$this->data['subscribeAppid'] = $subscribeAppid;
}
}
11 changes: 11 additions & 0 deletions Src/AddWeChatConfig/AddWeChatConfigResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace TPay\AddWeChatConfig;


use TPay\BaseResponse;

class AddWeChatConfigResponse extends BaseResponse
{

}
19 changes: 18 additions & 1 deletion Src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
namespace TPay;


use TPay\AddWeChatConfig\AddWeChatConfigParams;
use TPay\AddWeChatConfig\AddWeChatConfigResponse;
use TPay\BarcodePay\BarcodePayParams;
use TPay\BarcodePay\BarcodePayResponse;
use TPay\PreCreate\PreCreateParams;
Expand Down Expand Up @@ -150,6 +152,22 @@ public function cancel(TradeCancelParams $params)
return $response;
}

/**
* 添加微信开发配置
* @param AddWeChatConfigParams $params
* @return AddWeChatConfigResponse
* @throws ParamsException
* @throws RequestException
*/
public function addWeChatConfig(AddWeChatConfigParams $params)
{
$response = new AddWeChatConfigResponse();

$this->request('open/merchant/addWeChatConfig', $params, $response);

return $response;
}

/**
* 发起请求
* @param $api
Expand All @@ -171,7 +189,6 @@ public function request($api, BaseParams $params, BaseResponse $response = null)
$rawData['sign'] = $this->generateSign($rawData);

$result = json_decode($this->curlPOST($this->domain . $api, $rawData), true);
var_dump($result);

// 转为response对象
if (!is_null($response)) {
Expand Down
43 changes: 42 additions & 1 deletion Src/TPayManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
namespace TPay;


use TPay\AddWeChatConfig\AddWeChatConfigParams;
use TPay\BarcodePay\BarcodePayParams;
use TPay\PreCreate\PreCreateParams;
use TPay\Refund\RefundParams;
use TPay\RefundQuery\RefundQueryParams;
use TPay\TradeCancel\TradeCancelParams;
use TPay\TradeCreate\TradeCreateParams;
use TPay\TradeCreate\TradeCreateResponse;
use TPay\TradeQuery\TradeQueryParams;

class TPayManager
Expand Down Expand Up @@ -163,7 +165,7 @@ public static function newTradeCreateParams($payType, $outTradeNo, $amount, $sub
* @param $body
* @param $buyerId
* @param string $notifyURL
* @return PreCreate\TradeCreateResponse
* @return TradeCreateResponse
* @throws ParamsException
* @throws RequestException
*/
Expand Down Expand Up @@ -323,4 +325,43 @@ public static function cancel(Client $client, $payType, $outTradeNo = '', $chann

return $client->cancel($params);
}

/**
* 获取新的添加微信开发配置参数对象
* @param string $appid
* @param string $path
* @param string $subscribeAppid
* @return AddWeChatConfigParams
* @throws ParamsException
*/
public static function newAddWeChatConfigParams($appid = '', $path = '', $subscribeAppid = '')
{
$params = new AddWeChatConfigParams();
$params->setSubscribeAppid($subscribeAppid);
$params->setAppid($appid);
$params->setPath($path);

if (empty($params->getData())) {
throw new ParamsException('appid,path,subscribeAppid 不能同时为空');
}

return $params;
}

/**
* 添加微信开发配置
* @param Client $client
* @param string $appid
* @param string $path
* @param string $subscribeAppid
* @return AddWeChatConfig\AddWeChatConfigResponse
* @throws ParamsException
* @throws RequestException
*/
public static function addWeChatConfig(Client $client, $appid = '', $path = '', $subscribeAppid = '')
{
$params = self::newAddWeChatConfigParams($appid, $path, $subscribeAppid);

return $client->addWeChatConfig($params);
}
}
6 changes: 3 additions & 3 deletions test.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@


// 通过helper直接发起请求
/*$response = TPayManager::barcodePay($client, 1, 'FZY2019112101', 0.01, 'authcode',
/*$response = TPayManager::barcodePay($client, 1, 'FZY2019112204', 0.03, 'xxxxxxxxxxxxxxx',
'测试订单', '测试订单');*/

//$response = TPayManager::preCreate($client, 1, 'FZY2019112201', 0.01, '测试订单', '测试订单');
Expand All @@ -35,9 +35,9 @@

//$response = TPayManager::cancel($client, 1, 'FZY2019112202');

//$response = TPayManager::refund($client, 1, 0.01, 0.01, 'FZY2019112201', 'FZY2019112201');
$response = TPayManager::refund($client, 1, 0.01, 0.03, 'FZY201911220403', 'FZY2019112204');

$response = TPayManager::refundQuery($client, 1, 'FZY2019112201', 'FZY2019112201');
//$response = TPayManager::refundQuery($client, 1, 'FZY2019112201', 'FZY2019112201');

echo PHP_EOL;
echo $response;
Expand Down

0 comments on commit edf371f

Please sign in to comment.