文件

107 行
1.6 KiB
PHP

<?php
namespace addons\shopro_huifu\controller;
use addons\shopro_huifu\library\HuifuNotifyHandler;
use addons\shopro_huifu\library\HuifuNotifyParser;
use addons\shopro_huifu\library\HuifuQueryService;
use think\addons\Controller;
use think\Log;
class Pay extends Controller
{
protected $noNeedLogin = ['notify', 'notifyrefund'];
protected $noNeedRight = ['*'];
public function notify()
{
$raw = HuifuNotifyParser::parse($this->request);
Log::write('[shopro_huifu] notify hit(legacy): req_seq_id=' . $this->peekReqSeqId($raw));
@file_put_contents(RUNTIME_PATH . 'log/huifu_notify_hit.log', date('c') . ' legacy ' . $this->peekReqSeqId($raw) . "\n", FILE_APPEND);
try {
$handler = new HuifuNotifyHandler();
$ack = $handler->handlePayNotify($raw);
http_response_code($ack['httpCode']);
echo $ack['body'];
} catch (\Throwable $e) {
Log::write('[shopro_huifu] notify error: ' . $e->getMessage());
http_response_code(500);
echo '';
}
exit;
}
public function notifyrefund()
{
http_response_code(200);
echo 'OK';
exit;
}
protected function peekReqSeqId(array $raw)
{
$respData = $raw['resp_data'] ?? '';
if (is_string($respData) && $respData !== '') {
$data = json_decode($respData, true);
if (is_array($data) && !empty($data['req_seq_id'])) {
return (string) $data['req_seq_id'];
}
}
return '-';
}
}