HEX
Server: Apache/2.4.37 (CentOS Stream) OpenSSL/1.1.1k
System: Linux ysnet.com.tw 4.18.0-553.5.1.el8.x86_64 #1 SMP Tue May 21 05:46:01 UTC 2024 x86_64
User: test (521)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: //proc/self/cwd/period_notify.php
<?php
    require_once 'db.php'; // 引入資料庫連線

    try {
        // 從綠界收到的 POST 資料
        $userID = $_POST['CustomField1'] ?? null; // 你在訂單建立時傳入的 user id
        $processDate = $_POST['ProcessDate'] ?? ''; // 付款時間,如 2025/04/11 16:40:33
    	$rtnCodeRaw = $_POST['RtnCode'] ?? '';  //回傳狀態碼(重要),1扣款成功,非1 扣款失敗
    	$rtnCode = ($rtnCodeRaw == 1) ? 1 : 0;
    	$rtnMsg = '❌ 扣款失敗,請確認您的信用卡資訊或帳戶餘額,或與客服聯繫(03)358-5867。';

        if ($userID && $processDate) {
        	// 清理付款日期格式:轉換成 yyyy-mm-dd
            $dateOnly = date('Y-m-d', strtotime($processDate));
        	if ($rtnCode == 1) {
            
            	// 更新資料庫,把付款日期寫入 ecpay 欄位
            	$stmt = $conn->prepare("UPDATE filemaker SET ecpay = ?, rtn_code = ? WHERE user = ?");
        		$stmt->bind_param("sii", $dateOnly, $rtnCode, $userID);
            	$stmt->execute();
            	$stmt->close();
            } else {
            	$stmt = $conn->prepare("UPDATE filemaker SET rtn_code = ?, rtn_msg = ? WHERE user = ?");
        		$stmt->bind_param("isi", $rtnCode, $rtnMsg, $userID);
            	$stmt->execute();
            	$stmt->close();
            }
        }

        // 回應綠界:成功收到
        echo '1|OK';

    } catch (Exception $e) {
        // 失敗回應給綠界,並可選擇記 log
        error_log("ECPay Notify Error: " . $e->getMessage());
        echo '0|Fail';
    }
?>