44 lines
1.2 KiB
PHP
44 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace app\controller\open;
|
|
|
|
use app\support\OrderLogisticsSyncService;
|
|
use support\Request;
|
|
|
|
class Kuaidi100Controller
|
|
{
|
|
public function callback(Request $request)
|
|
{
|
|
$payload = json_decode($request->rawBody(), true);
|
|
if (!is_array($payload)) {
|
|
$payload = $request->all();
|
|
}
|
|
if (isset($payload['param']) && is_string($payload['param'])) {
|
|
$paramPayload = json_decode($payload['param'], true);
|
|
if (is_array($paramPayload)) {
|
|
$payload = $paramPayload;
|
|
}
|
|
}
|
|
if (!is_array($payload)) {
|
|
return $this->callbackResponse(false, '400', '请求体格式错误');
|
|
}
|
|
|
|
try {
|
|
(new OrderLogisticsSyncService())->handleCallback($payload);
|
|
} catch (\Throwable $e) {
|
|
return $this->callbackResponse(false, '500', $e->getMessage());
|
|
}
|
|
|
|
return $this->callbackResponse(true, '200', '成功');
|
|
}
|
|
|
|
private function callbackResponse(bool $result, string $returnCode, string $message)
|
|
{
|
|
return json([
|
|
'result' => $result,
|
|
'returnCode' => $returnCode,
|
|
'message' => $message,
|
|
]);
|
|
}
|
|
}
|