PHPackages                             code-lives/baidu-pay - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. code-lives/baidu-pay

ActiveLibrary

code-lives/baidu-pay
====================

百度小程序支付、订单查询、退款、支付回调、获取token

11.2k↓100%PHP

Since Nov 2Pushed 4y ago1 watchersCompare

[ Source](https://github.com/code-lives/Baidu-Pay)[ Packagist](https://packagist.org/packages/code-lives/baidu-pay)[ RSS](/packages/code-lives-baidu-pay/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

百度小程序支付（点个收藏是我前进的动力）
====================

[](#百度小程序支付点个收藏是我前进的动力)

[官方接口文档](https://smartprogram.baidu.com/docs/develop/function/parameter/)

说明（重要）
======

[](#说明重要)

#### 支付回调一定要保存userId 退款需要。

[](#支付回调一定要保存userid-退款需要)

Config 参数
=========

[](#config-参数)

参数名字类型必须说明appidstring是百度小程序appkey（退款必须）appkeystring是百度小程序appkeypayappKeystring是百度小程序支付appkeyappSecretstring是百度小程序aapSecretdealIdint是百度小程序支付凭证rsaPriKeyStrstring是私钥（只需要一行长串，不需要文件）rsaPubKeyStrstring是百度小程序支付的平台公钥(支付回调需要)安装
==

[](#安装)

```
   composer require code-lives/baidu-pay
```

Demo
----

[](#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
-------

[](#获取token)

```
    $Baidu = new Pays($config);
    $result = $Baidu->getToken();
```

支付参数配置
======

[](#支付参数配置)

参数名字类型必须说明orderstring是平台订单号moneyint是金额descstring是订单描述Demo
----

[](#demo-1)

```
    $result = $Baidu->getOrderParm($order, $money, $desc);
```

订单查询参数配置
========

[](#订单查询参数配置)

参数名字类型必须说明access\_tokenstring是根据上面的获取tokentpOrderIdstring是平台订单号```
    $order = [
	'access_token' => 'abcde',
	'tpOrderId' => '123456',
    ];
    $result = $Baidu->findOrder($order);
```

退款参数配置
======

[](#退款参数配置)

参数名字类型必须说明tokenstring是根据上面的获取tokenbizRefundBatchIdint是百度平台的订单号isSkipAuditint是默认为0； 0：不跳过开发者业务方审核；1：跳过开发者业务方审核。orderIdint是百度平台的订单号refundReasonstring是退款描述refundTypeint是退款类型 1：用户发起退款；2：开发者业务方客服退款；3：开发者服务异常退款。百度小程序支付的平台公钥tpOrderIdstring是自己平台订单号userIdint是用户uid（不是自己平台uid）Demo
----

[](#demo-2)

```
    $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
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity27

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/66c8ab94602f8fde6cbb339ec8b9b0dbd178b1aeab8973d957e3903d14e2b7be?d=identicon)[code-lives](/maintainers/code-lives)

---

Top Contributors

[![code-lives](https://avatars.githubusercontent.com/u/79346591?v=4)](https://github.com/code-lives "code-lives (10 commits)")

### Embed Badge

![Health badge](/badges/code-lives-baidu-pay/health.svg)

```
[![Health](https://phpackages.com/badges/code-lives-baidu-pay/health.svg)](https://phpackages.com/packages/code-lives-baidu-pay)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
