php版银联支付接口开发简明教程


Posted in PHP onOctober 14, 2016

本文实例讲述了php版银联支付接口开发的方法。分享给大家供大家参考,具体如下:

支付接口现在有第三方的支付接口也有银行的支付接口。这里就来介绍php版本银联支付接口开发的方法。

银联支付,首先要注意二重要的部分:

PHP运行环境是5.4.18以上

开了扩展openssl

开发手册上面的列子只做参考,因为基本都是错的。你可以试着去官网下一个demo。。。注意现在银联开发,没有测试密钥提供,只能在正式环境开发

下面是我用ThinkPHP编写的一个支付类

/**
* 银联支付 v0.1
* @auther:Summer<dengwz7788@gmail.com>;
* @date:20151202
* **/
class NetPayAction extends BaseAction{
//在类初始化方法中,引入相关类库
public function _initialize() {
 header("Content-type:text/html;charset=utf-8");
 vendor('Netpay.util.common',"",".php"); //导入加密核心文件夹
 vendor('Netpay.util.SecssUtil',"",".class.php"); //导入加密核心文件夹
 vendor('Netpay.util.Settings_INI',"",".php"); //导入加密核心文件夹
 vendor('Netpay.util.Settings',"",".php"); //导入加密核心文件夹
 $this->securityPropFile= $_SERVER['DOCUMENT_ROOT'] . "/ThinkPHP/Extend/Vendor/Netpay/config/security.properties"; //谁知道这是啥,反正他们要我加的
 $this->b2cPaySend = __APP__."/Index/NetPay/b2cPaySend";
 $this->b2cRefundSend = __APP__."/Index/NetPay/b2cRefundSend";
 $this->b2cQuerySend = __APP__."/Index/NetPay/b2cQuerySend";
 $this->;MerBgUrl = __APP__."/Index/NetPay/MerBgUrl";
 $this->MerPageUrl = __APP__."/Index/NetPay/MerPageUrl";
}
public function index()
{
 $paramArray=array (
   'MerId' => '商户号',
   'MerOrderNo' => '0000001944663232',
   'OrderAmt' => '1',
   'TranDate' => '20151219',
  'TranTime' =>'171248',
  'TranType' => '0001',
  'BusiType' =>'0001',
  'Version' => '20140728',
  'CurryNo' => 'CNY',
  'AccessType' =>; '0',
  'CommodityMsg' => '测试商品1号',
  'MerPageUrl' => $this->MerBgUrl,
  'MerBgUrl' =>$this->MerPageUrl,
  'MerResv' => 'MerResv',
 );
 if (count($paramArray) >0) {
  $dispatchUrl = $this->b2cPaySend;
  $transResvedJson = array();
  $cardInfoJson = array();
  $sendMap = array();
   foreach ($paramArray as $key => $value) {
   if (isEmpty($value)) {
    continue;
   }
   if (startWith($key, "trans_")) {
     $key = substr($key, strlen("trans_"));
        $transResvedJson[$key] = $value;
   } else
     if (startWith($key, "card_")) {
       $key = substr($key, strlen("card_"));
       $cardInfoJson[$key] = $value;
     } else {
       $sendMap[$key] = $value;
     }
  }
  $transResvedStr = null;
  $cardResvedStr = null;
  if (count($transResvedJson) >0) {
   $transResvedStr = json_encode($transResvedJson);
  }
  if (count($cardInfoJson) > 0) {
   $cardResvedStr = json_encode($cardInfoJson);
  }
 $secssUtil = new SecssUtil();
 if (! isEmpty($transResvedStr)) {
  $transResvedStr = $secssUtil->decryptData($transResvedStr);
  $sendMap["TranReserved"] = $transResvedStr;
  }
 if (! isEmpty($cardResvedStr)) {
   $cardResvedStr = $secssUtil->decryptData($cardResvedStr);
   $sendMap["card_"] = $cardResvedStr;
  }
  $securityPropFile = $this>securityPropFile;
  $secssUtil->init($securityPropFile);
  $secssUtil->sign($sendMap);
  $sendMap["Signature"] = $secssUtil->getSign();
  $_SESSION = $sendMap;
  header("Location:" . $dispatchUrl);
 }
}
public function b2cPaySend(){
  layout(false);
  $settings = new Settings_INI();
  $settings->oad($this->securityPropFile);
  $pay_url = "https://payment.chinapay.com/CTITS/service/rest/page/nref/000000000017/0/0/0/0/0";
  $html = "<form name='payment' action='{$pay_url}' method='POST' target='_blank'>;";
  $params = "TranReserved;MerId;MerOrderNo;OrderAmt;CurryNo;TranDate;SplitMethod;BusiType;MerPageUrl;MerBgUrl;SplitType;MerSplitMsg;PayTimeOut;MerResv;Version;BankInstNo;CommodityMsg;Signature;AccessType;AcqCode;OrderExpiryTime;TranType;RemoteAddr;Referred;TranTime;TimeStamp;CardTranData";
  foreach ($_SESSION as $k =>$v) {
   if (strstr($params, $k)) {
     $html .= "<input type='hidden' name = '" . $k . "' value ='" . $v . "'/>";
   }
  }
    $html .= "<nput type='button' type='hidden' value='提交订单' >";
    $html .= "<;/from>";
    $this->html = $html;
    $this->display();
}
public function pgReturn(){
 if ($_POST) {
   if (count($_POST) > 0) {
    $secssUtil = new SecssUtil();
    $securityPropFile = $this>securityPropFile;
    $secssUtil->init($securityPropFile);
    $text = array();
    foreach($_POST as $key=>$value){
      $text[$key] = urldecode($value);
    }
   if ($secssUtil->verify($text)) {
            //支付成功
     $_SESSION["VERIFY_KEY"] = "success";
   } else {
    //支付失败
     $_SESSION["VERIFY_KEY"] = "fail";
   }
  }
  }
 }
}

银联支付应该是算比较简单的!!

希望本文所述对大家PHP程序设计有所帮助。

PHP 相关文章推荐
PHP 操作文件的一些FAQ总结
Feb 12 PHP
php生成的html meta和link标记在body标签里 顶部有个空行
May 18 PHP
php中将汉字转换成拼音的函数代码
Sep 08 PHP
Php header()函数语法及使用代码
Nov 04 PHP
PHP_Cooikes不同页面无法传递的解决方法
Mar 07 PHP
php检测useragent版本示例
Mar 24 PHP
PHP中file_get_contents函数抓取https地址出错的解决方法(两种方法)
Sep 22 PHP
php ajax实现文件上传进度条
Mar 29 PHP
wordpress网站转移到本地运行测试的方法
Mar 15 PHP
PHP实现用户异地登录提醒功能的方法【基于thinkPHP框架】
Mar 15 PHP
PHP实现chrome表单请求数据转换为接口使用的json数据
Mar 04 PHP
php引用传递
Apr 01 PHP
PHP二进制与字符串之间的相互转换教程
Oct 14 #PHP
php基于curl主动推送最新内容给百度收录的方法
Oct 14 #PHP
thinkphp分页实现效果
Oct 13 #PHP
php实现图片以base64显示的方法
Oct 13 #PHP
php实现将base64格式图片保存在指定目录的方法
Oct 13 #PHP
thinkphp隐藏index.php/home并允许访问其他模块的实现方法
Oct 13 #PHP
Mac版PhpStorm之XAMPP整合apache服务器配置的图文教程详解
Oct 13 #PHP
You might like
使用php测试硬盘写入速度示例
2014/01/27 PHP
PHP连接access数据库
2015/03/27 PHP
php安全配置记录和常见错误梳理(总结)
2017/03/28 PHP
php微信公众号开发之快递查询
2018/10/20 PHP
解决laravel 表单提交-POST 异常的问题
2019/10/15 PHP
jQuery的一些注意
2006/12/06 Javascript
js二维数组定义和初始化的三种方法总结
2014/03/03 Javascript
jquery实现鼠标滑过显示提示框的方法
2015/02/05 Javascript
thinkphp实现无限分类(使用递归)
2015/12/19 Javascript
Ajax基础知识详解
2017/02/17 Javascript
关于jquery layui弹出层的使用方法
2018/04/21 jQuery
js图片无缝滚动插件使用详解
2020/05/26 Javascript
Openlayers实现测量功能
2020/09/25 Javascript
使用python将mdb数据库文件导入postgresql数据库示例
2014/02/17 Python
Python之eval()函数危险性浅析
2014/07/03 Python
进一步探究Python中的正则表达式
2015/04/28 Python
Python实现随机生成有效手机号码及身份证功能示例
2017/06/05 Python
浅析python继承与多重继承
2018/09/13 Python
Django框架文件上传与自定义图片上传路径、上传文件名操作分析
2019/05/10 Python
Python简单处理坐标排序问题示例
2019/07/11 Python
解决win7操作系统Python3.7.1安装后启动提示缺少.dll文件问题
2019/07/15 Python
Python实现的企业粉丝抽奖功能示例
2019/07/26 Python
Python数据存储之 h5py详解
2019/12/26 Python
Python求平面内点到直线距离的实现
2020/01/19 Python
解决Keras 与 Tensorflow 版本之间的兼容性问题
2020/02/07 Python
Python try except异常捕获机制原理解析
2020/04/18 Python
Python ArgumentParse的subparser用法说明
2020/04/20 Python
详解基于Scrapy的IP代理池搭建
2020/09/29 Python
纽约通行卡:The New York Pass(免费游览纽约90多个景点)
2017/07/29 全球购物
NFL官方在线商店:NFLShop
2020/07/29 全球购物
Internet主要有哪些网络群组成
2015/12/24 面试题
报关简历自我评价怎么写
2013/09/19 职场文书
学校安全教育月活动总结
2014/07/07 职场文书
2015年十月一日放假通知
2015/08/18 职场文书
导游词之吉林花园山
2019/10/17 职场文书
Python使用pyecharts控件绘制图表
2022/06/05 Python