统一支付

  • 微信支付

  • 支付宝支付

  • 银联支付

微信支付

use jianyan\basics\common\payment\WechatPay;

订单

$order = [
        'body'              => 'The test order',
        'out_trade_no'      => date('YmdHis') . mt_rand(1000, 9999),
        'total_fee'         => 1, //=0.01
        'notify_url'        => '', //支持回调地址
         // 'openid'        => '', //微信js支付必传
         // 'auth_code'     => '', //微信刷卡支付必传
   ]

生成参数

// 实例化微信支付类
$payment = new WechatPay();

// 微信APP支付
$config = $payment->app($order);
// 微信原生扫码支付
$config = $payment->native($order);
// 微信js支付
$config = $payment->js($order);
// 微信刷卡支付
$config = $payment->pos($order);
// 微信H5支付
$config = $payment->mweb($order);

支付回调

$response = $payment->notify();

if ($response->isPaid()) {
    // 支付成功回调
    var_dump($response->getRequestData());
}else{
    // 支付失败回调
}

关闭订单

// $type WechatPay_App, WechatPay_Native, WechatPay_Js, WechatPay_Pos, WechatPay_Mweb
// APP支付,原生扫码支付,js支付,刷卡支付,H5支付
$result = $payment->app($type, $out_trade_no);

查询订单

$result = $payment->query($type, $transaction_id);

退款

/**
* @param $info
* [
*     'transaction_id' => $transaction_id, //The wechat trade no
*     'out_refund_no' => $outRefundNo,
*     'total_fee' => 1, //=0.01
*     'refund_fee' => 1, //=0.01
* ]
*/
$result = $payment->refund($type, $info);

支付宝支付

use jianyan\basics\common\payment\AliPay;

订单

$order = [
    'out_trade_no' => date('YmdHis') . mt_rand(1000, 9999),
    'total_amount' => 0.01,
    'subject'      => 'test',
];

生成参数

// 实例化支付宝支付类
$payment = new AliPay();

// 支付宝APP支付
$config = $payment->app($order);
// 支付宝pc支付
$config = $payment->pc($order);
// 支付宝面对面支付
$config = $payment->f2f($order);
// 支付宝wap支付
$config = $payment->wap($order);

银联支付

use jianyan\basics\common\payment\UnionPay;

订单

$order = [
    'orderId'   => date('YmdHis'), //订单id
    'txnTime'   => date('YmdHis'), //订单时间 format 'YmdHis'
    'orderDesc' => 'My order title', //订单标题
    'txnAmt'    => '100', //订单金额
];

生成参数

// 实例化微信支付类 
// $returnUrl 通知地址
// $notifyUrl 回调地址
$payment = new UnionPay($returnUrl, $notifyUrl);

// 银联APP支付
$config = $payment->app($order);
// 银联pc,wap支付
$config = $payment->html($order);

支付回调

$response = $payment->notify();

if ($response->isPaid()) {
    // 支付成功回调
    var_dump($response->getRequestData());
}else{
    // 支付失败回调
}

查询订单

/**
* @param $orderId 订单id
* @param $txnTime 订单交易时间
* @param $txnAmt 订单总费用
* @return mixed
*/
$result = $payment->query($orderId, $txnTime, $txnAmt);

退款

$result = $payment->refund($orderId, $txnTime, $txnAmt);

上次更新:2018-01-18