2017 © Pedro Peláez
 

library union-pay

The simplest union pay

image

zhangv/union-pay

The simplest union pay

  • Wednesday, July 4, 2018
  • by zhangv
  • Repository
  • 2 Watchers
  • 8 Stars
  • 19 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 10 Versions
  • 280 % Grown

The README.md

UnionPay - 银联支付

Latest Stable Version License Build Status codecov, (*1)

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

Feature

Install

composer require zhangv/union-pay

or, (*3)

add:, (*4)

"zhangv/union-pay":"0.8.12"

in composer.json, (*5)

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

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

The Versions

04/07 2018

dev-master

9999999-dev https://github.com/zhangv/union-pay

The simplest union pay

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

unionpay 银联 银联b2b 银联支付 银联网关支付 银联代收 银联全渠道 银联移动支付 银联无跳转支付

04/07 2018

dev-scrutinizer-patch-3

dev-scrutinizer-patch-3 https://github.com/zhangv/union-pay

The simplest union pay

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

unionpay 银联 银联b2b 银联支付 银联网关支付 银联代收 银联全渠道 银联移动支付 银联无跳转支付

02/07 2018

v0.8.11

0.8.11.0 https://github.com/zhangv/union-pay

The simplest union pay

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

unionpay 银联 银联b2b 银联支付 银联网关支付 银联代收 银联全渠道 银联移动支付 银联无跳转支付

26/06 2018

v0.8.8

0.8.8.0 https://github.com/zhangv/union-pay

The simplest union pay

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

unionpay 银联 银联b2b 银联支付 银联网关支付 银联代收 银联全渠道 银联移动支付 银联无跳转支付

25/06 2018

dev-scrutinizer-patch-2

dev-scrutinizer-patch-2 https://github.com/zhangv/union-pay

The simplest union pay

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

unionpay 银联 银联b2b 银联支付 银联网关支付 银联代收 银联全渠道 银联移动支付 银联无跳转支付

25/06 2018

dev-scrutinizer-patch-1

dev-scrutinizer-patch-1 https://github.com/zhangv/union-pay

The simplest union pay

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

unionpay 银联 银联b2b 银联支付 银联网关支付 银联代收 银联全渠道 银联移动支付 银联无跳转支付

09/05 2018

v0.8

0.8.0.0 https://github.com/zhangv/union-pay

The simplest union pay

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

unionpay 银联 银联支付