From 589683e56bed0c65c8e3a6f664cc0853179de74a Mon Sep 17 00:00:00 2001 From: "X14XA\\shengli" Date: Tue, 10 Mar 2026 13:37:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DJSON=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E4=B8=A2=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/factory/object/trade/DeviceInfo.php | 17 ++++++++++++++++- src/factory/object/trade/DivDetail.php | 13 ++++++++++++- src/factory/object/trade/ObjectInfo.php | 13 ++++++++++++- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/factory/object/trade/DeviceInfo.php b/src/factory/object/trade/DeviceInfo.php index 39c70d4..f08b5c8 100644 --- a/src/factory/object/trade/DeviceInfo.php +++ b/src/factory/object/trade/DeviceInfo.php @@ -2,6 +2,8 @@ namespace Tansilu\HfPayLib\factory\object\trade; +use JsonSerializable; +use PHPUnit\Util\Json; use Tansilu\HfPayLib\exception\ParamsException; /** @@ -31,7 +33,7 @@ use Tansilu\HfPayLib\exception\ParamsException; * @property $serviceProviderIp 商户服务IP地址 * @property $merUrl 商户网址 */ -class DeviceInfo +class DeviceInfo implements JsonSerializable { public static function make( string $devType, @@ -62,6 +64,14 @@ class DeviceInfo $this->data[$name] = $value; } + /** + * @throws ParamsException + */ + public function __toString() + { + return $this->toJson(); + } + public function toJSON(): string { @@ -76,4 +86,9 @@ class DeviceInfo } return json_encode($this->data, JSON_UNESCAPED_UNICODE); } + + public function jsonSerialize(): array + { + return $this->data; + } } \ No newline at end of file diff --git a/src/factory/object/trade/DivDetail.php b/src/factory/object/trade/DivDetail.php index 5dfa368..a440b12 100644 --- a/src/factory/object/trade/DivDetail.php +++ b/src/factory/object/trade/DivDetail.php @@ -2,13 +2,15 @@ namespace Tansilu\HfPayLib\factory\object\trade; +use JsonSerializable; + /** * @property $divCustId 分账客户号 * @property $divAcctId 分账账户号 * @property $divAmt 分账金额 * @property $riskDivType 风控分账用途 */ -class DivDetail +class DivDetail implements JsonSerializable { public static function make(string $divCustId, string $divAcctId, string $amount, string $riskDivType): self { @@ -35,9 +37,18 @@ class DivDetail $this->data[$name] = $value; } + public function __toString() + { + return $this->toJSON(); + } public function toJSON(): string { return json_encode($this->data, JSON_UNESCAPED_UNICODE); } + + public function jsonSerialize(): array + { + return $this->data; + } } \ No newline at end of file diff --git a/src/factory/object/trade/ObjectInfo.php b/src/factory/object/trade/ObjectInfo.php index fb2c613..d709455 100644 --- a/src/factory/object/trade/ObjectInfo.php +++ b/src/factory/object/trade/ObjectInfo.php @@ -2,6 +2,8 @@ namespace Tansilu\HfPayLib\factory\object\trade; +use JsonSerializable; + /** * 藏品信息 * @@ -22,7 +24,7 @@ namespace Tansilu\HfPayLib\factory\object\trade; * @property string $regCustId 买家注册用户ID * */ -class ObjectInfo +class ObjectInfo implements JsonSerializable { public static function make(int $marketType): self { @@ -46,9 +48,18 @@ class ObjectInfo $this->data[$name] = $value; } + public function __toString() + { + return $this->toJSON(); + } public function toJSON(): string { return json_encode($this->data, JSON_UNESCAPED_UNICODE); } + + public function jsonSerialize(): array + { + return $this->data; + } } \ No newline at end of file