feat: add kuaidi100 logistics sync
This commit is contained in:
43
server-api/app/controller/open/Kuaidi100Controller.php
Normal file
43
server-api/app/controller/open/Kuaidi100Controller.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user