{"record":{"id":"ce34cbc67364947b","repo":"w7corp/easywechat","slug":"invalid-response-content-s","errorCode":null,"errorMessage":"Invalid Response content \"%s\".","messagePattern":"Invalid Response content \"(.+?)\"\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Kernel/Traits/RespondJsonMessage.php","lineNumber":59,"sourceCode":"        }\n\n        throw new InvalidArgumentException(\n            sprintf('Invalid Response type \"%s\".', gettype($response))\n        );\n    }\n\n    /**\n     * @throws RuntimeException\n     */\n    protected function createJsonResponse(array $attributes, ?Encryptor $encryptor = null): ResponseInterface\n    {\n        $jsonStr = json_encode($attributes, JSON_UNESCAPED_UNICODE);\n\n        if (is_string($jsonStr)) {\n            return new Response(200, ['Content-Type' => 'application/json'], $encryptor ? $encryptor->encrypt($jsonStr, messageType: $this->messageType) : $jsonStr);\n        }\n\n        throw new InvalidArgumentException(\n            sprintf('Invalid Response content \"%s\".', implode(',', $attributes))\n        );\n    }\n}\n","sourceCodeStart":41,"sourceCodeEnd":64,"githubUrl":"https://github.com/w7corp/easywechat/blob/f0cf0a8b8361417ed683b8246d0ecbaf0aafcaa8/src/Kernel/Traits/RespondJsonMessage.php#L41-L64","documentation":"createJsonResponse() json_encodes the reply attributes and throws this InvalidArgumentException when json_encode returns false. Encoding fails on malformed UTF-8 byte sequences and on NAN/INF values, so the usual culprit is reply content containing non-UTF-8 text (GBK/Latin-1 from a legacy database) or binary data. Note the message itself does implode(',', $attributes), which cannot render nested arrays.","triggerScenarios":"A Work JSON-mode passive reply whose text was stored or converted as GBK; echoing raw uploaded bytes into a reply; a division producing NAN/INF floats that end up in the payload.","commonSituations":"Databases with latin1/gbk columns feeding reply content; upstream systems sending unvalidated user text; debug strings appended to replies.","solutions":["Normalize reply text to UTF-8: mb_convert_encoding($text, 'UTF-8', 'GBK').","Strip invalid sequences: iconv('UTF-8', 'UTF-8//IGNORE', $text).","Keep floats out or guard with is_finite() before returning the reply.","Never put binary in a passive reply — reply with a download link instead."],"exampleFix":"// before: user text in GBK reaches the reply\nreturn ['msgtype' => 'text', 'text' => ['content' => $userInput]];\n// after: normalize to UTF-8 before replying\nreturn ['msgtype' => 'text', 'text' => ['content' => mb_convert_encoding($userInput, 'UTF-8', 'GBK')]];","handlingStrategy":"validation","validationCode":"array_walk_recursive($reply, function (&$v): void {\n    if (is_string($v) && !mb_check_encoding($v, 'UTF-8')) { $v = mb_convert_encoding($v, 'UTF-8', 'GBK,UTF-8'); }\n    if (is_float($v) && !is_finite($v)) { $v = 0; }\n});","typeGuard":"function isUtf8JsonEncodable(array $reply): bool { $ok = true; array_walk_recursive($reply, function ($v) use (&$ok) { if (is_string($v)) { $ok = $ok && mb_check_encoding($v, 'UTF-8'); } }); return $ok; }","tryCatchPattern":"try { return $server->serve(); } catch (\\EasyWeChat\\Kernel\\Exceptions\\InvalidArgumentException $e) { if (str_contains($e->getMessage(), 'Invalid Response content')) { \\Log::warning('reply not JSON-encodable, falling back to success'); return new \\Nyholm\\Psr7\\Response(200, [], 'success'); } throw $e; }","preventionTips":["Make UTF-8 the single internal encoding","Validate external text at the boundary with mb_check_encoding","Never place raw file bytes in passive replies"],"tags":["php","json","utf-8","encoding","wechat-work"],"backgroundTag":"json-encode-failed","analyzedSha":"f0cf0a8b8361417ed683b8246d0ecbaf0aafcaa8","analyzedAt":"2026-08-21T05:29:19.565Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}