iT邦幫忙

0

藍新金流 - 智付通API串接

1.創建商店:註冊->登入->會員中心->商店管理->開立商店設定/商店資料設定
2.獲取商店資料:銷售中心->模擬交易

重要串接資料

https://core.newebpay.com/MPG/mpg_gateway
MerchantID
HashKey
HashIV

<適用所有支付方式Post參數>

MerchantID
TradeInfo
TradeSha
Version

<TradeInfo內含參數>

MerchantID
RespondType
TimeStamp
LangType
MerchantOrderNo
Amt
ItemDesc
Email
LoginType
Version

<放置網頁頂部>

<?php
  // 正式串接網址 https://core.newebpay.com/MPG/mpg_gateway
  // MerchantID: MS1422390428
  // HashKey:123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
  // HashIV:abcdefg12345ABCDEFG
  
  $Money = '1600';
  $date_now = gmdate('Y-m-d H:i:s',strtotime('+8 hours'));
  $date_now = strtotime($date_now);
  $ItemDesc = '入會費';
  $Email = 'e490318@gmail.com';
  $MerchantID = 'MS1422390428'; 

 $trade_info_arr = array(
  'MerchantID' => $MerchantID,
  'RespondType' => 'JSON',
  'TimeStamp' => $date_now,
  'Version' => 1.5,
  'MerchantOrderNo' => $date_now,
  'Amt' => $Money,
  'ItemDesc' => $ItemDesc
  );
  $mer_key = '123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  $mer_iv = 'abcdefg12345ABCDEFG';

  //交易資料經 AES 加密後取得 TradeInfo
  $TradeInfo = create_mpg_aes_encrypt($trade_info_arr, $mer_key, $mer_iv);
  $sha256 = strtoupper(hash("sha256","HashKey=$mer_key&".$TradeInfo."&HashIV=$mer_iv")); 
?>

<form表單範例Basic>

<form name='Spgateway' method='post' action='https://core.newebpay.com/MPG/mpg_gateway'> 
<input type='hidden' id='MerchantID' name='MerchantID' value='MS1422390428'>
<input type='hidden' id='TradeInfo' name='TradeInfo' value='<?php echo $TradeInfo;?>'>
<input type='hidden' id='TradeSha' name='TradeSha' value='<?php echo $sha256;?>'>
<input type='hidden' id='RespondType' name='RespondType' value='JSON'>
<input type='hidden' id='TimeStamp' name='TimeStamp' value='<?php echo $date_now;?>'>
<input type='hidden' id='Version' name='Version' value='1.4'>
<input type='hidden' id='MerchantOrderNo' name='MerchantOrderNo' value='<?php echo $date_now;?>'>
<input type='hidden' id='Amt' name='Amt' value='<?php echo $Money;?>'>
<input type='hidden' id='ItemDesc' name='ItemDesc' value='<?php echo $ItemDesc;?>'>
<input type='hidden' id='Email' name='Email' value='<?php echo $Email?>'>
<input type='hidden' id='LoginType' name='LoginType' value='no'>
</form>

<form表單範例Dev>

<form name='Spgateway' method='post' action='https://core.newebpay.com/MPG/mpg_gateway'> 
  <h3>MERCHANT INFO</h3>
  MerchantID:<input type='text' id='MerchantID' name='MerchantID' disabled="disabled" value='MS1422390428'></br>
  TradeInfo:<input type='text' id='TradeInfo' name='TradeInfo' disabled="disabled" value='<?php echo $TradeInfo;?>'></br>
  TradeSha:<input type='text' id='TradeSha' name='TradeSha' disabled="disabled" value='<?php echo $sha256;?>'></br>
  RespondType:<input type='text' id='RespondType' name='RespondType' disabled="disabled" value='JSON'></br>
  TimeStamp:<input type='text' id='TimeStamp' name='TimeStamp' disabled="disabled"  value='<?php echo $date_now;?>'></br>
  Version:<input type='text' id='Version' name='Version' disabled="disabled" value='1.5'></br></br>
  <h3>TRADE INFO</h3>
  MerchantOrderNo:<input type='number' id='MerchantOrderNo' name='MerchantOrderNo' disabled="disabled" value='<?php echo $date_now;?>'></br>
  Amt:<input type='number' id='Amt' name='Amt' value='<?php echo $Money;?>'></br>
  ItemDesc:<input type='text' id='ItemDesc' name='ItemDesc' value='<?php echo $ItemDesc;?>'></br>
  Email:<input type='email' id='Email' name='Email' value='<?php echo $Email?>'></br>
  LoginType:<input type='text' id='LoginType' name='LoginType' disabled="disabled" value='no'></br>
  <input id="submit" type='submit' value='Submit'>
</form>

//靠程式解除disabled後台才能收到數值
<script type="text/javascript">
$("#submit").click(function(){
  $("input").prop("disabled",false);
});
</script>

<簡易資料檢視>

<!--<?php
  echo "<h3>INPUT DETAIL:</h3>";
  echo "TradeInfo: <br>".$TradeInfo."<br><br>";
  echo "Sha256: <br>".$sha256."<br><br>";
  echo "Date_now: <br>".$date_now."<br><br>";
  echo "Money: <br>".$Money."<br><br>";
?>-->

<放置網頁底部>

<?php
/**
 * AES 加密範例
 */

function create_mpg_aes_encrypt ($parameter = "" , $key = "", $iv = "") {
 $return_str = '';
 if (!empty($parameter)) {
 //將參數經過 URL ENCODED QUERY STRING
 $return_str = http_build_query($parameter);
 }
 return trim(bin2hex(openssl_encrypt(addpadding($return_str), 'aes-256-cbc', $key, OPENSSL_RAW_DATA|OPENSSL_ZERO_PADDING, $iv)));
}

function addpadding($string, $blocksize = 32) {
  $len = strlen($string);
  $pad = $blocksize - ($len % $blocksize);
  $string .= str_repeat(chr($pad), $pad);
  return $string;
}
 
?>

1 則留言

3
screenleon
iT邦新手 4 級 ‧ 2021-01-13 10:34:47

雖然我不知道你那組API使用的參數是不是測試用
但請注意不要把他們丟上來(註解也一樣),只要示意就可以了

Javen Lin iT邦新手 5 級 ‧ 2021-01-18 01:08:36 檢舉

Ok 感謝 已修正!

我要留言

立即登入留言