PHP code example of winwin / pay-sdk

1. Go to this page and download the library: Download winwin/pay-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

winwin / pay-sdk example snippets


use winwin\pay\sdk\Config;
use winwin\pay\sdk\payment\Payment;

$payment = new Payment(new Config([
    'appid' => $appid,
    'secret' => $secret,
]));

use winwin\pay\sdk\payment\Order;

$result = $payment->prepare(new Order([
    'mch_id' => $merchant_id,
    'method' => 'pay.weixin.jsapi',
    'body' => '支付1分',
    'total_fee' => 1,
    'out_trade_no' => date('ymdHis') . mt_rand(1000, 9999),
    'notify_url' => 'http://example.org/notify',
    'openid' => $openid,
]));

$response = $payment->handleNotify(function($notify, $successful) {
    // 处理逻辑
    return true;
});
echo $response->getBody();

use winwin\pay\sdk\payment\OrderQuery;

$result = $payment->query(new OrderQuery([
    'mch_id' => $merchant_id,
    'method' => 'trade.query',
    'transaction_id' => '平台订单号',
    'out_trade_no' => '商户订单号',
]));

use winwin\pay\sdk\payment\CloseOrder;

$result = $payment->close(new CloseOrder([
    'mch_id' => $merchant_id,
    'method' => 'trade.close',
    'out_trade_no' => '商户订单号',
]));

use winwin\pay\sdk\payment\Refund;

$result = $payment->refund(new Refund([
    'mch_id' => $merchant_id,
    'method' => 'trade.refund',
    'transaction_id' => '平台订单号',
    'out_trade_no' => '商户订单号',
    'out_refund_no' => '商户退款单号',
    'total_fee' => 1,
    'refund_fee' => 1,
    'op_user_id' => $merchant_id,
]));

use winwin\pay\sdk\payment\RefundQuery;

$result = $payment->queryRefund(new RefundQuery([
    'mch_id' => $merchant_id,
    'method' => 'trade.refund.query',
    'transaction_id' => '平台订单号',
    'out_trade_no' => '商户订单号',
    'out_refund_no' => '商户退款单号',
    'refund_id' => '平台退款单号',
]));

use Monolog\Logger;
use Monolog\Handler\StreamHandler;
$logger = new Logger('WinwinPay');
$logger->pushHandler(new StreamHandler('php://stderr', Logger::DEBUG));

$payment->setLogger($logger);