Rumah > pembangunan bahagian belakang > tutorial php > 易宝网上支付平台的PHP接口代码

易宝网上支付平台的PHP接口代码

WBOY
Lepaskan: 2016-08-08 09:23:20
asal
1607 orang telah melayarinya

本代码参照自韩顺平149讲视频后5讲,需要学习的朋友可以参考本代码

这是测试图片:

以下是代码部分:

<span> 1</span> <span>php
</span><span> 2</span><span> 3</span><span> 4</span><span>function</span> HmacMd5(<span>$data</span>, <span>$key</span><span>)
</span><span> 5</span><span>{
</span><span> 6</span><span> 7</span><span>//</span><span>需要配置环境支撑iconv,否则中文参数不能正常处理</span><span> 8</span><span>$key</span> = <span>iconv</span>("GB2312", "UTF-8", <span>$key</span><span>);
</span><span> 9</span><span>$data</span> = <span>iconv</span>("GB2312", "UTF-8", <span>$data</span><span>);
</span><span>10</span><span>$b</span> = 64<span>;
</span><span>11</span><span>if</span> (<span>strlen</span>(<span>$key</span>) > <span>$b</span><span>) {
</span><span>12</span><span>$key</span> = <span>pack</span>("H*", <span>md5</span>(<span>$key</span><span>));
</span><span>13</span><span>    }
</span><span>14</span><span>$key</span> = <span>str_pad</span>(<span>$key</span>, <span>$b</span>, <span>chr</span>(0x00<span>));
</span><span>15</span><span>$ipad</span> = <span>str_pad</span>('', <span>$b</span>, <span>chr</span>(0x36<span>));
</span><span>16</span><span>$opad</span> = <span>str_pad</span>('', <span>$b</span>, <span>chr</span>(0x5c<span>));
</span><span>17</span><span>$k_ipad</span> = <span>$key</span> ^ <span>$ipad</span><span>;
</span><span>18</span><span>$k_opad</span> = <span>$key</span> ^ <span>$opad</span><span>;
</span><span>19</span><span>return</span><span>md5</span>(<span>$k_opad</span> . <span>pack</span>("H*", <span>md5</span>(<span>$k_ipad</span> . <span>$data</span><span>)));
</span><span>20</span><span>}
</span><span>21</span><span>//</span><span>我们把易宝支付要求怎样生成一个签名串
</span><span>22</span><span>    //把各个请求参数凭借作为$data传入: $key 就是易宝给商家分配的密钥</span><span>23</span><span>24</span> ?>
Salin selepas log masuk
common.php

<span> 1</span> 
<span> 2</span> 
<span> 3</span> <meta http-equiv="content-type" c>
<span> 4</span> 
<span> 5</span> 
Salin selepas log masuk
6 7 81213141516171819202122232425
9 订单号: 10 支付金额: 11
请选择支付银行
招商银行 工商银行 农业银行 建设银行
26
27 pay.php

<span> 1</span> 
<span> 2</span> 
<span> 3</span> <meta http-equiv="content-type" c>
<span> 4</span> 
<span> 5</span> php
 6include 'common.php';
 7// 这里我们获取用户提交的信息
 8 9    // 1.获取订单号10$p0_Cmd = "Buy";
11$p1_MerId = "10001126856";
12$p2_Order = $_REQUEST['p2_Order'];
13$p3_Amt = $_REQUEST['p3_Amt'];
14$p4_Cur = "CNY";
15// 商品名称16$p5_Pid = "";
17$p6_Pcat = ""; // 商品种类18$p7_Pdesc = ""; // 商品介绍
19    // 只是易宝支付成功后,给url返回信息20$p8_Url = "http://loaclhost/FUCKPHP/onlinezhifu/res.php";
21$p9_SAF = "0"; // 送货地址22$pa_MP = ""; // 额外介绍23$pd_FrpId = $_REQUEST['pd_FrpId']; // 支付通道24$pr_NeedResponse = "1"; // 应答机制
25    // 我们把请求参数一个一个拼接(拼接的时候,顺序很重要!!)26$data="";
27$data=$data.$p0_Cmd;
28$data=$data.$p1_MerId;
29$data=$data.$p2_Order;
30$data=$data.$p3_Amt;
31$data=$data.$p4_Cur;
32$data=$data.$p5_Pid;
33$data=$data.$p6_Pcat;
34$data=$data.$p7_Pdesc;
35$data=$data.$p8_Url;
36$data=$data.$p9_SAF;
37$data=$data.$pa_MP;
38$data=$data.$pd_FrpId;
39$data=$data.$pr_NeedResponse;
4041$merchantKey ="69cl522AV6q613Ii4W6u8K6XuW8vM1N6bFgyv769220IuYe9u37N4y7rI4Pl";
42// hmac是签名串,是用于易宝和商家互相确认的关键字
43    // 这里我们需要使用算法来生成(md5-hmac算法)44$hmac = HmacMd5($data,$merchantKey);
45 ?>
46             你的订单号是:echo$p2_Order;  ?>支付的金额是echo$p3_Amt; ?>
47             
48 
Salin selepas log masuk
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
65 payConfirm.php

<span> 1</span> <span>php
</span><span> 2</span><span>include</span> 'common.php'<span>;
</span><span> 3</span><span>//</span><span>获取从易宝支付网关返回的信息</span><span> 4</span><span>$p1_MerId</span> = "10001126856"<span>;
</span><span> 5</span><span>$r0_Cmd</span> = <span>$_REQUEST</span>['r0_Cmd'<span>];
</span><span> 6</span><span>$r1_Code</span> = <span>$_REQUEST</span>['r1_Code'<span>];
</span><span> 7</span><span>$r2_TrxId</span> = <span>$_REQUEST</span>['r2_TrxId'<span>];
</span><span> 8</span><span>$r3_Amt</span> = <span>$_REQUEST</span>['r3_Amt'<span>];
</span><span> 9</span><span>$r4_Cur</span> = <span>$_REQUEST</span>['r4_Cur'<span>];
</span><span>10</span><span>$r5_Pid</span> = <span>$_REQUEST</span>['r5_Pid'<span>];
</span><span>11</span><span>$r6_Order</span> = <span>$_REQUEST</span>['r6_Order'<span>];
</span><span>12</span><span>$r7_Uid</span> = <span>$_REQUEST</span>['r7_Uid'<span>];
</span><span>13</span><span>$r8_MP</span> = <span>$_REQUEST</span>['r8_MP'<span>];
</span><span>14</span><span>$r9_BType</span> = <span>$_REQUEST</span>['r9_BType'<span>];
</span><span>15</span><span>$hmac</span> = <span>$_REQUEST</span>['hmac'<span>];
</span><span>16</span><span>17</span><span>//</span><span> 拼接</span><span>18</span><span>$res_src</span> = ""<span>;
</span><span>19</span><span>$res_src</span> = <span>$res_src</span> . <span>$p1_MerId</span><span>;
</span><span>20</span><span>$res_src</span> = <span>$res_src</span> . <span>$r0_Cmd</span><span>;
</span><span>21</span><span>$res_src</span> = <span>$res_src</span> . <span>$r1_Code</span><span>;
</span><span>22</span><span>$res_src</span> = <span>$res_src</span> . <span>$r2_TrxId</span><span>;
</span><span>23</span><span>$res_src</span> = <span>$res_src</span> . <span>$r3_Amt</span><span>;
</span><span>24</span><span>$res_src</span> = <span>$res_src</span> . <span>$r4_Cur</span><span>;
</span><span>25</span><span>$res_src</span> = <span>$res_src</span> . <span>$r5_Pid</span><span>;
</span><span>26</span><span>$res_src</span> = <span>$res_src</span> . <span>$r6_Order</span><span>;
</span><span>27</span><span>$res_src</span> = <span>$res_src</span> . <span>$r7_Uid</span><span>;
</span><span>28</span><span>$res_src</span> = <span>$res_src</span> . <span>$r8_MP</span><span>;
</span><span>29</span><span>$res_src</span> = <span>$res_src</span> . <span>$r9_BType</span><span>;
</span><span>30</span><span>$merchantKey</span> = "69c1522AV6q613Ii4W6u8K6XuW8vM1N6bFgyv769220IuYe9u37N4y7rI4P1"<span>;
</span><span>31</span><span>//</span><span> 对返回的结果进行MD5-hmac加密处理,和返回的hmac签名串比较</span><span>32</span><span>if</span> (HmacMd5(<span>$res_src</span>, <span>$merchantKey</span>) == <span>$hmac</span><span>) {
</span><span>33</span><span>if</span> (<span>$r1_Code</span> == 1<span>) {
</span><span>34</span><span>if</span> (<span>$r9_BType</span> == 1<span>) {
</span><span>35</span><span>echo</span> '交易成功!'<span>;
</span><span>36</span><span>echo</span> '订单号为' . <span>$r6_Order</span> . '支付成功!' . '所付金额是' . <span>$r3_Amt</span> . '易宝支付订单号' . <span>$r2_TrxId</span><span>;
</span><span>37</span><span>echo</span> '<br>浏览器重定向'<span>;
</span><span>38</span>             } <span>elseif</span> (<span>$r9_BType</span> == 2<span>) {
</span><span>39</span><span>echo</span> 'success'<span>;
</span><span>40</span><span>echo</span> '<br>交易成功!'<span>;
</span><span>41</span><span>echo</span> '<br>服务器点对点通讯'<span>;
</span><span>42</span><span>            }
</span><span>43</span><span>        }
</span><span>44</span>     } <span>else</span><span> {
</span><span>45</span><span>echo</span> '签名被篡改了'<span>;
</span><span>46</span><span>    }
</span><span>47</span><span>48</span> ?>
Salin selepas log masuk
res.php

以上就介绍了易宝网上支付平台的PHP接口代码,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan