iT邦幫忙

0

form所需要的一些變數及計算.

php

麻煩各位,另外我在同時共有數篇都是環繞於此主題(一系列)的發問。
主題: 如何在送出以下form資料前先產生需要的數值, 再將數值填入需要的value中。

日期格式:"2014/02/24 01:58:00"
在載入此php時需要先:
1.當時的日期載入到變數$time_now中
2.並隨機產生10位'數字'變數到$my_tradeno
3.生成CheckMacValue到變數$test1234(下面會講解如何生成)
然後不清楚如何將上面變數放到下面的value中?

<form id="form" action="http://payment-stage.xxxxxx.com.tw/Cashier/AioCheckOut" method="post" target="_self">
<input type="hidden" value="ALL" name="ChoosePayment">
<input type="hidden" value="300dm" name="ItemName">
<input type="hidden" value="2000132" name="MerchantID">
<input type="hidden" value="$time_now" name="MerchantTradeDate">
<input type="hidden" value="$my_tradeno" name="MerchantTradeNo">
<input type="hidden" value="aio" name="PaymentType">
<input type="hidden" value="http://www.xxxxx.tw/success.php" name="ReturnURL">
<input type="hidden" value="150" name="TotalAmount">
<input type="hidden" value="novatest" name="TradeDesc">
<input type="hidden" value="$test123" name="CheckMacValue">
<input type="submit" name="auto" value="跳轉" alt="跳轉中">  
</form>

除此之外比較頭痛的就是上面的CheckMacValue, 此數值的計算為如下
步驟一, 先組合好如下

HashKey=A123456789012345&ChoosePayment=ALL&ItemName=300dm&MerchantID=2000132&MerchantTradeDate=這裡要填入$time_now&MerchantTradeNo=這裡要填入$my_tradeno&PaymentType=aio&ReturnURL=http://www.xnova.tw/paypal_success.php&TotalAmount=150&TradeDesc=novatest&HashIV=B123456789012345

至於前後的HashKey跟HashIV也是要加入於計算之中(此兩數值為固定值),

步驟二, 將以上的數值UrlEncode編碼後轉為小寫 (下面就用以上代碼來舉例)

HashKey%3dA123456789012345%26ChoosePayment%3dALL%26ItemName%3d300dm%26MerchantID%3d2000132%26MerchantTradeDate%3d%e9%80%99%e8%a3%a1%e8%a6%81%e5%a1%ab%e5%85%a5%24time_now%26MerchantTradeNo%3d%e9%80%99%e8%a3%a1%e8%a6%81%e5%a1%ab%e5%85%a5%24my_tradeno%26PaymentType%3daio%26ReturnURL%3dhttp%3a%2f%2fwww.xnova.tw%2fpaypal_success.php%26TotalAmount%3d150%26TradeDesc%3dnovatest%26HashIV%3dB123456789012345

步驟三四 見下樓

fillano iT邦超人 1 級 ‧ 2014-02-24 11:55:50 檢舉
歐付寶喔...
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
fillano
iT邦超人 1 級 ‧ 2014-02-24 12:01:10

你是拿歐付寶(綠界)的金流API來練PHP喔...

這樣:

<pre class="c" name="code"><input type="hidden" value="<?=$test123?>" name="CheckMacValue"> 

請參考:http://www.php.net/manual/en/language.basic-syntax.phptags.php

我要發表回答

立即登入回答