蓝新金流 - 智付通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 = '[email protected]';
  $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;
}
 
?>

<参考来源>

智付通API 程序串接的示范(程序教学)
(作者:AppMate 你有APP了吗?)
https://www.youtube.com/watch?v=5QW6OoJgxVc&list=PLRd4vZfEurYh2uM37ruvV-9w0Kr49DVOE&index=1&t=1330s

蓝新金流API文件
https://www.newebpay.com/website/Page/content/download_api


<<:  【Debug】PHP Key-Value 输入格式错误

>>:  [python 爬虫] 美金_欧元 半年走势

iOS Swift TodoList ( 画面部分 no code ) Part1

前言: 哈罗~~此篇是我第一篇文,跟其他人一样纪录程序学习过程,而swift也是我最近在学习的新语言...

Day 21 - 网际网路的运行

今天,我们来聊一下网路世界中的运行方式。 先提前说,这篇跟 HomeLab 其实就没有特别大的关系了...

Day22 切版笔记- 互动图文卡片

运用到的观念: 利用vertical-align: middle;调整图片预设多余的空间 使用po...

[第十五只羊] 迷雾森林舞会IX 玩家加入房间

天亮了 昨晚1号玩家被杀死了 关於迷雾森林故事 杂讯 洛神:昨晚1号玩家被杀死了,1号玩家发动角色技...

Day 20 : 案例分享(6.3) 人事、差勤与薪资 - 线上请休假及签到退

案例说明及适用场景 实务上的运用,设定员工的假别及特休假,是需要个别设定 虽较为麻烦提但搭配odoo...