PHPackages                             code-lives/ali - 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/ali

ActiveLibrary

code-lives/ali
==============

支付宝小程序（支付、手机号解密、获取Token、模版消息、支付异步通知、退款、订单查询）

1.0.0(2y ago)0533—0%1MITPHP

Since Jul 26Pushed 2y ago1 watchersCompare

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

READMEChangelog (1)DependenciesVersions (2)Used By (1)

[![GitHub forks](https://camo.githubusercontent.com/48ef6153e77d3aded1d8eb4790a8e570f635c7c4b6d2cc7a438bddfb059b4cb0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f64652d6c697665732f616c693f696e636c7564655f70726572656c6561736573)](https://packagist.org/packages/code-lives/ali)[![GitHub forks](https://camo.githubusercontent.com/18b3de0966232d93168e922b0df36407861e96056cc005af04a60aa180e4c1db/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f636f64652d6c697665732f616c693f7374796c653d736f6369616c)](https://packagist.org/packages/code-lives/ali)[![GitHub forks](https://camo.githubusercontent.com/b61760c071edab699c339d2ebedfa3416a80b99c3cb48aea9325bfc395af266c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f636f64652d6c697665732f616c693f7374796c653d736f6369616c)](https://github.com/code-lives/ali/fork)

第三方tokenopenid支付回调退款订单查询解密手机号分账模版消息[支付宝小程序](https://opendocs.alipay.com/mini/03l5wn)x✓✓✓✓✓✓x✓安装
--

[](#安装)

```
composer require code-lives/ali 1.0.0
```

### ⚠️ 注意

[](#️-注意)

> 金额单位分 100=1 元

> 返回结果 array 由开发者自行判断

预下单
===

[](#预下单)

```
//引入命名空间
use Applet\Assemble\Ali;

// 小程序下单
$pay= Ali::init($config)->set("订单号","金额","描述",'openid')->getParam();
```

支付宝小程序
======

[](#支付宝小程序)

> 使用密钥进行签名解密，没有使用证书签名解密。

> 订单查询、退款、参数设置可以设置其他，具体看文档。

> 返回值 看官方文档，每个返回值都不一样，自行判断，如 openid 返回\[alipay\_system\_oauth\_token\_response\] 退款返回\[alipay\_trade\_create\_response\]

### Config

[](#config)

参数名字类型必须说明appidstring是小程序 appidsecretstring是小程序 AES 用于手机号解密privateKeystring是应用私钥（开发工具生成）publicKeystring是支付宝公钥（支付宝后台下载）notify\_urlstring是异步回调地址### Openid

[](#openid)

> getOpenid 获取支付宝的用户 user\_id 类似于微信的 openid

```
$code="";
$data= Ali::init($config)->getOpenid($code);
//返回参数
$data = array(
    [alipay_system_oauth_token_response] => Array
        (
            [access_token] => 123
            [alipay_user_id] => 123
            [auth_start] => 2023-03-26 20:56:36
            [expires_in] => 1296000
            [re_expires_in] => 2592000
            [refresh_token] => auth
            [user_id] => 123
        )
    [sign] =>
    )
```

### 解密手机号

[](#解密手机号)

```
$data= Ali::init($config)->decryptPhone($session_key, $iv, $encryptedData);
echo $phone['mobile'];
```

### 订单查询

[](#订单查询)

```
$data = Ali::init($config)->findOrder(['out_trade_no' => '1679838318']);
```

### 退款

[](#退款)

参数名字类型必须说明out\_trade\_nostring是平台订单号refund\_amountint是退款金额```
$orders = [
        'out_order_no' => $order['out_order_no'],
        'refund_amount' => $order['refund_amount'],
    ];
$data= Ali::init($config)->applyOrderRefund($order);
```

### 模版消息

[](#模版消息)

模版消息设置比较麻烦。需要先到开发平台添加进入小程序进行产品绑定，在去商家平台设置[文档](https://opendocs.alipay.com/b/03ksho)

```
$data = [
        'to_user_id' => '用户uid',
        'user_template_id' => '模版id',
        'page' => 'pages/index/index',
        'data' => json_encode([
            'keyword1' => ['value' => '1'],
            'keyword2' =>  ['value' => '2'],
            'keyword3' => ['value' => '3'],
        ]),
    ];
$data= Ali::init($config)->sendMsg($data,$token);
```

支付回调
----

[](#支付回调)

```
$pay = Ali::init($config);
$status = $pay->notifyCheck(); //验证
if ($status) {
    $order = $pay->getNotifyOrder(); //订单数据
    //$order['out_trade_no']//平台订单号
}
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 66.7% 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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1028d ago

### 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 (2 commits)")[![LeeCodeLives](https://avatars.githubusercontent.com/u/28551829?v=4)](https://github.com/LeeCodeLives "LeeCodeLives (1 commits)")

### Embed Badge

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

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

PHPackages © 2026

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