ホームページ >バックエンド開発 >PHPチュートリアル >Yibaoオンライン決済プラットフォームのPHPインターフェースコード
このコードは、Han Shuping のビデオ講義 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> ?>common.php
<span> 1</span> <html> <span> 2</span> <head> <span> 3</span> <meta http-equiv="content-type" c /> <span> 4</span> </head> <span> 5</span> <form action="payConfirm.php" method="post"> <span> 6</span> <table> <span> 7</span> <tr> <span> 8</span> <td colspan="4"> <span> 9</span> 订单号:<input type="text" name="p2_Order" /> <span>10</span> 支付金额:<input type="text" name="p3_Amt" /> <span>11</span> </td> <span>12</span> </tr> <span>13</span> <tr> <span>14</span> <td colspan="4">请选择支付银行</td> <span>15</span> </tr> <span>16</span> <tr> <span>17</span> <td><input type="radio" name="pd_FrpId" value="CMBCHINA-NET-B2C" />招商银行</td> <span>18</span> <td><input type="radio" name="pd_FrpId" value="ICBC-NET-B2C" />工商银行</td> <span>19</span> <td><input type="radio" name="pd_FrpId" value="ABC-NET-B2C" />农业银行</td> <span>20</span> <td><input type="radio" name="pd_FrpId" value="CCB-NET-B2C" />建设银行</td> <span>21</span> </tr> <span>22</span> <tr> <span>23</span> <td colspan="4"><input type="submit" value="确认支付" /></td> <span>24</span> </tr> <span>25</span> </table> <span>26</span> </form> <span>27</span> </html>pay.php
<span> 1</span> <html> <span> 2</span> <head> <span> 3</span> <meta http-equiv="content-type" c /> <span> 4</span> </head> <span> 5</span> <?<span>php </span><span> 6</span><span>include</span> 'common.php'<span>; </span><span> 7</span><span>//</span><span> 这里我们获取用户提交的信息 </span><span> 8</span><span> 9</span><span> // 1.获取订单号</span><span>10</span><span>$p0_Cmd</span> = "Buy"<span>; </span><span>11</span><span>$p1_MerId</span> = "10001126856"<span>; </span><span>12</span><span>$p2_Order</span> = <span>$_REQUEST</span>['p2_Order'<span>]; </span><span>13</span><span>$p3_Amt</span> = <span>$_REQUEST</span>['p3_Amt'<span>]; </span><span>14</span><span>$p4_Cur</span> = "CNY"<span>; </span><span>15</span><span>//</span><span> 商品名称</span><span>16</span><span>$p5_Pid</span> = ""<span>; </span><span>17</span><span>$p6_Pcat</span> = ""; <span>//</span><span> 商品种类</span><span>18</span><span>$p7_Pdesc</span> = ""; <span>//</span><span> 商品介绍 </span><span>19</span><span> // 只是易宝支付成功后,给url返回信息</span><span>20</span><span>$p8_Url</span> = "http://loaclhost/FUCKPHP/onlinezhifu/res.php"<span>; </span><span>21</span><span>$p9_SAF</span> = "0"; <span>//</span><span> 送货地址</span><span>22</span><span>$pa_MP</span> = ""; <span>//</span><span> 额外介绍</span><span>23</span><span>$pd_FrpId</span> = <span>$_REQUEST</span>['pd_FrpId']; <span>//</span><span> 支付通道</span><span>24</span><span>$pr_NeedResponse</span> = "1"; <span>//</span><span> 应答机制 </span><span>25</span><span> // 我们把请求参数一个一个拼接(拼接的时候,顺序很重要!!)</span><span>26</span><span>$data</span>=""<span>; </span><span>27</span><span>$data</span>=<span>$data</span>.<span>$p0_Cmd</span><span>; </span><span>28</span><span>$data</span>=<span>$data</span>.<span>$p1_MerId</span><span>; </span><span>29</span><span>$data</span>=<span>$data</span>.<span>$p2_Order</span><span>; </span><span>30</span><span>$data</span>=<span>$data</span>.<span>$p3_Amt</span><span>; </span><span>31</span><span>$data</span>=<span>$data</span>.<span>$p4_Cur</span><span>; </span><span>32</span><span>$data</span>=<span>$data</span>.<span>$p5_Pid</span><span>; </span><span>33</span><span>$data</span>=<span>$data</span>.<span>$p6_Pcat</span><span>; </span><span>34</span><span>$data</span>=<span>$data</span>.<span>$p7_Pdesc</span><span>; </span><span>35</span><span>$data</span>=<span>$data</span>.<span>$p8_Url</span><span>; </span><span>36</span><span>$data</span>=<span>$data</span>.<span>$p9_SAF</span><span>; </span><span>37</span><span>$data</span>=<span>$data</span>.<span>$pa_MP</span><span>; </span><span>38</span><span>$data</span>=<span>$data</span>.<span>$pd_FrpId</span><span>; </span><span>39</span><span>$data</span>=<span>$data</span>.<span>$pr_NeedResponse</span><span>; </span><span>40</span><span>41</span><span>$merchantKey</span> ="69cl522AV6q613Ii4W6u8K6XuW8vM1N6bFgyv769220IuYe9u37N4y7rI4Pl"<span>; </span><span>42</span><span>//</span><span> hmac是签名串,是用于易宝和商家互相确认的关键字 </span><span>43</span><span> // 这里我们需要使用算法来生成(md5-hmac算法)</span><span>44</span><span>$hmac</span> = HmacMd5(<span>$data</span>,<span>$merchantKey</span><span>); </span><span>45</span> ?> <span>46</span> 你的订单号是:<?php <span>echo</span><span>$p2_Order</span>; ?>支付的金额是<?php <span>echo</span><span>$p3_Amt</span>; ?> <span>47</span> <!-- 把要提交的数据用隐藏域表示 --> <span>48</span> <form action="https://www.yeepay.com/app-merchant-proxy/node" method="post"> <span>49</span> <input type="hidden" name="p0_Cmd" value="<?php echo <span>$p0_Cmd</span>; ?>"/> <span>50</span> <input type="hidden" name="p1_MerId" value="<?php echo <span>$p1_MerId</span>; ?>"/> <span>51</span> <input type="hidden" name="p2_Order" value="<?php echo <span>$p2_Order</span>; ?>"/> <span>52</span> <input type="hidden" name="p3_Amt" value="<?php echo <span>$p3_Amt</span>; ?>"/> <span>53</span> <input type="hidden" name="p4_Cur" value="<?php echo <span>$p4_Cur</span>; ?>"/> <span>54</span> <input type="hidden" name="p5_Pid" value="<?php echo <span>$p5_Pid</span>; ?>"/> <span>55</span> <input type="hidden" name="p6_Pcat" value="<?php echo <span>$p6_Pcat</span>; ?>"/> <span>56</span> <input type="hidden" name="p7_Pdesc" value="<?php echo <span>$p7_Pdesc</span>; ?>"/> <span>57</span> <input type="hidden" name="p8_Url" value="<?php echo <span>$p8_Url</span>; ?>"/> <span>58</span> <input type="hidden" name="p9_SAF" value="<?php echo <span>$p9_SAF</span>; ?>"/> <span>59</span> <input type="hidden" name="pa_MP" value="<?php echo <span>$pa_MP</span>; ?>"/> <span>60</span> <input type="hidden" name="pd_FrpId" value="<?php echo <span>$pd_FrpId</span>; ?>"/> <span>61</span> <input type="hidden" name="pr_NeedResponse" value="<?php echo <span>$pr_NeedResponse</span>; ?>"/> <span>62</span> <input type="hidden" name="hmac" value="<?php echo <span>$hmac</span>; ?>"/> <span>63</span> <input type="submit" value="确认网上支付"/> <span>64</span> </form> <span>65</span> </html>payconfirm.php