php 网上支付讲座
先看一个实际的案例
我们给大家演示一个我自己开发的一个网上支付平台.
目前两种支付方式
1. 直接和银行对接
缺点是工作量大,而且需要资格审核
优点安全
2. 和中间公司对接
*缺点就是安全隐患
*优点就是开发维护方便
巴巴运动网和易宝支付网关 uml 图
我们实际来开发一个自己的网上支付平台
1 前提: 需要我们商家到易宝公司去注册账号
目前我们使用 yeebay 公司提供了用于测试的账号和密钥
账号 :$p1_MerId = "10001126856";
密钥: $merchantKey =
"69cl522AV6q613Ii4W6u8K6XuW8vM1N6bFgyv769220IuYe9u37N4y7rI4Pl";
2 开发界面
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=gb2312"/>
</head>
<form action="payConfirm.php" method="post">
<table>
<tr>
<td colspan="4">
订单号:<input type="text" name="p2_Order"/>
支付金额:<input type="text" name="p3_Amt"/></td>
</tr>
<tr><td colspan="4">请选择支付银行</td></tr>
<tr>
<td><input type="radio" name="pd_FrpId" value="CMBCHINA-NET"/>招商银行</td>
<td><input type="radio" name="pd_FrpId" value="ICBC-NET"/>工商银行</td>
<td><input type="radio" name="pd_FrpId" value="ABC-NET"/>农业银行</td>
<td><input type="radio" name="pd_FrpId" value="CCB-NET"/>建设银行</td>
</tr>
<tr>
<td colspan="4"><input type="submit" value="确认支付"/></td>
</tr>
</table>
</form>
</html>
3 如何生成一个 hmac 签名串.
这里我们要求大家会用即可:
关键代码:
function HmacMd5($data,$key){
// RFC 2104 HMAC implementation for php.
// Creates an md5 HMAC.
// Eliminates the need to install mhash to compute a HMAC
// Hacked by Lance Rushing(NOTE: Hacked means written)
//需要配置环境支持 iconv,否则中文参数不能正常处理
$key = iconv("GB2312","UTF-8",$key);
$data = iconv("GB2312","UTF-8",$data);
$b = 64; // byte length for md5
if (strlen($key) > $b) {
$key = pack("H*",md5($key));
}
$key = str_pad($key, $b, chr(0x00));
$ipad = str_pad('', $b, chr(0x36));
$opad = str_pad('', $b, chr(0x5c));
$k_ipad = $key ^ $ipad ;
$k_opad = $key ^ $opad;
return md5($k_opad . pack("H*",md5($k_ipad . $data)));}
4 开发确认支付页面
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=gb2312"/>
</head>
<?php
include_once 'Common.php';
//这里我们获取用户提交的信息
//1.获取订单号
$p0_Cmd="Buy";
$p1_MerId="10001126856";
$p2_Order=$_REQUEST['p2_Order'];
$p3_Amt=$_REQUEST['p3_Amt'];
$p4_Cur="CNY";
//商品名称
$p5_Pid="";
$p6_Pcat="";//种类
$p7_Pdesc="";//商品介绍
//这是易宝支付成功后,给 url 返回信息
$p8_Url="http://localhost:80/myNetPayment/res.php";
$p9_SAF="0";
$pa_MP="";
$pd_FrpId=$_REQUEST['pd_FrpId'];
$pr_NeedResponse="1";
- 1
- 2
- 3
- 4
前往页