最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php版本银联支付接口开发实例
时间:2022-06-24 17:48:56 编辑:袖梨 来源:一聚教程网
银联支付,首先要注意二重要的部分:
PHP运行环境是5.4.18以上
开了扩展openss
开发手册上面的列子只做参考,因为基本都是错的。你可以试着去官网下一个demo。。。注意现在银联开发,没有测试密钥提供,只能在正式环境开发【20151219】
下面是我用ThinkPHP编写的一个支付类
/**
* 银联支付 v0.1
* @auther:Summer
* @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 = "
感觉银联的支付接口比支付宝的还简单好用了,当然每个考虑到的东西不一样哦,上面只是开个玩笑的哦
相关文章
- 人们熟悉的寄居蟹属于以下哪种分类 神奇海洋11月21日答案 11-21
- 第五人格11.22共研服有什么更新 11月22日共研服更新内容介绍 11-21
- 原神恰斯卡怎么培养 11-21
- 无期迷途四星装束是谁 11-21
- 王者荣耀帝丹高中校服怎么获得 11-21
- 光遇姆明季后续版本怎么玩 11-21