DIBS支付前执行MD5操作及PHP触发MD5计算函数求助
Hey there! As someone who’s worked through DIBS payment integrations before, let’s break this down simply so you can get that MD5 calculation working smoothly before your payment form submits. The critical thing here is to compute the MD5 hash on your server first (never expose your key1 and key2 in frontend code—they’re secret!) and pass it to your HTML form as a hidden field.
Step 1: Compute the MD5 Hash in PHP
First, let’s make sure your PHP code is set up with all the right values. Replace the placeholders with your actual DIBS credentials and order details:
// Replace these with your real DIBS info and order data $yourMerchantID = 'YOUR_MERCHANT_ID'; $yourOrderID = 'UNIQUE_ORDER_NUMBER'; // Generate this dynamically for each order $yourCurrency = 'SEK'; // Use your preferred currency code (e.g., EUR, USD) $yourAmount = '1000'; // Amount in the smallest unit (1000 = 10.00 SEK) $key1 = 'YOUR_DIBS_KEY1'; $key2 = 'YOUR_DIBS_KEY2'; // Build the parameter string exactly as DIBS requires $parameter_string = ''; $parameter_string .= 'merchant=' . $yourMerchantID; $parameter_string .= '&orderid=' . $yourOrderID; $parameter_string .= '¤cy=' . $yourCurrency; $parameter_string .= '&amount=' . $yourAmount; // Calculate the nested MD5 key per DIBS instructions $md5key = md5($key2 . md5($key1 . $parameter_string));
Heads up: Don’t mix up the order of
key1,key2, and the parameter string—DIBS’ validation depends on this exact nesting!
Step 2: Add the MD5 Hash to Your HTML Form
Now, insert the computed $md5key as a hidden input into your DIBS payment form. This way, when the form submits, the hash is sent along with all other payment data to DIBS:
<form id="payment-form" action="https://payment.archive.dibspayment.com/payment/dbw/" method="POST"> <!-- Hidden fields with your order and merchant data --> <input type="hidden" name="merchant" value="<?php echo $yourMerchantID; ?>"> <input type="hidden" name="orderid" value="<?php echo $yourOrderID; ?>"> <input type="hidden" name="currency" value="<?php echo $yourCurrency; ?>"> <input type="hidden" name="amount" value="<?php echo $yourAmount; ?>"> <!-- The pre-computed MD5 key (critical for DIBS validation) --> <input type="hidden" name="md5key" value="<?php echo $md5key; ?>"> <!-- Your submit button --> <button type="submit">Pay Now</button> </form>
Quick Tips for PHP Newbies
- Keep keys secret: Never put
key1orkey2in JavaScript or frontend code—anyone could steal them. Always do the MD5 calculation server-side. - Dynamic values: For real orders, generate
$yourOrderID,$yourAmount, etc., from your database or shopping cart (don’t hardcode them like in the example). - Test first: Use DIBS’ test environment to double-check the hash works before going live—this saves you headaches later!
That’s all there is to it! When your user clicks "Pay Now", the form sends all the required data (including the pre-computed MD5 key) to DIBS, which will validate the hash to make sure the payment request hasn’t been tampered with.
内容的提问来源于stack exchange,提问作者Kuanl

