PHPackages                             code-lives/weixin - 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. [Payment Processing](/categories/payments)
4. /
5. code-lives/weixin

ActiveLibrary[Payment Processing](/categories/payments)

code-lives/weixin
=================

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

1.0.0(2y ago)6527—0%11MITPHP

Since Jul 26Pushed 2y ago1 watchersCompare

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

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

[![GitHub forks](https://camo.githubusercontent.com/65a9be2f548e0a64cd9b77ec822cf54d2ee73f53825e7a8594e158aeec4d9b07/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f64652d6c697665732f77656978696e3f696e636c7564655f70726572656c6561736573)](https://packagist.org/packages/code-lives/weixin)[![GitHub forks](https://camo.githubusercontent.com/cd437c7986ed82a62c13cca81f2435592aa57b7d985fcd425b31db41d57e71c5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f636f64652d6c697665732f77656978696e3f7374796c653d736f6369616c)](https://packagist.org/packages/code-lives/weixin)[![GitHub forks](https://camo.githubusercontent.com/1bf6867093367e7cd9e83105896162656e9531d32ffded55d5c406c5cd60a884/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f636f64652d6c697665732f77656978696e3f7374796c653d736f6369616c)](https://github.com/code-lives/weixin/fork)

第三方tokenopenid支付回调退款订单查询解密手机号分账模版消息[微信小程序](https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_1)✓✓✓✓✓✓✓x✓微信 h5xx✓✓✓✓xxx微信 APPx✓✓✓✓✓xxx微信公众号xx✓✓✓✓xx✓安装
--

[](#安装)

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

### ⚠️ 注意

[](#️-注意)

> 金额单位分 100=1 元

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

预下单
===

[](#预下单)

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

// 微信小程序
$pay= Weixin::init($config)->set("订单号","金额","描述","描述")->getParam();

// 微信公众号【appid 和secret 换成公众号的】
$pay= Weixin::init($config)->set("订单号","金额","描述","openid")->getParam();

// 微信H5【appid 和secret 换成公众号的】
$pay= Weixin::init($config)->set("订单号","金额","描述")->getH5Param();

// 微信APP (没有openid)
$pay= Weixin::init($config)->set("订单号","金额","描述")->getParam();
```

### Config

[](#config)

参数名字类型必须说明appidint是小程序 appidsecretint是小程序 secretmch\_idstring是商户 mch\_idmch\_keystring是商户 mch\_keynotify\_urlstring是异步地址cert\_pemstring是cert\_pem 证书key\_pemstring是key\_pem 证书trade\_typestring是默认为：JSAPI。MWEB：代表微信 H5 、JSAPI：公众号或小程序### Token

[](#token)

```
$data= Weixin::init($config)->getToken();
```

返回参数类型必须说明expires\_instring是凭证有效时间，单位：秒access\_tokenstring是获取到的凭证### Openid

[](#openid)

```
$code="";
$data= Weixin::init($config)->getOpenid($code);
```

返回参数类型必须说明session\_keystring是session\_keyopenidstring是用户 openidunionidstring是unionid### 解密手机号

[](#解密手机号)

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

### 订单查询

[](#订单查询)

```
$data = Weixin::init($config)->findOrder("订单号");
```

### 退款

[](#退款)

参数名字类型必须说明out\_trade\_nostring是平台订单号out\_refund\_nostring是自定义订单号refund\_feeint是退款金额total\_feeint是订单金额refund\_descstring是退款原因```
$order = [
        'out_trade_no' => '123',
        'total_fee' => 0.01,
        'out_refund_no' => time(),
        'refund_fee' => 0.01,
    ];
$data= Weixin::init($config)->applyOrderRefund($order);
```

### 模版消息

[](#模版消息)

```
$data = [
    "touser" => "",
    "template_id" => "",
    "page" => "pages/index/index",
    "miniprogram_state" => "developer",
    "lang" => "zh_CN",
    "data" => [
        'thing6' => ['value' => "第一个参数{{thing6.DATA}}"],
        'thing7' => ['value' => "第二个参数{{thing7.DATA}}"],
        'time8' =>  ['value' => "第三个参数{{time8.DATA}}"],
],
$data= Weixin::init($config)->sendMsg($data,$token);
$data=[
    "errcode" => 0
    "errmsg" => "ok"
    "msgid" => 123456
]
```

支付回调
----

[](#支付回调)

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

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

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

1025d ago

### Community

Maintainers

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

---

Top Contributors

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

### Embed Badge

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

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

###  Alternatives

[omnipay/paypal

PayPal gateway for Omnipay payment processing library

3156.8M53](/packages/omnipay-paypal)[eduardokum/laravel-boleto

Biblioteca com boletos para o laravel

626351.9k2](/packages/eduardokum-laravel-boleto)[tbbc/money-bundle

This is a Symfony bundle that integrates moneyphp/money library (Fowler pattern): https://github.com/moneyphp/money.

1961.9M](/packages/tbbc-money-bundle)[2checkout/2checkout-php

2Checkout PHP Library

83740.3k2](/packages/2checkout-2checkout-php)[smhg/sepa-qr-data

Generate QR code data for SEPA payments

61717.2k5](/packages/smhg-sepa-qr-data)[omnipay/dummy

Dummy driver for the Omnipay payment processing library

271.2M33](/packages/omnipay-dummy)

PHPackages © 2026

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