待加密的字串
TradeDesc=促銷方案&PaymentType=aio&MerchantTradeDate=2023/03/12 15:30:23&MerchantTradeNo=ecpay20230312153023&MerchantID=3002607&ReturnURL=https://www.ecpay.com.tw/receive.php&ItemName=Apple iphone 15&TotalAmount=30000&ChoosePayment=ALL&EncryptType=1
檢核碼計算順序
(1) 將傳遞參數依照第一個英文字母,由A到Z的順序來排序(遇到第一個英文字母相同時,以第二個英文字母來比較,以此類推),並且以&方式將所有參數串連。
ChoosePayment=ALL&EncryptType=1&ItemName=Apple iphone 15&MerchantID=3002607&MerchantTradeDate=2023/03/12 15:30:23&MerchantTradeNo=ecpay20230312153023&PaymentType=aio&ReturnURL=https://www.ecpay.com.tw/receive.php&TotalAmount=30000&TradeDesc=促銷方案
(2) 參數最前面加上HashKey、最後面加上HashIV
HashKey=pwFHCqoQZGmho4w6&ChoosePayment=ALL&EncryptType=1&ItemName=Apple iphone 15&MerchantID=3002607&MerchantTradeDate=2023/03/12 15:30:23&MerchantTradeNo=ecpay20230312153023&PaymentType=aio&ReturnURL=https://www.ecpay.com.tw/receive.php&TotalAmount=30000&TradeDesc=促銷方案&HashIV=EkRm7iFT261dpevs
(3) 將整串字串進行URL encode
HashKey%3dpwFHCqoQZGmho4w6%26ChoosePayment%3dALL%26EncryptType%3d1%26ItemName%3dApple+iphone+15%26MerchantID%3d3002607%26MerchantTradeDate%3d2023%2f03%2f12+15%3a30%3a23%26MerchantTradeNo%3decpay20230312153023%26PaymentType%3daio%26ReturnURL%3dhttps%3a%2f%2fwww.ecpay.com.tw%2freceive.php%26TotalAmount%3d30000%26TradeDesc%3d%e4%bf%83%e9%8a%b7%e6%96%b9%e6%a1%88%26HashIV%3dEkRm7iFT261dpevs
注意事項:
若使用PHP語言時請使用urlencode()(RFC 1866),並使用str_replace() 依urlencode轉換表更換字元
(4) 轉為小寫
hashkey%3dpwfhcqoqzgmho4w6%26choosepayment%3dall%26encrypttype%3d1%26itemname%3dapple+iphone+15%26merchantid%3d3002607%26merchanttradedate%3d2023%2f03%2f12+15%3a30%3a23%26merchanttradeno%3decpay20230312153023%26paymenttype%3daio%26returnurl%3dhttps%3a%2f%2fwww.ecpay.com.tw%2freceive.php%26totalamount%3d30000%26tradedesc%3d%e4%bf%83%e9%8a%b7%e6%96%b9%e6%a1%88%26hashiv%3dekrm7ift261dpevs
注意事項:
若使用PHP語言時請使用strtolower()
(5) 以SHA256加密方式來產生雜凑值
6c51c9e6888de861fd62fb1dd17029fc742634498fd813dc43d4243b5685b840
(6) 再轉大寫產生CheckMacValue
6C51C9E6888DE861FD62FB1DD17029FC742634498FD813DC43D4243B5685B840
注意事項:
- 請特店接收到綠界傳送的資訊時,必須檢查檢查碼[CheckMacValue]是否正確,如未判斷特店可能產生損失。
- 請用SHA256加密方式產生雜凑值。
- 請確認您的語言的 UrlEncode function 轉換後的結果符合附錄URLENCODE轉換表中的「.NET編碼(ecpay)」欄位值,若有不符合的字元,請用字元替換功能處理,以免無法符合檢查規則。
例如:PHP urlencode function會將 ! 字元編碼成 %21,不符合「.NET編碼(ecpay)」,所以在 PHP urlencode後需用 str_replace function 將%21轉回 ! 字元。以下僅以 PHP轉換範例說明:
$sMacValue = str_replace(‘%2d’, ‘-‘, $sMacValue);
$sMacValue = str_replace(‘%5f’, ‘_’, $sMacValue);
$sMacValue = str_replace(‘%2e’, ‘.’, $sMacValue);
$sMacValue = str_replace(‘%21’, ‘!’, $sMacValue);
$sMacValue = str_replace(‘%2a’, ‘*’, $sMacValue);
$sMacValue = str_replace(‘%28’, ‘(‘, $sMacValue);
$sMacValue = str_replace(‘%29’, ‘)’, $sMacValue);
其它程式語言的轉換功能,請閱該程式語言的編碼轉換規則改寫。