Git Product home page Git Product logo

union-pay's Introduction

UnionPay - 银联支付

Latest Stable Version License Build Status codecov

simplest union pay - no dependency to any library, simple enough to let you hack.

Feature

Install

composer require zhangv/union-pay

or

add:

"zhangv/union-pay":"0.8.12"

in composer.json

Step 1: config.php - 配置

return ['test', [
		'version' => '5.1.0',
		'signMethod'=> '01', //RSA
		'encoding' => 'UTF-8',
		'merId' => '700000000000001',
		'returnUrl' => 'http://dev.git.com/union-pay/demo/payreturn.php', //前台网关支付返回
		'notifyUrl' => 'http://dev.git.com/union-pay/demo/paynotify.php', //后台通知
		'frontFailUrl'   => 'http://dev.git.com/union-pay/demo/payfail.php',
		'refundnotifyUrl' => 'http://dev.git.com.com/union-pay/demo/refundnotify.php',
		'signCertPath' => dirname(__FILE__).'/../cert/acp_test_sign.pfx',
		'signCertPwd' => '000000', //签名证书密码
		'verifyCertPath' => dirname(__FILE__).'/../cert/acp_test_verify_sign.cer',  //v5.0.0 required
		'verifyRootCertPath' => dirname(__FILE__).'/../cert/acp_test_root.cer', //v5.1.0 required
		'verifyMiddleCertPath' => dirname(__FILE__).'/../cert/acp_test_middle.cer', //v5.1.0 required
		'encryptCertPath' => dirname(__FILE__).'/../cert/acp_test_enc.cer',
		'ifValidateCNName' => false, //正式环境设置为true
	]
];

Step 2: pay.php - 支付

<?php

list($mode,$config) = include './config.php';
$unionPay = UnionPay::B2C($config,$mode);

$payOrderNo = date('YmdHis');
$amt = 1;

$html = $unionPay->pay($payOrderNo,$amt);
echo $html;

Step 3: payreturn.php - 支付完成前台返回

<?php

list($mode,$config) = include './config.php';
$unionPay = UnionPay::B2C($config,$mode);

$postdata = $_REQUEST;
$unionPay->onPayNotify($postdata,function($notifydata){
	echo 'SUCCESS';
	var_dump($notifydata);
});

Step 4: paynotify.php - 支付完成后台通知

<?php
list($mode,$config) = include './config.php';
$unionPay = UnionPay::B2C($config,$mode);

$notifyData = $_POST;
$respCode = $notifyData['respCode'];
if($respCode == '00'){
	$unionPay->onNotify($notifyData,'demoCallback');
}elseif(in_array($respCode,['03','04','05'])){
	//后续需发起交易状态查询交易确定交易状态
}else{
	echo 'fail';
}


function demoCallback($notifyData){//自定义回调
	var_dump($notifyData);
	print('ok');
}

FAQ

  • 关于测试环境:有时候会报验签错误,一般的原因是证书错误或者参数拼接,如果确认二者没错,那么可能是因为你的商户号在银联测试环境中不生效,这种时候需要联系银联的客服。也可以直接用生产环境的证书测试交易,如果可以正常交易,那么测试交易这步也可以不做。
  • 关于测试用例:目前的测试用例依赖银联的测试环境,但并不是很稳定,经常会有返回错误的情况。后续可能考虑改成模拟数据。

union-pay's People

Contributors

scrutinizer-auto-fixer avatar zhangv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

union-pay's Issues

B2C发起请求bug

最新版本,B2C发起请求时调用pay方法,这里不应该用httpClient发起post请求,会导致页面超时。

return $this->submitForm($this->frontTransUrl,$params);

应使用上一个版本的html表单自动构建提交
return $this->createPostForm($params);

参数类型不对,frontTransUrl 问题

  1. $html = $unionPay->pay($payOrderNo,$amt,'desc','');
    参数‘desc’在 B2C.php 里参数$ext 是数组,这里传字符串array_merge出错了。
  2. B2C.php 里38行 return $this->createPostForm($params,'支付',$this->frontTransUrl, $serverSide);

$this->frontTransUrl传进去没加$apiEndpoint

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.