• 工商银行网上支付接口PHP的demo(原创) 发送篇


    send.php

    <?php
    date_default_timezone_set('PRC');
    include_once("icbc.php");
    if(!empty($_POST['hide'])) {
    $fdir = $_SERVER['DOCUMENT_ROOT']."/key/"; //商户证书所放路径
    $target = "http://localhost/test.php";
    $payAPI['interfaceName'] = "ICBC_PERBANK_B2C"; //接口方式
    $payAPI['interfaceVersion'] = "1.0.0.1"; //接口版本
    $payAPI['merID'] = "0200EC20000012"; //商户ID
    $payAPI['merAcct'] = "0200029109000030106"; //商户银行帐号
    $payAPI['merURL'] = "http://localhost/get.php"; //接收银行通知路径
    $payAPI['notifyType'] = "HS"; //接口通知方式
    $payAPI['orderid'] = $_POST['orderid'];
    $payAPI['amount'] = $_POST['amount'];
    $payAPI['curType'] = "001"; //货币类型 001为人民币
    $payAPI['resultType'] = "0";
    $payAPI['orderDate'] = date("YmdHis");
    $payAPI['verifyJoinFlag'] = "0";

    $icbc = new icbcpay();
    $icbc->init($payAPI,$fdir);
    $icbc->Send();
    }
    ?>
    <html>
    <head>
    <title>模拟B2C交易</title>
    </head>
    <body leftmargin="0" topmargin="0">
    <table cellpadding="1" cellspacing="1" bgcolor="#E5E5E5" width="800" align="center">
    <tr bgcolor="#F5F5F5">
    <td height="50" align="center">交易平台</td>
    </tr>
    <form action="b2c.php" method="post">
    <tr bgcolor="#FFFFFF">
    <td height="440" align="center">
    <table cellpadding="1" cellspacing="1" bgcolor="#E5E5E5" width="600">
    <tr bgcolor="#F5F5F5">
       <td height="30" align="center" width="120">订 单 号</td>
       <td bgcolor="#FDFDFD" width="580">&nbsp;
       <input type="text" name="orderid" value="000000001" style="300px" />
       </td>
    </tr>
    <tr bgcolor="#F5F5F5">
       <td height="30" align="center" width="120">商品金额</td>
       <td bgcolor="#FDFDFD" width="580">&nbsp;
       <input type="text" name="amount" value="100" style="300px" />
       </td>
    </tr>
    <tr bgcolor="#FAFAFA">
       <td colspan="2" height="30">
       <input type="hidden" name="hide" value="1" />
       <input type="submit" value="提交" />
       </td>
    </tr>
    </table>
    </td>
    </tr>
    </form>
    </table>
    </body>
    </html>

    icbc.php

    <?php
    class icbcpay
    {
    private $payAPI = Array();
    private $fdir;
    private $LongString;
    private $POSTString;
    private $target;
    public function init($api,$fdir)
    {
       $this->payAPI = $api;
       $this->fdir = $fdir;
       $this->target = $target;
       $this->getCOMAPI();
    }

    private function getCOMAPI()
    {
       $icbc = new COM("ICBCEBANKUTIL.B2CUtil");
       $crt = $this->fdir."user.crt";
       $key = $this->fdir."user.key";
       $rc = $icbc->init($crt, $crt, $key, '11111111');
       $this->setString();
       if($rc == 0) {
        $this->payAPI['merSignMsg'] = $icbc->signC($this->LongString, strlen($this->LongString));
        $this->payAPI['merCert'] = $icbc->getCert(1);
       }
    }

    private function setString()
    {
       $payAPI = $this->payAPI;
       $this->LongString.= "";
       foreach ($payAPI as $key => $value) {
        $this->LongString.= $value;
       }
    }

    private function setPOSTString()
    {
       $payAPI=$this->payAPI;
       $this->POSTString = "";
       foreach ($payAPI as $key => $value) {
        if($key == "interfaceName") {
         $this->POSTString.=$key."=".$value;
        } else {
         $this->POSTString.="&".$key."=".$value;
        }
       }
    }

    private function setFromTxt()
    {
       $payAPI = $this->payAPI;
      
       foreach ($payAPI as $key => $value) {
        $header.= '<input type="hidden" readonly="readonly" name="'.$key.'" value="'.$value.'">';
       }
       $header.= '</form>';
       return $header;
    }

    public function Send()
    {
      
       $url = "http://localhost/test.php";
       $header = '<form action="'.$url.'" id="sendform" method="post" name="order">';
       $header.= $this->setFromTxt();
       $header.= "<script type=\"text/javascript\">";
       $header.= "document.getElementById(\"sendform\").submit();";
       $header.= "</script>";
       echo $header;
      
       //$referrer = "";
       //$url_info = parse_url($url);
       //if($referrer == "")
        //$referrer = $_SERVER['SCRIPT_URI'];
       //$this->setPOSTString();
       //$POSTString = $this->POSTString;
       //$data_string = $POSTString;
      
       //$request = "POST ".$url_info["path"]." HTTP/1.1\n";
       //$request.= "Host: ".$url_info["host"]."\n";
       //$request.= "Referer: $referrer\n";
       //$request.= "Content-type: application/x-www-form-urlencoded\n";
       //$request.= "Content-length: ".strlen($data_string)."\n";
       //$request.= "Connection: close\n";
       //$request.= "\n";
       //$request.= $data_string."\n";
       //$fp = fsockopen($url_info['host'], 80);
       //fputs($fp, $request);
       //while (!feof($fp)) {
        //$request .= fgets($fp, 128);
       //}
       //echo $request;
       //fclose($fp);
       //header("location:$url");
       //printf('<script type="text/javascript">');
       //printf('window.location="'.$url.'";');
       //printf('</script>');
    }
    }
    ?>

    转自:http://hi.baidu.com/linuxapplication/blog/item/15d986c2138d681d0ef47783.html
  • 相关阅读:
    03 python学习笔记-文件操作
    02 Python学习笔记-基本数据类型
    01 Python简介、环境搭建及包管理
    一、如何使用postman做接口测试笔记一
    django测试开发-1.开始Hello django!
    Oracle创建用户并给用户授权查询指定表或视图的权限
    ORA-00933 UNION 与 ORDER BY
    excel设置单元格不可编辑
    oracle之分组内的字符串连接
    10 款强大的JavaScript图表图形插件推荐
  • 原文地址:https://www.cnblogs.com/gyxdbk/p/1910553.html
Copyright © 2020-2023  润新知