mirror of
https://gitee.com/yansongda/pay.git
synced 2024-11-30 03:07:38 +08:00
fix: json 中有 &
时解析错误 (#687)
This commit is contained in:
parent
0f6963a90f
commit
6a730b79c0
@ -1,3 +1,9 @@
|
||||
## v3.2.6
|
||||
|
||||
### fixed
|
||||
|
||||
- fix: json 中有 `&` 时解析错误(#687)
|
||||
|
||||
## v3.2.5
|
||||
|
||||
### fixed
|
||||
|
@ -23,17 +23,16 @@ class ArrayParser implements ParserInterface
|
||||
|
||||
$body = (string) $response->getBody();
|
||||
|
||||
$result = json_decode($body, true);
|
||||
if (JSON_ERROR_NONE === json_last_error()) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
if (Str::contains($body, '&')) {
|
||||
return $this->query($body);
|
||||
}
|
||||
|
||||
$result = json_decode($body, true);
|
||||
|
||||
if (JSON_ERROR_NONE !== json_last_error()) {
|
||||
throw new InvalidResponseException(Exception::UNPACK_RESPONSE_ERROR, 'Unpack Response Error', ['body' => $body, 'response' => $response]);
|
||||
}
|
||||
|
||||
return $result;
|
||||
throw new InvalidResponseException(Exception::UNPACK_RESPONSE_ERROR, 'Unpack Response Error', ['body' => $body, 'response' => $response]);
|
||||
}
|
||||
|
||||
protected function query(string $body): array
|
||||
|
@ -61,4 +61,16 @@ class ArrayParserTest extends TestCase
|
||||
|
||||
self::assertEqualsCanonicalizing(['name' => 'yansongda', 'age' => '29'], $result);
|
||||
}
|
||||
|
||||
public function testJsonWith()
|
||||
{
|
||||
$url = 'https://yansongda.cn?name=yansongda&age=29';
|
||||
|
||||
$response = new Response(200, [], json_encode(['h5_url' => $url]));
|
||||
|
||||
$parser = new ArrayParser();
|
||||
$result = $parser->parse($response);
|
||||
|
||||
self::assertEquals('https://yansongda.cn?name=yansongda&age=29', $result['h5_url']);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user