From ffa47b5b4881f228ac69465f17f1147a25fc3ee1 Mon Sep 17 00:00:00 2001 From: "zhangpeng.spin" Date: Mon, 9 Dec 2024 20:04:54 +0800 Subject: [PATCH] feat: fix jsonSerialize --- src/Model/Message/Saas/Attribution.php | 2 +- src/Sender/Saas/SaasItemMessageSender.php | 4 ++-- src/Sender/Saas/SaasProfileMessageSender.php | 2 +- test/HttpSaasTester.php | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Model/Message/Saas/Attribution.php b/src/Model/Message/Saas/Attribution.php index e8f8dc2..be9ccc7 100644 --- a/src/Model/Message/Saas/Attribution.php +++ b/src/Model/Message/Saas/Attribution.php @@ -69,7 +69,7 @@ public function jsonSerialize() if ($this->name != null) { $data["name"] = $this->name; } - if ($this->value != null) { + if ($this->value !== null) { $data["value"] = $this->value; } if ($this->operation != null) { diff --git a/src/Sender/Saas/SaasItemMessageSender.php b/src/Sender/Saas/SaasItemMessageSender.php index 3f181f9..27d886d 100644 --- a/src/Sender/Saas/SaasItemMessageSender.php +++ b/src/Sender/Saas/SaasItemMessageSender.php @@ -22,7 +22,7 @@ public function send(Message $message) $content = json_encode(array( "code" => "200", "message" => "success" - )); + ), JSON_PRESERVE_ZERO_FRACTION); foreach ($events as $event) { /** @var Event $event */ $objectEvent = $event; @@ -32,7 +32,7 @@ public function send(Message $message) $sendMessage = new SaasItemAppMessage($objectEvent); $urlPath = sprintf(SaasItemMessageSender::$path, $appMessage->getAppId(), $item_name, $item_id); $url = ($openapi->getDomain()) . $urlPath; - $body = json_encode($sendMessage); + $body = json_encode($sendMessage, JSON_PRESERVE_ZERO_FRACTION); $method = "PUT"; $authorization = AuthUtils::sign($openapi->getAk(), $openapi->getSk(), 1800, $method, $urlPath, null, $body); diff --git a/src/Sender/Saas/SaasProfileMessageSender.php b/src/Sender/Saas/SaasProfileMessageSender.php index 5ee586c..1af6ce0 100644 --- a/src/Sender/Saas/SaasProfileMessageSender.php +++ b/src/Sender/Saas/SaasProfileMessageSender.php @@ -16,7 +16,7 @@ class SaasProfileMessageSender implements MessageSender public function send(Message $message): void { $sendMessage = new SaasProfileAppMessage($message); - $body = json_encode($sendMessage); + $body = json_encode($sendMessage, JSON_PRESERVE_ZERO_FRACTION); $appMessage = $message->getAppMessage(); $openapi = CollectorConfig::getOpenapi(); $urlPath = sprintf(SaasProfileMessageSender::$path, $appMessage->getAppId(), $appMessage->getUserUniqueId()); diff --git a/test/HttpSaasTester.php b/test/HttpSaasTester.php index feb0550..ba6134e 100644 --- a/test/HttpSaasTester.php +++ b/test/HttpSaasTester.php @@ -25,14 +25,14 @@ $rc = new AppEventCollector(); # send event $rc->sendEvent("test-uuidsdk1", getenv("APP_ID"), null, ["php_event"], - [["php_name" => "php", "php_version" => "5.6"]]); + [["php_name" => "php", "php_version" => "5.6", "event_coin1"=>0]]); # send single event $rc->sendEvent("test-uuidsdk1", getenv("APP_ID"), null, "php_single_event", - ["php_name" => "php", "php_version" => "5.6"]); + ["php_name" => "php", "php_version" => "5.6", "event_coin2"=>0]); # profile set -$rc->profileSet("test-uuidsdk1", getenv("APP_ID"), ["profile_php_name" => "php7", "profile_php_version" => "7.4", "profile_int" => 1]); +$rc->profileSet("test-uuidsdk1", getenv("APP_ID"), ["profile_php_name" => "php7", "profile_php_version" => "7.4", "profile_int" => 1, "profile_coin" => 0]); # set item properties $rc->itemIdSet(getenv("APP_ID"), "book", "book3", ["author" => "吴承恩", "name" => "西游记", "price" => 59.90, "category" => 1]);