PHP code example of xhat / payjs-laravel
1. Go to this page and download the library: Download xhat/payjs-laravel 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/ */
xhat / payjs-laravel example snippets
return [
'mchid' => '', // 填写商户号
'key' => '', // 填写通信KEY
];
use Xhat\Payjs\Facades\Payjs;
// 构造订单基础信息
$data = [
'body' => '订单测试', // 订单标题
'total_fee' => 2, // 订单标题
'out_trade_no' => time(), // 订单号
'attach' => 'test_order_attach', // 订单附加信息(可选参数)
'notify_url' => 'https://www.baidu.com/notify', // 异步通知地址(可选参数)
];
return Payjs::native($data);
// 构造订单基础信息
$data = [
'body' => '订单测试', // 订单标题
'total_fee' => 2, // 订单金额
'out_trade_no' => time(), // 订单号
'attach' => 'test_order_attach', // 订单附加信息(可选参数)
'notify_url' => 'https://www.baidu.com/notify', // 异步通知地址(可选参数)
'callback_url' => 'https://www.baidu.com/callback', // 支付后前端跳转地址(可选参数)
];
$url = Payjs::cashier($data);
return redirect($url);
// 构造订单基础信息
$data = [
'body' => '订单测试', // 订单标题
'total_fee' => 2, // 订单金额
'out_trade_no' => time(), // 订单号
'attach' => 'test_order_attach', // 订单附加信息(可选参数)
'openid' => 'xxxxxxxxxxxxxxxxx', // 订单附加信息(可选参数)
'notify_url' => 'https://www.baidu.com/notify', // 异步通知地址(可选参数)
];
return Payjs::jsapi($data);
// 构造订单基础信息
$data = [
'body' => '订单测试', // 订单标题
'total_fee' => 2, // 订单金额
'out_trade_no' => time(), // 订单号
'attach' => 'test_order_attach', // 订单附加信息(可选参数)
'notify_url' => 'https://www.baidu.com/notify', // 异步通知地址(可选参数)
'callback_url' => 'https://www.baidu.com', // 前端跳转地址(可选参数)
];
return Payjs::mweb($data);
// 构造订单基础信息
$data = [
'mchid' => '123123', // 商户号
];
return Payjs::complaint($data);
// 根据订单号查询订单状态
$payjs_order_id = '****************';
return Payjs::check($payjs_order_id);
// 根据订单号关闭订单
$payjs_order_id = '****************';
return Payjs::close($payjs_order_id);
// 根据订单号退款
$payjs_order_id = '****************';
return Payjs::refund($payjs_order_id);
// 返回商户基础信息
return Payjs::info();
// 根据订单信息中的 OPENID 查询用户资料
$openid = '***************';
return Payjs::user($openid);
// 根据订单信息中的银行编码查询银行中文名称
$bank = '***************';
return Payjs::bank($bank);
// 接收异步通知,无需关注验签动作,已自动处理
$notify_info = Payjs::notify();
Log::info($notify_info);
shell
php artisan vendor:publish --provider="Xhat\Payjs\PayjsServiceProvider"