guzzle json 请求

use GuzzleHttp\Client;

$guzzle = new Client();

$header = [
'Content-Type' => 'application/json',
'appKey'=> $app_key,
'timestamp' => $timestamp,
'sign' => $sign
];

$data = [
'orderNo' => $ccic_order['third_order_no'],
'voucherNo' => $ccic_order['voucher_no'],
'userNo' => $ccic_order['ecif_id'],
'productCode' => $ccic_order['service_id'],
'orderType' => 1,
'orderStatus' => 3, // 0:未使用,自费券购买后默认状态 1:使用中 2:使用完成 3:取消
'ownExpense' => 1,
'callbackType' => 2,
];


$response
= $guzzle->post($callback_url, [
    'headers' => $header,     'json' =>
$data
]);
$res
= json_decode($response->getBody()->getContents(),true);

\Seaslog::info("请求结果:" . json_encode($res, JSON_UNESCAPED_UNICODE));

 

guzzle官方文档传送门:https://guzzle-cn.readthedocs.io/zh_CN/latest/

 

posted @ 2021-07-20 16:45  七彩鱼丸  阅读(548)  评论(0编辑  收藏  举报