code-lives / baidu-pay
百度小程序支付、订单查询、退款、支付回调、获取token
Installs: 1 052
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/code-lives/baidu-pay
This package is auto-updated.
Last update: 2025-09-29 02:51:57 UTC
README
说明(重要)
支付回调一定要保存userId 退款需要。
Config 参数
| 参数名字 | 类型 | 必须 | 说明 |
|---|---|---|---|
| appid | string | 是 | 百度小程序appkey(退款必须) |
| appkey | string | 是 | 百度小程序appkey |
| payappKey | string | 是 | 百度小程序支付appkey |
| appSecret | string | 是 | 百度小程序aapSecret |
| dealId | int | 是 | 百度小程序支付凭证 |
| rsaPriKeyStr | string | 是 | 私钥(只需要一行长串,不需要文件) |
| rsaPubKeyStr | string | 是 | 百度小程序支付的平台公钥(支付回调需要) |
安装
composer require code-lives/baidu-pay
Demo
$config = [ 'appid'=>'abcdef', 'appkey' => 'abcdef', 'payappKey' => "MMMMMMMM", 'appSecret' => 'ABCDEF', 'dealId' => 123456, 'rsaPriKeyStr' => "ABCDEF", 'rsaPubKeyStr' => 'ABCDEF', ];
初始化
//use Baidu\Pay\Pays; $Baidu = new Pays($config);
获取token
$Baidu = new Pays($config); $result = $Baidu->getToken();
支付参数配置
| 参数名字 | 类型 | 必须 | 说明 |
|---|---|---|---|
| order | string | 是 | 平台订单号 |
| money | int | 是 | 金额 |
| desc | string | 是 | 订单描述 |
Demo
$result = $Baidu->getOrderParm($order, $money, $desc);
订单查询参数配置
| 参数名字 | 类型 | 必须 | 说明 |
|---|---|---|---|
| access_token | string | 是 | 根据上面的获取token |
| tpOrderId | string | 是 | 平台订单号 |
$order = [ 'access_token' => 'abcde', 'tpOrderId' => '123456', ]; $result = $Baidu->findOrder($order);
退款参数配置
| 参数名字 | 类型 | 必须 | 说明 |
|---|---|---|---|
| token | string | 是 | 根据上面的获取token |
| bizRefundBatchId | int | 是 | 百度平台的订单号 |
| isSkipAudit | int | 是 | 默认为0; 0:不跳过开发者业务方审核;1:跳过开发者业务方审核。 |
| orderId | int | 是 | 百度平台的订单号 |
| refundReason | string | 是 | 退款描述 |
| refundType | int | 是 | 退款类型 1:用户发起退款;2:开发者业务方客服退款;3:开发者服务异常退款。百度小程序支付的平台公钥 |
| tpOrderId | string | 是 | 自己平台订单号 |
| userId | int | 是 | 用户uid(不是自己平台uid) |
Demo
$data = [ 'token' => 'abcd', 'bizRefundBatchId' => 123456,//百度平台订单号 'isSkipAudit' => 1, 'orderId' => 123456, 'refundReason' => '测试退款', 'refundType' => 2,// 'tpOrderId' => '123',//自己平台订单号 'userId' => 123, ]; $result = $Baidu->applyOrderRefund($data);
支付异步通知
$Baidu->notifyCheck($_POST); //返回 true false