异常的消息数据中,我能不能只要response这部分,其他多余的信息不要
leeboo opened this issue · comments
leeboo commented
Client error: POST https://api.mch.weixin.qq.com/v3/applyment4sub/applyment/
resulted in a 400 Bad Request
response: {"code":"PARAM_ERROR","message":"开户银行省市编码(/bank_account_info/bank_address_code)取值有误,请检查
我只想要
{"code":"PARAM_ERROR","message":"开户银行省市编码(/bank_account_info/bank_address_code)取值有误,请检查这部分json
怎么弄?
James ZHANG commented
两种方式:
- 同步模式:
try {
$r = $instance->chain('v3/applyment4sub/applyment/')->post([]);
$m = json_decode((string)$r->getBody());
print_r($m);
} catch(Exception $e) {
if ($e instanceof \GuzzleHttp\Exception\RequestException && $e->hasResponse()) {
$r = $e->getResponse();
$m = json_decode((string)$r->getBody());
print_r($m);
}
}
- 异步链式:
$instance->chain('v3/applyment4sub/applyment/')
->postAsync([])
->then(static function(\Psr\Http\Message\ResponseInterface $r) {
$m = json_decode((string)$r->getBody());
print_r($m);
})
->otherwise(static function (\GuzzleHttp\Exception\RequestException $e) {
$r = $e->getResponse();
$m = json_decode((string)$r->getBody());
print_r($m);
})
->wait();