You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
honor-dd-light-ds-java/doc/move/controller/class.DoudianMsgController.php

75 lines
2.2 KiB
PHP

<?php
class DoudianMsgController extends ZcController {
/**
* @var DoudianMsgService
*/
private $doudianMsgService;
private $doudianMsgLog;
public function __construct($route) {
parent::__construct($route);
$this->doudianMsgService = Zc::singleton(DoudianMsgService::class);
$this->doudianMsgLog = Zc::getLog('open/doudian_msg/msg_body', ZcLog::INFO);
}
private function checkCurrentApp($requestAppId, $eventSign, $msgBody) {
if (CommonTool::anyEmpty($requestAppId, $eventSign, $msgBody)) {
return false;
}
if ($requestAppId != Zc::C('appKey')) {
return false;
}
$md5 = md5(Zc::C('appKey') . $msgBody . Zc::C('appSecret'));
if ($eventSign != $md5) {
return false;
}
return true;
}
private function responseFail() {
return $this->renderJSON([
'code' => 1,
'msg' => 'fail',
]);
}
private function responseSuccess() {
return $this->renderJSON([
'code' => 0,
'msg' => 'success',
]);
}
public function ReceiveMessagePush() {
$msgBody = file_get_contents('php://input');
$isCurrentApp = $this->checkCurrentApp($_SERVER['HTTP_APP_ID'], $_SERVER['HTTP_EVENT_SIGN'], $msgBody);
if (!$isCurrentApp) {
$this->doudianMsgService->addDoudianFailMsg($msgBody);
$this->recordFailLog($msgBody);
return $this->responseFail();
}
$addRet = $this->doudianMsgService->addDoudianMsg($msgBody);
if (!$addRet) {
$this->recordFailLog($msgBody);
$this->doudianMsgService->addDoudianFailMsg($msgBody);
return $this->responseFail();
}
return $this->responseSuccess();
}
private function recordFailLog($msgBody) {
$this->doudianMsgLog->info(sprintf('HTTP_APP_ID[%s] HTTP_EVENT_SIGN[%s] msgBody: %s', $_SERVER['HTTP_APP_ID'], $_SERVER['HTTP_EVENT_SIGN'], $msgBody));
}
public function testDebug() {
exit('hello word');
}
}