Skip to content

Commit

Permalink
🐛 修复参数传递问题,fixed #26
Browse files Browse the repository at this point in the history
  • Loading branch information
Abbotton committed Oct 12, 2021
1 parent ccbc47d commit 7cfe506
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 104 deletions.
40 changes: 0 additions & 40 deletions aop/AlipayAccessorTrait.php

This file was deleted.

15 changes: 0 additions & 15 deletions aop/AlipayHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,4 @@ public static function isEmpty($value)
{
return $value === null || trim($value) === '';
}

/**
* 转换字符串为变种驼峰命名(例如:FooBar).
*
* @param $str
* @param string $delimiters
*
* @return array|string|string[]
*/
public static function studlyCase($str, $delimiters = ' ')
{
return version_compare(PHP_VERSION, '5.6', '<')
? str_replace(' ', '', ucwords(str_replace($delimiters, ' ', $str)))
: str_replace($delimiters, '', ucwords($str, $delimiters));
}
}
10 changes: 2 additions & 8 deletions aop/AlipayRequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,8 @@ public static function create($apiName, $config = [])
*/
private function createByApi($apiName, $config = [])
{
$config = array_merge($config, ['api_method_name' => $apiName]);
$request = new AlipayRequest();
$config = array_merge($config, ['method' => $apiName]);

foreach ($config as $key => $value) {
$property = AlipayHelper::studlyCase($key, '_');
$request->$property = $value;
}

return $request;
return new AlipayRequest($config);
}
}
54 changes: 31 additions & 23 deletions aop/AopClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ public static function decrypt($encryptedData, $encodedKey, $cipher = 'aes-128-c
}

/**
* 一键执行请求
*
* @param AlipayRequest $request
* 一键执行请求.
*
* @param AlipayRequest $request
* @return AlipayResponse
*
* @see self::build()
* @see self::request()
* @throws AlipayBase64Exception
* @throws AlipayInvalidSignException
* @throws AlipayOpenSslException
* @throws Exception\AlipayInvalidResponseException
*/
public function execute(AlipayRequest $request)
{
Expand Down Expand Up @@ -164,14 +164,15 @@ public function build(AlipayRequest $request)
$sysParams['auth_token'] = $request->getAuthToken();
$sysParams['app_auth_token'] = $request->getAppAuthToken();
$sysParams['biz_content'] = $request->getBizContent();
$sysParams = array_merge($sysParams, get_object_vars($request));
// 转换可能是数组的参数
if ($request->arrayAsJson) {
foreach ($sysParams as &$param) {
if (is_array($param) || is_object($param)) {
$param = json_encode($param, JSON_UNESCAPED_UNICODE);
}
foreach ($sysParams as $key => &$param) {
if (is_array($param) || is_object($param)) {
$param = json_encode($param, JSON_UNESCAPED_UNICODE);
}
if (is_null($param)) {
unset($sysParams[$key]);
}
unset($param);
}

// 签名
Expand All @@ -186,9 +187,12 @@ public function build(AlipayRequest $request)
/**
* 发起请求、解析响应、验证签名.
*
* @param array $params
*
* @param $params
* @return AlipayResponse
* @throws AlipayBase64Exception
* @throws AlipayInvalidSignException
* @throws AlipayOpenSslException
* @throws Exception\AlipayInvalidResponseException
*/
public function request($params)
{
Expand All @@ -206,11 +210,12 @@ public function request($params)
}

/**
* 仅拼接请求参数并签名,但不发起请求
*
* @param AlipayRequest $request
* 仅拼接请求参数并签名,但不发起请求.
*
* @param AlipayRequest $request
* @return string
* @throws AlipayBase64Exception
* @throws AlipayOpenSslException
*/
public function sdkExecute(AlipayRequest $request)
{
Expand All @@ -222,9 +227,10 @@ public function sdkExecute(AlipayRequest $request)
/**
* 仅拼接请求参数并签名,生成跳转 URL.
*
* @param AlipayRequest $request
*
* @param AlipayRequest $request
* @return string
* @throws AlipayBase64Exception
* @throws AlipayOpenSslException
*/
public function pageExecuteUrl(AlipayRequest $request)
{
Expand All @@ -237,9 +243,10 @@ public function pageExecuteUrl(AlipayRequest $request)
/**
* 仅拼接请求参数并签名,生成表单 HTML.
*
* @param AlipayRequest $request
*
* @param AlipayRequest $request
* @return string
* @throws AlipayBase64Exception
* @throws AlipayOpenSslException
*/
public function pageExecuteForm(AlipayRequest $request)
{
Expand All @@ -262,9 +269,10 @@ public function pageExecuteForm(AlipayRequest $request)
/**
* 验证由支付宝服务器发来的回调通知请求,其签名数据是否未被篡改.
*
* @param array|null $params 请求参数(默认使用 $_POST)
*
* @param null $params
* @return bool
* @throws AlipayBase64Exception
* @throws AlipayOpenSslException
*/
public function verify($params = null)
{
Expand Down
12 changes: 1 addition & 11 deletions aop/Request/AlipayRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,11 @@

namespace Alipay\Request;

use Alipay\AlipayAccessorTrait;
use ReflectionClass;
use ReflectionException;

class AlipayRequest
{
use AlipayAccessorTrait;

/**
* 构建请求字符串时,是否将参数内的数组编码为 JSON.
*
* @var bool
*/
public $arrayAsJson = true;

protected $notifyUrl;

protected $returnUrl;
Expand All @@ -38,7 +28,7 @@ class AlipayRequest
public function __construct($config = [])
{
foreach ($config as $key => $value) {
$this->$key = $value;
$this->{$key} = $value;
}
}

Expand Down
7 changes: 0 additions & 7 deletions tests/default/HelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,4 @@ public function testIsEmpty()
$res = AlipayHelper::isEmpty($str);
$this->assertFalse($res);
}

public function testStudlyCase()
{
$str = 'foo.bar';
$res = AlipayHelper::studlyCase($str, '.');
$this->assertEquals('FooBar', $res);
}
}

0 comments on commit 7cfe506

Please sign in to comment.