--- title: '綠界問題' tags: 綠界問題 description: 2023/08/29 --- 綠界問題 === [ToC] 綠界問題 --- * 以下是我 post 給綠界,<span class="red">**綠界 api 回傳**</span>的參數內容 * 測試環境 api:`https://payment-stage.ecpay.com.tw/Cashier/AioCheckOut/V5` ```PHP= array( "AlipayID" => null "AlipayTradeNo" => null "amount" => "1000" "ATMAccBank" => null "ATMAccNo" => null "auth_code" => "777777" "card4no" => "2222" "card6no" => "431195" "CustomField1" => null "CustomField2" => null "CustomField3" => null "CustomField4" => null "eci" => "0" "ExecTimes" => null "Frequency" => null "gwsr" => "12793002" "MerchantID" => "2000132" "MerchantTradeNo" => "ECPay1693271370" "PayFrom" => null "PaymentDate" => "2023/08/29 09:11:00" "PaymentNo" => null "PaymentType" => "Credit_CreditCard" "PaymentTypeChargeFee" => "20" "PeriodAmount" => null "PeriodType" => null "process_date" => "2023/08/29 09:11:00" "red_dan" => "0" "red_de_amt" => "0" "red_ok_amt" => "0" "red_yet" => "0" "RtnCode" => "1" "RtnMsg" => "Succeeded" "SimulatePaid" => "0" "staed" => "0" "stage" => "0" "stast" => "0" "StoreID" => null "TenpayTradeNo" => null "TotalSuccessAmount" => null "TotalSuccessTimes" => null "TradeAmt" => "1000" "TradeDate" => "2023/08/29 09:09:32" "TradeNo" => "2308290909327284" "WebATMAccBank" => null "WebATMAccNo" => null "WebATMBankName" => null "CheckMacValue" => "F73AFA6CE619312B0EABFCF768BD2BFC0D6CDF954AE56D752EA55AB183EC938B" ) ``` 這是您上次給我參考的 "產生檢查碼" code ```php= private function getMacValue($hash_key, $hash_iv, $form_array) //產生檢查碼 { $encode_str = "HashKey=" . $hash_key; foreach ($form_array as $key => $value) { $encode_str .= "&" . $key . "=" . $value; } $encode_str .= "&HashIV=" . $hash_iv; $encode_str = strtolower(urlencode($encode_str)); $encode_str = $this->replaceChar($encode_str); //MD5加密 //return strtoupper(md5($encode_str)); //SHA256加密 return strtoupper(hash('sha256' ,$encode_str)); } private function merchantSort($a,$b) //仿自然排序法 { return strcasecmp($a, $b); } private function replaceChar($value) //特殊字元置換 { $search_list = array('%2d', '%5f', '%2e', '%21', '%2a', '%2A', '%28', '%29'); $replace_list = array('-', '_', '.', '!', '*' , '*', '(', ')'); $value = str_replace($search_list, $replace_list ,$value); return $value; } ``` ==問題 : [綠界文件 : 付款 / 付款結果通知](https://developers.ecpay.com.tw/?p=2878)== ==(如下第 10、11 行結果) <span class="red">**得到的檢查碼不一樣...**</span>,可是確有交易成功 ??== ==請問這樣的 "比對檢查碼" 寫法對嗎 ??== (第 6 行) $request->all( ) 為綠界回傳的 array...,使之變成檢查碼... ```php= public function callback(Request $request) { $hash_key = "5294y06JbISpM5x9"; //HashKey $hash_iv = "v77hoKGq4kWxNNIS"; //HashIV // 檢查碼 : $request->all() 即綠界回傳的 array $aaa = $request->all(); uksort($aaa, array($this, "merchantSort")); $get_CheckMacValue = $this->getMacValue($hash_key, $hash_iv, $aaa); dd( $aaa['CheckMacValue'], $get_CheckMacValue ) } // $aaa['CheckMacValue'] 得到 F73AFA6CE619312B0EABFCF768BD2BFC0D6CDF954AE56D752EA55AB183EC938B // $get_CheckMacValue 得到 D23626466BF5440A8264EA83D7E979141342BA485A0F1D4807459D930021B3A2 ``` <style> .red { color: red; } .green { color: green; } </style>