PHP code example of kuangjy / omnipay-qpay
1. Go to this page and download the library: Download kuangjy/omnipay-qpay 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/ */
kuangjy / omnipay-qpay example snippets
//gateways: QPay_App, QPay_Native, QPay_Js
$gateway = Omnipay::create('QPay_Native');
$gateway->setAppId('app_id'); //ey');
$order = [
'out_trade_no' => time() . mt_rand(1000, 9999),
'body' => 'order information',
'attach' => 'attached information',
'total_fee' => '100',
'spbill_create_ip' => '127.0.0.1',
'notify_url' => 'http://example.com/notify.php',
];
/**
* @var Omnipay\QPay\Message\CreateOrderRequest $request
* @var Omnipay\QPay\Message\CreateOrderResponse $response
*/
$request = $gateway->purchase($order);
$response = $request->send();
//available methods
$response->isSuccessful();
$response->getData(); //For debug
$response->getPrepayId(); //Prepay ID
$response->getAppData(); //For QPay_App
$response->getJsOrderData(); //For QPay_Js
$response->getCodeUrl(); //For QPay_Native
//gateways: QPay_MicroPay
$gateway = Omnipay::create('QPay_MicroPay');
$gateway->setMchId('mch_id');
$gateway->setApiKey('api_key');
$order = [
'out_trade_no' => time() . mt_rand(1000, 9999),
'body' => '商品描述',
'attach' => '附加信息',
'total_fee' => '100',
'spbill_create_ip' => '127.0.0.1',
'notify_url' => 'http://example.com/notify.php',
'device_info' => '001',
'auth_code' => '910783818928826810'
];
/**
* @var Omnipay\QPay\Message\CreateMicroPayOrderRequest $request
* @var Omnipay\QPay\Message\CreateMicroPayOrderResponse $response
*/
$request = $gateway->purchase($order);
$response = $request->send();
//available methods
$response->isSuccessful(); //Get result
$response->getData(); //For debug
//gateways: QPay_Transfer
$gateway = Omnipay::create('QPay_Transfer');
$gateway->setMchId('mch_id');
$gateway->setApiKey('api_key');
$gateway->setCertPath($certPath);//证书cert路径
$gateway->setKeyPath($keyPath);//证书key路径
$order = [
'out_trade_no' => time() . mt_rand(1000, 9999),
'uin' => '123456789',
'memo' => '转账描述',
'total_fee' => '100',
'spbill_create_ip' => '127.0.0.1',
];
/**
* @var Omnipay\QPay\Message\CreateTransferRequest $request
* @var Omnipay\QPay\Message\CreateTransferResponse $response
*/
$request = $gateway->transfer($order);
$response = $request->send();
//available methods
$response->isSuccessful(); //Get result
$response->getData(); //For debug
//gateways: QPay_RedPacket
$gateway = Omnipay::create('QPay_RedPacket');
$gateway->setMchId('mch_id');
$gateway->setApiKey('api_key');
$gateway->setCertPath($certPath);//证书cert路径
$gateway->setKeyPath($keyPath);//证书key路径
$order = [
'mch_billno' => '1441246101201610101234567890',//组成:mch_id+yyyymmdd+10位一天内不能重复的的数字
'mch_name' => '测试商户',
're_openid' => '123456789',
'total_amount' => '100',
'total_num' => '10',
'wishing' => '红包祝福语',
'act_name' => '活动名称',
'icon_id' => '23',
'min_value' => '1',
'max_value' => '100'
];
/**
* @var Omnipay\QPay\Message\CreateRedPacketRequest $request
* @var Omnipay\QPay\Message\CreateRedPacketResponse $response
*/
$request = $gateway->redPacket($order);
$response = $request->send();
//available methods
$response->isSuccessful(); //Get result
$response->getData(); //For debug
$gateway = Omnipay::create('QPay');
$gateway->setAppId('app_id');
$gateway->setMchId('mch_id');
$gateway->setApiKey('api_key');
$response = $gateway->completePurchase([
'request_params' => file_get_contents('php://input')
])->send();
if ($response->isPaid()) {
//pay success
var_dump($response->getRequestData());
}else{
//pay fail
}
$response = $gateway->query([
'transaction_id' => '1217752501201407033233368018',
])->send();
var_dump($response->isSuccessful());
var_dump($response->getData());
$response = $gateway->close([
'out_trade_no' => '20150806125346',
])->send();
var_dump($response->isSuccessful());
var_dump($response->getData());
$gateway->setCertPath($certPath);
$gateway->setKeyPath($keyPath);
$response = $gateway->refund([
'transaction_id' => '1353933301461607211903715555',
'out_refund_no' => $outRefundNo,
'refund_fee' => 100,
'op_user_id' => '1900000109',
'op_user_passwd' => 'e47fefadd66e024bb2b85dfeb5fe86ba'
])->send();
var_dump($response->isSuccessful());
var_dump($response->getData());
$response = $gateway->queryRefund([
'refund_id' => '1121218133801201611098791376',
])->send();
var_dump($response->isSuccessful());
var_dump($response->getData());