Files
oil/server-tp6/app/api/controller/QytNotify.php
T

57 lines
2.0 KiB
PHP

<?php
// +----------------------------------------------------------------------
// | 企油通 · 回调接收
// +----------------------------------------------------------------------
// | 入口:public/qytconsume.php -> /qytNotify/consume
// | 对应企油通 7.10「运单加油明细推送(异步)」,我方须返回 {"code":"100","msg":"Success"}
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\api\controller;
use app\common\crypto\Qyt as QytCrypto;
use app\common\service\QueueService;
use app\common\service\QytOil;
use think\facade\Request;
class QytNotify extends Controller
{
/**
* 7.10 运单加油明细推送
* @return \think\response\Json
*/
public function consume()
{
$raw = Request::instance()->getContent();
(new QytOil())->saveLog('7.10 消费回调原文:' . $raw);
$body = json_decode($raw, true);
// 兼容:外层信封 {appId,timestamp,sign,params(JSON字符串)} 或 直接推 body
$params = $body;
if (is_array($body) && isset($body['params'])) {
$params = is_string($body['params']) ? json_decode($body['params'], true) : $body['params'];
}
// TODO 验签(规则待对接人确认)
// if (is_array($body) && !empty($body['sign'])) {
// $crypto = new QytCrypto();
// if (!$crypto->verify($params, $body['sign'])) {
// return json(['code' => '99', 'msg' => '验签失败']);
// }
// }
// 无明细也回 100,避免企油通重复推送
if (is_array($params) && !empty($params['order_list'])) {
(new QueueService())->push('callback_queue', json_encode([
'header' => ['method' => 'qyt_consume'],
'res' => $params,
], 320));
} else {
(new QytOil())->saveLog('7.10 消费回调无 order_list,已忽略');
}
return json(['code' => '100', 'msg' => 'Success']);
}
}