Vik*_*han 1 php md5 authorize.net payment-gateway sha512
我正在将DPM的md5更新为sha512,请为我提供帮助-
我没有工作。
查看代码更改-
为x_hp_hash生成指纹时-
来自md5-
if (function_exists('hash_hmac')) {
return hash_hmac("md5", $api_login_id . "^" . $fp_sequence . "^" .
$fp_timestamp . "^" . $amount . "^", $transaction_key);
}
return bin2hex(mhash(MHASH_MD5, $api_login_id . "^" . $fp_sequence . "^" . $fp_timestamp . "^" . $amount . "^", $transaction_key));
Run Code Online (Sandbox Code Playgroud)
至sha512-
$signature_key = hex2bin($signature_key);
if (function_exists('hash_hmac')) {
return hash_hmac("sha512", $api_login_id . "^" . $fp_sequence . "^" .
$fp_timestamp . "^" . $amount . "^", $signature_key);
}
return bin2hex(mhash(MHASH_SHA512, $api_login_id . "^" . $fp_sequence . "^" . $fp_timestamp . "^" . $amount . "^", $signature_key));
Run Code Online (Sandbox Code Playgroud)
在获得响应并比较md5中的x_sha_hash值时-
if(strtoupper(md5($this->md5_setting . $this->api_login_id . $this
->transaction_id . $amount)) == $this->md5_hash){
//valid
} else{
//not valid
}
Run Code Online (Sandbox Code Playgroud)
更改为sha512-
$this->signature_key = hex2bin($this->signature_key);
$string = '^'.$this->api_login_id.'^'.$this->transaction_id.'^'.$amount.'^';
if(strtoupper(HASH_HMAC('sha512', $string, $this->signature_key)) == $this->SHA2_Hash){
//valid
} else{
//not valid
}
Run Code Online (Sandbox Code Playgroud)
我做错了什么?在我最后验证交易时,是说请检查您的md5设置。它根据代码段中显示的最后一个代码进行验证。
我的签名密钥= E284BDC12A45A7F5B0933A352EB1C3F25E91A3B92360693D94E4366190EF12E78F6CFE8601751F719DA7A72ABBA117BF0161F8A1DD894DADE3C56A838D8355AD
x_hp_hash提交使用所述第二代码段(即SHA512指纹)x_hp_hash = b4c9e1878f88aa9c4f808761ed8ceee71ab117cc0f1297b2d850e28351f08fc52bd528a7538c832568c674a1d5095ead1a5383a626c9797587ab16bae76e45fb
提交回应后-
X_SHA2_Hash-19AB7947709CF6CB2B8415784EBD7669FCDE5D83B69EC8C716203806A3235308187668F5783F9CA0F1AE8A47808EDAB241025A8AF61A2FABC27FA6AAAEA8FFD8
生成的哈希码-3E6427E67271B1F0732D3D95217D25EE4D7C4103C906A6CB70943498698157F48F7BECD5C7E5393CF2A489B464070A7778F15757385E8F29029CFC3F66256F05
使用上面的最后一个片段。
所以这些不相等,因此不是有效的交易。
我知道了
而不是仅使用以下三个字段
$ api_login_id
$ transaction_id
$ amount;
我必须使用以下所有字段,请参阅-
$hashData = implode('^', [
$_POST['x_trans_id'],
$_POST['x_test_request'],
$_POST['x_response_code'],
$_POST['x_auth_code'],
$_POST['x_cvv2_resp_code'],
$_POST['x_cavv_response'],
$_POST['x_avs_code'],
$_POST['x_method'],
$_POST['x_account_number'],
$_POST['x_amount'],
$_POST['x_company'],
$_POST['x_first_name'],
$_POST['x_last_name'],
$_POST['x_address'],
$_POST['x_city'],
$_POST['x_state'],
$_POST['x_zip'],
$_POST['x_country'],
$_POST['x_phone'],
$_POST['x_fax'],
$_POST['x_email'],
$_POST['x_ship_to_company'],
$_POST['x_ship_to_first_name'],
$_POST['x_ship_to_last_name'],
$_POST['x_ship_to_address'],
$_POST['x_ship_to_city'],
$_POST['x_ship_to_state'],
$_POST['x_ship_to_zip'],
$_POST['x_ship_to_country'],
$_POST['x_invoice_num'],
]);
$hash = hash_hmac('sha512', '^'.$hashData.'^', hex2bin($signatureKey));
$hash = strtoupper($hash);
if($this->SHA2_Hash === $hash) {
//valid
}
Run Code Online (Sandbox Code Playgroud)
因此,请使用authorize.net的所有x_fields生成哈希码