From 251a75bfa1214628b49485331e8f813f3f581496 Mon Sep 17 00:00:00 2001 From: cobenash Date: Sun, 19 Jun 2016 12:24:36 +0800 Subject: [PATCH] fix small bug --- AioSDK/sdk/AllPay.Payment.Integration.php | 202 +++++++++++----------- 1 file changed, 101 insertions(+), 101 deletions(-) diff --git a/AioSDK/sdk/AllPay.Payment.Integration.php b/AioSDK/sdk/AllPay.Payment.Integration.php index 0fa0ff7..f37aeaa 100644 --- a/AioSDK/sdk/AllPay.Payment.Integration.php +++ b/AioSDK/sdk/AllPay.Payment.Integration.php @@ -146,12 +146,12 @@ abstract class PaymentMethodItem { * 中國信託。 */ const ATM_CHINATRUST = 'CHINATRUST'; - + /** * 土地銀行。 */ const ATM_LAND = 'LAND'; - + /** * 國泰世華銀行。 */ @@ -176,7 +176,7 @@ abstract class PaymentMethodItem { * 第一銀行。 */ const ATM_FIRST = 'FIRST'; - + // 超商類(201~300) /** * 超商代碼繳款。 @@ -349,13 +349,13 @@ abstract class InvoiceState { abstract class CarruerType { // 無載具 const None = ''; - + // 會員載具 const Member = '1'; - + // 買受人自然人憑證 const Citizen = '2'; - + // 買受人手機條碼 const Cellphone = '3'; } @@ -366,7 +366,7 @@ abstract class CarruerType { abstract class PrintMark { // 不列印 const No = '0'; - + // 列印 const Yes = '1'; } @@ -377,7 +377,7 @@ abstract class PrintMark { abstract class Donation { // 捐贈 const Yes = '1'; - + // 不捐贈 const No = '2'; } @@ -388,7 +388,7 @@ abstract class Donation { abstract class ClearanceMark { // 經海關出口 const Yes = '1'; - + // 非經海關出口 const No = '2'; } @@ -399,13 +399,13 @@ abstract class ClearanceMark { abstract class TaxType { // 應稅 const Dutiable = '1'; - + // 零稅率 const Zero = '2'; - + // 免稅 const Free = '3'; - + // 應稅與免稅混合(限收銀機發票無法分辦時使用,且需通過申請核可) const Mix = '9'; } @@ -416,7 +416,7 @@ abstract class TaxType { abstract class InvType { // 一般稅額 const General = '07'; - + // 特種稅額 const Special = '08'; } @@ -424,7 +424,7 @@ abstract class InvType { abstract class EncryptType { // MD5(預設) const ENC_MD5 = 0; - + // SHA256 const ENC_SHA256 = 1; } @@ -499,7 +499,7 @@ function __construct() { 'MerchantTradeNo' => '', 'TradeNo' => '', 'ChargeBackTotalAmount' => 0, 'Remark' => '' ); $this->Capture = array(); - + } //產生訂單 @@ -516,14 +516,14 @@ function CheckOutString($paymentButton = null, $target = "_self") { //取得付款結果通知的方法 function CheckOutFeedback() { - return $arFeedback = CheckOutFeedback::CheckOut($_POST,$this->HashKey,$this->HashIV,0); + return $arFeedback = CheckOutFeedback::CheckOut($_POST,$this->HashKey,$this->HashIV,0); } //訂單查詢作業 function QueryTradeInfo() { return $arFeedback = QueryTradeInfo::CheckOut(array_merge($this->Query,array("MerchantID" => $this->MerchantID)) ,$this->HashKey ,$this->HashIV ,$this->ServiceURL) ; } - + //信用卡定期定額訂單查詢的方法 function QueryPeriodCreditCardTradeInfo() { return $arFeedback = QueryPeriodCreditCardTradeInfo::CheckOut(array_merge($this->Query,array("MerchantID" => $this->MerchantID)) ,$this->HashKey ,$this->HashIV ,$this->ServiceURL); @@ -533,18 +533,18 @@ function QueryPeriodCreditCardTradeInfo() { function DoAction() { return $arFeedback = DoAction::CheckOut(array_merge($this->Action,array("MerchantID" => $this->MerchantID)) ,$this->HashKey ,$this->HashIV ,$this->ServiceURL); } - + //廠商通知退款 function AioChargeback() { return $arFeedback = AioChargeback::CheckOut(array_merge($this->ChargeBack,array("MerchantID" => $this->MerchantID)) ,$this->HashKey ,$this->HashIV ,$this->ServiceURL); } - + function AioCapture(){ return $arFeedback = AioCapture::Capture(array_merge($this->Capture,array("MerchantID" => $this->MerchantID)) ,$this->HashKey ,$this->HashIV ,$this->ServiceURL); } - + } @@ -553,7 +553,7 @@ function AioCapture(){ */ abstract class Aio { - abstract static function CheckOut(); + //abstract static function CheckOut(); protected function ServerPost($parameters ,$ServiceURL) { $ch = curl_init(); @@ -577,39 +577,39 @@ protected function ServerPost($parameters ,$ServiceURL) { * 產生訂單 */ class Send extends Aio -{ +{ //付款方式物件 public static $PaymentObj ; - function process($arParameters = array(),$arExtend = array()) + static function process($arParameters = array(),$arExtend = array()) { //宣告付款方式物件 $PaymentMethod = 'allPay_'.$arParameters['ChoosePayment']; self::$PaymentObj = new $PaymentMethod; - + //檢查參數 $arParameters = self::$PaymentObj->check_string($arParameters); - + //檢查商品 $arParameters = self::$PaymentObj->check_goods($arParameters); //檢查各付款方式的額外參數&電子發票參數 $arExtend = self::$PaymentObj->check_extend_string($arExtend,$arParameters['InvoiceMark']); - + //過濾 $arExtend = self::$PaymentObj->filter_string($arExtend,$arParameters['InvoiceMark']); //合併共同參數及延伸參數 return array_merge($arParameters,$arExtend) ; } - + static function CheckOut($target = "_self",$arParameters = array(),$arExtend = array(),$HashKey='',$HashIV='',$ServiceURL=''){ - + $arParameters = self::process($arParameters,$arExtend); //產生檢查碼 $szCheckMacValue = CheckMacValue::generate($arParameters,$HashKey,$HashIV,$arParameters['EncryptType']); - + //生成表單,自動送出 $szHtml = ''; $szHtml .= '
'; @@ -625,11 +625,11 @@ static function CheckOut($target = "_self",$arParameters = array(),$arExtend = a } static function CheckOutString($paymentButton,$target = "_self",$arParameters = array(),$arExtend = array(),$HashKey='',$HashIV='',$ServiceURL=''){ - + $arParameters = self::process($arParameters,$arExtend); //產生檢查碼 $szCheckMacValue = CheckMacValue::generate($arParameters,$HashKey,$HashIV,$arParameters['EncryptType']); - + $szHtml = ''; $szHtml = ''; $szHtml .= '
'; @@ -645,7 +645,7 @@ static function CheckOutString($paymentButton,$target = "_self",$arParameters = } -class CheckOutFeedback extends Aio +class CheckOutFeedback extends Aio { static function CheckOut($arParameters = array(),$HashKey = '' ,$HashIV = ''){ // 變數宣告。 @@ -680,7 +680,7 @@ static function CheckOut($arParameters = array(),$HashKey = '' ,$HashIV = ''){ if (sizeof($arErrors) > 0) { throw new Exception(join('- ', $arErrors)); } - + return $arFeedback; } } @@ -700,7 +700,7 @@ static function CheckOut($arParameters = array(),$HashKey ='',$HashIV ='',$Servi $szResult = parent::ServerPost($arParameters,$ServiceURL); $szResult = str_replace(' ', '%20', $szResult); $szResult = str_replace('+', '%2B', $szResult); - + // 轉結果為陣列。 parse_str($szResult, $arParameters); // 重新整理回傳參數。 @@ -728,7 +728,7 @@ static function CheckOut($arParameters = array(),$HashKey ='',$HashIV ='',$Servi return $arFeedback ; - } + } } @@ -746,7 +746,7 @@ static function CheckOut($arParameters = array(),$HashKey ='',$HashIV ='',$Servi $szResult = parent::ServerPost($arParameters,$ServiceURL); $szResult = str_replace(' ', '%20', $szResult); $szResult = str_replace('+', '%2B', $szResult); - + // 轉結果為陣列。 $arParameters = json_decode($szResult,true); // 重新整理回傳參數。 @@ -771,7 +771,7 @@ static function CheckOut($arParameters = array(),$HashKey ='',$HashIV ='',$Servi // 變數宣告。 $arErrors = array(); $arFeedback = array(); - + //產生驗證碼 $szCheckMacValue = CheckMacValue::generate($arParameters,$HashKey,$HashIV,0); $arParameters["CheckMacValue"] = $szCheckMacValue; @@ -791,7 +791,7 @@ static function CheckOut($arParameters = array(),$HashKey ='',$HashIV ='',$Servi if (array_key_exists('RtnCode', $arFeedback) && $arFeedback['RtnCode'] != '1') { array_push($arErrors, vsprintf('#%s: %s', array($arFeedback['RtnCode'], $arFeedback['RtnMsg']))); } - + if (sizeof($arErrors) > 0) { throw new Exception(join('- ', $arErrors)); } @@ -810,7 +810,7 @@ static function CheckOut($arParameters = array(), $HashKey='',$HashIV='',$Servic // 變數宣告。 $arErrors = array(); $arFeedback = array(); - + $szCheckMacValue = CheckMacValue::generate($arParameters,$HashKey,$HashIV,0); $arParameters["CheckMacValue"] = $szCheckMacValue; // 送出查詢並取回結果。 @@ -839,7 +839,7 @@ static function CheckOut($arParameters=array(),$HashKey='',$HashIV='',$ServiceUR $arErrors = array(); $arFeedback = array(); - + $szCheckMacValue = CheckMacValue::generate($arParameters,$HashKey,$HashIV,0); $arParameters["CheckMacValue"] = $szCheckMacValue; @@ -904,7 +904,7 @@ abstract function check_extend_string($arExtend = array(),$InvoiceMark = ''); ); //檢查共同參數 public function check_string($arParameters = array()){ - + $arErrors = array(); if (strlen($arParameters['MerchantID']) == 0) { array_push($arErrors, 'MerchantID is required.'); @@ -950,7 +950,7 @@ public function check_string($arParameters = array()){ if (sizeof($arParameters['Items']) == 0) { array_push($arErrors, 'Items is required.'); } - + // 檢查CheckMacValue加密方式 if (strlen($arParameters['EncryptType']) > 1) { array_push($arErrors, 'EncryptType max langth as 1.'); @@ -1061,7 +1061,7 @@ public function check_invoiceString($arExtend = array() ){ if (strlen($arExtend['CustomerPhone']) > 20) array_push($arErrors, "CustomerPhone max length as 20."); } - // 客戶信箱CustomerEmail + // 客戶信箱CustomerEmail if(!array_key_exists('CustomerEmail', $arExtend)){ $arExtend['CustomerEmail'] = ''; }else{ @@ -1073,7 +1073,7 @@ public function check_invoiceString($arExtend = array() ){ //課稅類別 TaxType(不可為空) if (strlen($arExtend['TaxType']) == 0) array_push($arErrors, "TaxType is required."); - + //通關方式 ClearanceMark(預設為空字串) if(!array_key_exists('ClearanceMark', $arExtend)) { $arExtend['ClearanceMark'] = ''; @@ -1086,7 +1086,7 @@ public function check_invoiceString($arExtend = array() ){ array_push($arErrors, "Please remove ClearanceMark."); } } - + // CarruerNum(預設為空字串) if (!array_key_exists('CarruerNum', $arExtend)) { $arExtend['CarruerNum'] = ''; @@ -1131,13 +1131,13 @@ public function check_invoiceString($arExtend = array() ){ } //備註 InvoiceRemark(UrlEncode, 預設為空字串) - if(!array_key_exists('InvoiceRemark', $arExtend)) $arExtend['InvoiceRemark'] = ''; - + if(!array_key_exists('InvoiceRemark', $arExtend)) $arExtend['InvoiceRemark'] = ''; + // 延遲天數 DelayDay(不可為空, 預設為0) 延遲天數,範圍0~15,設定為0時,付款完成後立即開立發票 if(!array_key_exists('DelayDay', $arExtend)) $arExtend['DelayDay'] = 0 ; if ($arExtend['DelayDay'] < 0 or $arExtend['DelayDay'] > 15) array_push($arErrors, "DelayDay should be 0 ~ 15."); - - + + // 字軌類別 InvType(不可為空) if (!array_key_exists('InvType', $arExtend)) array_push($arErrors, "InvType is required."); @@ -1168,7 +1168,7 @@ public function check_invoiceString($arExtend = array() ){ array_push($tmpItemTaxType, $tmpItemInfo['TaxType']); } } - + if ($arExtend['TaxType'] == TaxType::Mix) { if (in_array(TaxType::Dutiable, $tmpItemTaxType) and in_array(TaxType::Free, $tmpItemTaxType)) { // Do nothing @@ -1184,10 +1184,10 @@ public function check_invoiceString($arExtend = array() ){ $arExtend['InvoiceItemTaxType'] = implode($InvSptr, $tmpItemTaxType); } - unset($arExtend['InvoiceItems']); + unset($arExtend['InvoiceItems']); } - + $encode_fields = array( 'CustomerName', 'CustomerAddr', @@ -1229,7 +1229,7 @@ class allPay_CVS extends Verification //檢查共同參數 function check_string($arParameters = array()){ parent::check_string($arParameters); - if (!$arParameters['PlatformID']) unset($arParameters['PlatformID']); + if (!$arParameters['PlatformID']) unset($arParameters['PlatformID']); unset($arParameters['IgnorePayment']); return $arParameters ; } @@ -1246,7 +1246,7 @@ function check_extend_string($arExtend = array(),$InvoiceMark = ''){ return $arExtend ; } - + //過濾多餘參數 function filter_string($arExtend = array(),$InvoiceMark = '') { @@ -1290,7 +1290,7 @@ function check_goods($arParameters = array()){ /** -* 付款方式 : BARCODE +* 付款方式 : BARCODE */ class allPay_BARCODE extends Verification { @@ -1307,11 +1307,11 @@ class allPay_BARCODE extends Verification //檢查共同參數 function check_string($arParameters = array()){ parent::check_string($arParameters); - if (!$arParameters['PlatformID']) unset($arParameters['PlatformID']); + if (!$arParameters['PlatformID']) unset($arParameters['PlatformID']); unset($arParameters['IgnorePayment']); return $arParameters ; } - + //檢查BARCODE的延伸參數 function check_extend_string($arExtend = array(),$InvoiceMark = ''){ @@ -1325,7 +1325,7 @@ function check_extend_string($arExtend = array(),$InvoiceMark = ''){ return $arExtend ; } - + //過濾多餘參數 function filter_string($arExtend = array(),$InvoiceMark = '') { @@ -1381,7 +1381,7 @@ class allPay_ATM extends Verification //檢查共同參數 function check_string($arParameters = array()){ parent::check_string($arParameters); - if (!$arParameters['PlatformID']) unset($arParameters['PlatformID']); + if (!$arParameters['PlatformID']) unset($arParameters['PlatformID']); unset($arParameters['IgnorePayment']); return $arParameters ; } @@ -1392,13 +1392,13 @@ function check_extend_string($arExtend = array(),$InvoiceMark = ''){ foreach ($this->arPayMentExtend as $key => $value) { if(!isset($arExtend[$key])) $arExtend[$key] = $value; } - + //若有開發票,檢查一下發票參數 if($InvoiceMark == 'Y') $arExtend = $this->check_invoiceString($arExtend); return $arExtend ; } - + //過濾多餘參數 function filter_string($arExtend = array(),$InvoiceMark = '') { @@ -1448,11 +1448,11 @@ function check_goods($arParameters = array()){ class allPay_WebATM extends Verification { public $arPayMentExtend = array(); - + //檢查共同參數 function check_string($arParameters = array()){ parent::check_string($arParameters); - if (!$arParameters['PlatformID']) unset($arParameters['PlatformID']); + if (!$arParameters['PlatformID']) unset($arParameters['PlatformID']); unset($arParameters['IgnorePayment']); return $arParameters ; } @@ -1463,13 +1463,13 @@ function check_extend_string($arExtend = array(),$InvoiceMark = ''){ foreach ($this->arPayMentExtend as $key => $value) { if(!isset($arExtend[$key])) $arExtend[$key] = $value; } - + //若有開發票,檢查一下發票參數 if($InvoiceMark == 'Y') $arExtend = $this->check_invoiceString($arExtend); return $arExtend ; } - + //過濾多餘參數 function filter_string($arExtend = array(),$InvoiceMark = '') { @@ -1528,7 +1528,7 @@ class allPay_Alipay extends Verification //檢查共同參數 function check_string($arParameters = array()){ parent::check_string($arParameters); - if (!$arParameters['PlatformID']) unset($arParameters['PlatformID']); + if (!$arParameters['PlatformID']) unset($arParameters['PlatformID']); unset($arParameters['IgnorePayment']); return $arParameters ; } @@ -1545,13 +1545,13 @@ function check_extend_string($arExtend = array(),$InvoiceMark = ''){ } if(sizeof($arErrors)>0) throw new Exception(join('
', $arErrors)); - + //若有開發票,檢查一下發票參數 if($InvoiceMark == 'Y') $arExtend = $this->check_invoiceString($arExtend); return $arExtend ; } - + //過濾多餘參數 function filter_string($arExtend = array(),$InvoiceMark = '') { @@ -1569,7 +1569,7 @@ function check_goods($arParameters = array()){ $arErrors = array(); $szAlipayItemName = ''; $szAlipayItemCounts = ''; - $szAlipayItemPrice = ''; + $szAlipayItemPrice = ''; if (sizeof($arParameters['Items']) > 0) { foreach ($arParameters['Items'] as $keys => $value) { $szItemName .= vsprintf('#%s %d %s x %u', $arParameters['Items'][$keys]); @@ -1618,28 +1618,28 @@ function check_goods($arParameters = array()){ class allPay_Tenpay extends Verification { public $arPayMentExtend = array('ExpireTime' => ''); - + //檢查共同參數 function check_string($arParameters = array()){ parent::check_string($arParameters); - if (!$arParameters['PlatformID']) unset($arParameters['PlatformID']); + if (!$arParameters['PlatformID']) unset($arParameters['PlatformID']); unset($arParameters['IgnorePayment']); return $arParameters ; } - + //檢查Tenpay的延伸參數 function check_extend_string($arExtend = array(),$InvoiceMark = ''){ //沒設定參數的話,就給預設參數 foreach ($this->arPayMentExtend as $key => $value) { if(!isset($arExtend[$key])) $arExtend[$key] = $value; } - + //若有開發票,檢查一下發票參數 if($InvoiceMark == 'Y') $arExtend = $this->check_invoiceString($arExtend); return $arExtend ; } - + //過濾多餘參數 function filter_string($arExtend = array(),$InvoiceMark = '') { @@ -1687,19 +1687,19 @@ class allPay_Credit extends Verification { public $arPayMentExtend = array( "CreditInstallment" => 0, - "InstallmentAmount" => 0, - "Redeem" => FALSE, + "InstallmentAmount" => 0, + "Redeem" => FALSE, "UnionPay" => FALSE, "Language" => '', "PeriodAmount" => '', - "PeriodType" => '', - "Frequency" => '', + "PeriodType" => '', + "Frequency" => '', "ExecTimes" => '' ); //檢查共同參數 function check_string($arParameters = array()){ parent::check_string($arParameters); - if (!$arParameters['PlatformID']) unset($arParameters['PlatformID']); + if (!$arParameters['PlatformID']) unset($arParameters['PlatformID']); unset($arParameters['IgnorePayment']); return $arParameters ; } @@ -1708,14 +1708,14 @@ function check_extend_string($arExtend = array(),$InvoiceMark = ''){ foreach ($this->arPayMentExtend as $key => $value) { if(!isset($arExtend[$key])) $arExtend[$key] = $value; } - + //若有開發票,檢查一下發票參數 if($InvoiceMark == 'Y') $arExtend = $this->check_invoiceString($arExtend); return $arExtend ; } function filter_string($arExtend = array(),$InvoiceMark = ''){ - + $arPayMentExtend = ($InvoiceMark == '')? array_keys($this->arPayMentExtend) : array_merge(array_keys($this->arPayMentExtend),$this->arInvoice); foreach ($arExtend as $key => $value) { if (!in_array($key,$arPayMentExtend )) { @@ -1763,11 +1763,11 @@ class allPay_TopUpUsed extends Verification //檢查共同參數 function check_string($arParameters = array()){ parent::check_string($arParameters); - if (!$arParameters['PlatformID']) unset($arParameters['PlatformID']); + if (!$arParameters['PlatformID']) unset($arParameters['PlatformID']); unset($arParameters['IgnorePayment']); return $arParameters ; } - + //檢查延伸參數 function check_extend_string($arExtend = array(),$InvoiceMark = ''){ //若有開發票,檢查一下發票參數 @@ -1813,11 +1813,11 @@ function check_goods($arParameters = array()){ class allPay_ALL extends Verification { public $arPayMentExtend = array(); - + //檢查共同參數 function check_string($arParameters = array()){ parent::check_string($arParameters); - if (!$arParameters['PlatformID']) unset($arParameters['PlatformID']); + if (!$arParameters['PlatformID']) unset($arParameters['PlatformID']); return $arParameters ; } @@ -1890,28 +1890,28 @@ class CheckMacValue{ static function generate($arParameters = array(),$HashKey = '' ,$HashIV = '',$encType = 0){ $sMacValue = '' ; - + if(isset($arParameters)) - { + { unset($arParameters['CheckMacValue']); // 資料排序 php 5.3以下不支援 uksort($arParameters, array('CheckMacValue','merchantSort')); - + // 組合字串 $sMacValue = 'HashKey=' . $HashKey ; foreach($arParameters as $key => $value) { $sMacValue .= '&' . $key . '=' . $value ; } - - $sMacValue .= '&HashIV=' . $HashIV ; - - // URL Encode編碼 - $sMacValue = urlencode($sMacValue); - + + $sMacValue .= '&HashIV=' . $HashIV ; + + // URL Encode編碼 + $sMacValue = urlencode($sMacValue); + // 轉成小寫 - $sMacValue = strtolower($sMacValue); - + $sMacValue = strtolower($sMacValue); + // 取代為與 dotNet 相符的字元 $sMacValue = str_replace('%2d', '-', $sMacValue); $sMacValue = str_replace('%5f', '_', $sMacValue); @@ -1920,14 +1920,14 @@ static function generate($arParameters = array(),$HashKey = '' ,$HashIV = '',$en $sMacValue = str_replace('%2a', '*', $sMacValue); $sMacValue = str_replace('%28', '(', $sMacValue); $sMacValue = str_replace('%29', ')', $sMacValue); - + // 編碼 switch ($encType) { case EncryptType::ENC_SHA256: // SHA256 編碼 $sMacValue = hash('sha256', $sMacValue); break; - + case EncryptType::ENC_MD5: default: // MD5 編碼 @@ -1935,8 +1935,8 @@ static function generate($arParameters = array(),$HashKey = '' ,$HashIV = '',$en } $sMacValue = strtoupper($sMacValue); - } - + } + return $sMacValue ; } /** @@ -1950,4 +1950,4 @@ private static function merchantSort($a,$b) } -?> \ No newline at end of file +?>