From a0ab2772561ccb8375606181b1cd80eb28b972e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A2=E1=84=91=E1=85=B3=E1=86=AF=20=E1=84=82?= =?UTF-8?q?=E1=85=A9=E1=84=90=E1=85=B3=E1=84=87=E1=85=AE=E1=86=A8?= Date: Tue, 30 Apr 2019 12:04:43 +0900 Subject: [PATCH] Add: php MailSender class --- src/web/php/mail/chocomae_info.php | 15 +++ src/web/php/mail/mail_sender.php | 126 ++++++++++++++++++ src/web/php/mail/mail_setting.php | 31 +++++ src/web/php/{test.php => test_argument.php} | 0 src/web/php/test_sendmail.php | 17 +++ .../chocomae/backup_unregister_maestro.py | 17 ++- src/web/python/chocomae/test_mail.py | 7 + 7 files changed, 204 insertions(+), 9 deletions(-) create mode 100644 src/web/php/mail/chocomae_info.php create mode 100644 src/web/php/mail/mail_sender.php create mode 100644 src/web/php/mail/mail_setting.php rename src/web/php/{test.php => test_argument.php} (100%) create mode 100644 src/web/php/test_sendmail.php create mode 100644 src/web/python/chocomae/test_mail.py diff --git a/src/web/php/mail/chocomae_info.php b/src/web/php/mail/chocomae_info.php new file mode 100644 index 0000000..fd6b455 --- /dev/null +++ b/src/web/php/mail/chocomae_info.php @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/src/web/php/mail/mail_sender.php b/src/web/php/mail/mail_sender.php new file mode 100644 index 0000000..e50eec6 --- /dev/null +++ b/src/web/php/mail/mail_sender.php @@ -0,0 +1,126 @@ +mailSetting->hostNameUrl."\n\r"; + echo "senderName : ".$this->senderName."\n\r"; + echo "senderEmail : ".$this->senderEmail."\n\r"; + } + public function setMailSetting($setting) { + $this->mailSetting = $setting; + } + + public function setSenderInfo($name, $email) { + $this->senderName = $name; + $this->senderEmail = $email; + } + + function makeSignature($secretKey, $method, $uri, $timestamp, $accessKey) { + $space = " "; + $newLine = "\n"; + $hmac = $method.$space.$uri.$newLine.$timestamp.$newLine.$accessKey; + $signautue = base64_encode(hash_hmac('sha256', $hmac, $secretKey,true)); + echo "this is signiture : ".$signautue."\n"; + return $signautue; + } + + public function send() { + try { + $timestamp = ""; + $microtime = ""; + list($microtime,$timestamp) = explode(' ',microtime()); + $timestamp = $timestamp.substr($microtime, 2, 3); + + $is_post = false; + if($method == "POST") { + $postParam = array( + "advertising" => false, // 광고메일여부 default: false + "attachFileIds" => array(), // 첨부파일ID + "body" => "", // Email 본문 + "individual" => false, // 개인발송여부 (개인발송 시 참조인, 숨은참조 무시됨) default: true + "parameters" => array( + "maestro_name" => $maestro_name, + "register_date" => $register_date, + ), // 치환 파라미터 (수신자별로 적용), ‘치환 ID’ 를 key로, ‘치환 ID에 맵핑되는 값’ 을 value로 가지는 Map 형태의 Object + "recipients" => array( + array( + "address" => $maestro_email, // 수신자 Email 주소 + "name" => "", // 수신자 명 + "type" => "R", // 수신자 유형 (R: 수신자, C: 참조인, B: 숨은참조) default: R + // "parameters" => array_map(), + // 치환 파라미터 (수신자별로 적용), ‘치환 ID’ 를 key로, ‘치환 ID에 맵핑되는 값’ 을 value로 가지는 Map 형태의 Object + "parameters" => array( + "maestro_name" => $maestro_name, + ), // 치환 파라미터 (수신자별로 적용), ‘치환 ID’ 를 key로, ‘치환 ID에 맵핑되는 값’ 을 value로 가지는 Map 형태의 Object + ), + ), + "referencesHeader" => "", // 특정 메일을 모아서 보기 위해 네이버 메일에서 지원하는 기능, 해당 필드에 동일한 값을 입력한 메일들을 모아서 볼 수 있다. (다음의 형태가 되어야 함 : ) + "reservationUtc" => "", // 예약 발송 일시 ( 1970년 1월 1일 00:00:00 협정 세계시(UTC) 부터의 경과 시간을 1/1000초로 환산한 정수 ), reservationDateTime 값보다 이 값이 우선 적용된다. + "reservationDateTime" => "", // 다음과 같은 형태의 예약 발송 일시 (‘yyyy-MM-dd HH:mm’ UTC+09:00), reservationUtc 값이 우선한다. + "senderAddress" => $senderEmail, // 발송자 Email 주소 + "senderName" => $senderName, // 발송자 이름 + "tempRequestId" => "", // 첨부파일 등록 시 사용한 임시 요청 ID + "templateSid" => "337", // 템플릿 ID + "title" => "", // Mail 제목 + ); + + $postParam = json_encode($postParam); + echo "json:\n"; + echo $postParam; + echo "\n"; + + $is_post = true; + + $success_code = 201; + } else { + $success_code = 200; + $requestUrl = $requestUrl."/requests/".$requestId."/status"; + } + + $signautue = makeSignature($secretKey, $method, $requestUrl, $timestamp, $accessKey); + + $url = $hostNameUrl.$requestUrl; + echo $url."\n"; + $ch = curl_init(); + + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_POST, $is_post); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); + if($method == "POST") { + curl_setopt($ch, CURLOPT_POSTFIELDS, $postParam); + } + $headers = array(); + $headers[] = "X-NCP-APIGW-TIMESTAMP: " .$timestamp; + $headers[] = "X-NCP-IAM-ACCESS-KEY: " .$accessKey; + $headers[] = "X-NCP-APIGW-SIGNATURE-V2: " .$signautue; + $headers[] = "content-type: application/json"; + + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + $response = curl_exec ($ch); + $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); + echo "status_code:".$status_code."\n"; + curl_close ($ch); + if($status_code == 200) { + echo $response."\n"; + } else { + echo "Error 내용:".$response."\n"; + } + + } catch(Exception $E) { + echo "Response: ". $E->lastResponse . "\n"; + } + } +} + +?> \ No newline at end of file diff --git a/src/web/php/mail/mail_setting.php b/src/web/php/mail/mail_setting.php new file mode 100644 index 0000000..c563987 --- /dev/null +++ b/src/web/php/mail/mail_setting.php @@ -0,0 +1,31 @@ + \ No newline at end of file diff --git a/src/web/php/test.php b/src/web/php/test_argument.php similarity index 100% rename from src/web/php/test.php rename to src/web/php/test_argument.php diff --git a/src/web/php/test_sendmail.php b/src/web/php/test_sendmail.php new file mode 100644 index 0000000..00e9e02 --- /dev/null +++ b/src/web/php/test_sendmail.php @@ -0,0 +1,17 @@ +setMailSetting($nCloudSetting); + +$chocomae = new ChocomaeInfo(); +$mailSender->setSenderInfo($chocomae->sender_name, $chocomae->sender_email); + +$mailSender->showSettings(); + +?> diff --git a/src/web/python/chocomae/backup_unregister_maestro.py b/src/web/python/chocomae/backup_unregister_maestro.py index e3cba17..c3c4831 100644 --- a/src/web/python/chocomae/backup_unregister_maestro.py +++ b/src/web/python/chocomae/backup_unregister_maestro.py @@ -4,8 +4,8 @@ import subprocess from batch.unpaid_maestro_manager import UnpaidMaestroManager -print('# args : {}'.format(len(sys.argv))) -print('args : {}'.format(str(sys.argv))) +# print('# args : {}'.format(len(sys.argv))) +# print('args : {}'.format(str(sys.argv))) mode = 'mac' arg_count = len(sys.argv) if arg_count > 1: @@ -35,19 +35,18 @@ def backup_unregister_maestro_table_file(): command_db_backup = command + user + password + transaction + db + table + where_clause + output_filename # 'mysqldump -u "${DBUSER}" -p"${DBPASS}" --single-transaction "${DBNAME}" "${filename}" --where="DATE(${record_date})=CURDATE()" > "${filename}.dump.bydate.sql"' print(command_db_backup) - # subprocess.call(command_db_backup) + subprocess.call(command_db_backup) unpaidMaestroMan = UnpaidMaestroManager(mode) maestro_list = unpaidMaestroMan.get_unpaid_7days_maestro_list() -print_items(maestro_list) +# print_items(maestro_list) backup_unregister_maestro_table_file() # print(mode) -''' for maestro in maestro_list: - remark = maestro['Name'] + ' / unpaid 7 days' - unpaidMaestroMan.insert_maestro_log(maestro['MaestroID'], remark) - unpaidMaestroMan.delete_maestro_list(maestro['MaestroID']) -''' \ No newline at end of file + print(maestro['Name']) + # remark = maestro['Name'] + ' / unpaid 7 days' + # unpaidMaestroMan.insert_maestro_log(maestro['MaestroID'], remark) + # unpaidMaestroMan.delete_maestro_list(maestro['MaestroID']) diff --git a/src/web/python/chocomae/test_mail.py b/src/web/python/chocomae/test_mail.py new file mode 100644 index 0000000..6a92a4f --- /dev/null +++ b/src/web/python/chocomae/test_mail.py @@ -0,0 +1,7 @@ +import subprocess + +php +command_db_backup = command + user + password + transaction + db + table + where_clause + output_filename +# 'mysqldump -u "${DBUSER}" -p"${DBPASS}" --single-transaction "${DBNAME}" "${filename}" --where="DATE(${record_date})=CURDATE()" > "${filename}.dump.bydate.sql"' +print(command_db_backup) +subprocess.call(command_db_backup)