This commit is contained in:
aozhiwei 2024-06-05 19:22:04 +08:00
parent 9443d07aa8
commit 3d35b59f7b

View File

@ -17,57 +17,41 @@ class MailController extends BaseAuthedController {
$this->awardService = new services\AwardService(); $this->awardService = new services\AwardService();
} }
public function getAttachment() public function getAttachmentCb()
{ {
$mailIds = getReqVal('mail_ids', ''); $timestamp = getReqVal('timestamp', '');
$signStr = getReqVal('sign', '');
$data = file_get_contents('php://input');
$dataJson = json_decode($data, true);
$response = ''; $localSignStr = md5($data . MAIL_KEY . $timestamp);
{ if ($localSignStr != $signStr) {
$params = array( myself()->_rspErr(500, 'server internal error 3, url:');
'c' => 'Mail', return;
'a' => 'getAttachment', }
'account_id' => myself()->_getAccountId(), if (empty($dataJson)) {
'session_id' => myself()->_getSessionId(), myself()->_rspErr(500, 'server internal error 4, url:');
'mail_ids' => $mailIds return;
); }
if ($dataJson['account_id'] != myself()->_getAccountId()) {
myself()->_rspErr(500, 'server internal error 2, url:');
return;
}
$url = self::getMailServerUrl(); $this->procAttachments($dataJson);
if (!phpcommon\HttpClient::get myself()->_rspData(array(
($url, 'award' => $this->awardService->toDto(),
$params, 'property_chg' => $this->propertyChgService->toDto()
$response)) { ));
myself()->_rspErr(500, 'server internal error 3, url:' . $url);
die();
return;
}
}
error_log($mailIds);
error_log($response);
error_log($url);
$rspObj = json_decode($response, true);
if ($rspObj && $rspObj['errcode'] == 0) {
$this->procAttachments($rspObj['attachments']);
$rspObj['award'] = $this->awardService->toDto();
$rspObj['property_chg'] = $this->propertyChgService->toDto();
}
echo json_encode($rspObj);
} }
private function procAttachments($attachments) private function procAttachments($dataJson)
{ {
$mailHash = array(); $mailHash = $dataJson['mails'];
{ foreach ($mailHash as $val) {
foreach ($attachments as $item) { $mailId = $val['mailid'];
if (!array_key_exists($item['mailid'], $mailHash)) {
$mailHash[$item['mailid']] = array();
}
array_push($mailHash[$item['mailid']], $item);
}
}
foreach ($mailHash as $key => $val) {
$mailId = $key;
$items = array(); $items = array();
foreach ($val as $item) { foreach ($val['attachments'] as $item) {
array_push($items, array( array_push($items, array(
'item_id' => $item['itemid'], 'item_id' => $item['itemid'],
'item_num' => $item['itemnum'], 'item_num' => $item['itemnum'],
@ -116,9 +100,4 @@ class MailController extends BaseAuthedController {
} }
} }
private static function getMailServerUrl()
{
return MAIL_URL;
}
} }