https://github.com/zhangv/wechat-pay
Simplest WechatPay(最简单的微信支付)
https://github.com/zhangv/wechat-pay
pay php tool wechat wechatpay weixin
Last synced: 4 months ago
JSON representation
Simplest WechatPay(最简单的微信支付)
- Host: GitHub
- URL: https://github.com/zhangv/wechat-pay
- Owner: zhangv
- License: mit
- Created: 2015-02-22T14:53:11.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2024-06-15T03:24:34.000Z (about 2 years ago)
- Last Synced: 2025-08-18T20:00:06.554Z (10 months ago)
- Topics: pay, php, tool, wechat, wechatpay, weixin
- Language: PHP
- Homepage:
- Size: 274 KB
- Stars: 56
- Watchers: 5
- Forks: 37
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# WechatPay - 微信支付
[](https://packagist.org/packages/zhangv/wechat-pay)
[](https://packagist.org/packages/zhangv/wechat-pay)
[](https://travis-ci.org/zhangv/wechat-pay)
[](https://codecov.io/gh/zhangv/wechat-pay)
[](https://scrutinizer-ci.com/g/zhangv/wechat-pay/?branch=master)
[](https://zhangv.com)
#### simplest, minimal dependency
### Feature
* 使用简单
* 支持php-7x
* 不依赖第三方库(但依赖json、simpleXML、openssl、curl扩展)
* 100%测试覆盖
* 支持所有付款方式(公众号、APP、小程序、H5、扫码、刷卡)
* 支持企业付款、红包、代金券
### Install
```
composer require zhangv/wechat-pay
```
### Demo
* 配置参数
```php
$cfg = [
'mch_id' => 'XXXX', //商户号
'app_id' => 'XXXXXXXXXXXXXXXXXXX', //APPID
'app_secret' => 'XXXXXXXXXXXXXXXXXXXXXXXXX', //App Secret
'api_key' =>'XXXXXXXXXXXXXXXXXXXXXXX', //支付密钥
'ssl_cert_path' => __DIR__ . '/../cert/apiclient_cert.pem', //SSL证书(通过商户后台下载)
'ssl_key_path' => __DIR__ .'/../cert/apiclient_key.pem', //SSL密钥(通过商户后台下载)
'sign_type' => 'MD5',
'notify_url' => 'http://XXX.XXX/paidnotify.php', //支付结果通知地址
'refund_notify_url' => 'http://XXX.XXX/refundednotify.php', //退款结果通知地址
'h5_scene_info' => [//H5支付时需要
'h5_info' => ['type' => 'Wap', 'wap_url' => 'http://wapurl', 'wap_name' => 'wapname']
],
'rsa_pubkey_path' => __DIR__ .'/../cert/pubkey.pem',
'jsapi_ticket' => __DIR__ .'/jsapi_ticket.json' //jsticket的临时存放路径
];
```
* 获取公众号支付参数(公众号网页支付)
```php
$wp = WechatPay::Jsapi($cfg);
$prepayId = $wp->getPrepayId($body, $orderNo, $amt, $openid);
$package = $wp->getPackage($prepayId);
```
* 获取小程序支付参数(小程序支付)
```php
$wp = WechatPay::Weapp($cfg);
$prepayId = $wp->getPrepayId($body, $orderNo, $amt, $openid);
$package = $wp->getPackage($prepayId);
```
* 获取APP的支付参数(APP支付)
```php
$wp = WechatPay::App($cfg);
$prepayId = $wp->getPrepayId($body, $orderNo, $amt, $openid);
$package = $wp->getPackage($prepayId);
```
* 获取H5支付URL(H5支付)
```php
$wp = WechatPay::Mweb($cfg);
$url = $wp->getMwebUrl($body,$orderNo,$amt);
```
* 获取扫码支付URL(扫码支付)
```php
$wp = WechatPay::Native($cfg);
$url = $wp->getCodeUrl($body,$out_trade_no,$total_fee,$product_id);
```
* 提交支付授权码(刷卡支付)
```php
$wp = WechatPay::Micro($cfg);
$url = $wp->microPay($body,$out_trade_no,$total_fee,$spbill_create_ip,$auth_code);
```
* 支付结果后台通知处理
```php
$notifyxml = file_get_contents("php://input");
$wp = new WechatPay($cfg);
$msg = $wp->onPaidNotify($notifyxml, function($notifyArray){
//处理逻辑
return 'ok';
});
$xml = "
SUCCESS
";
echo $xml;
```
* 退款
```php
$wxpay = new WechatPay($cfg);
$result = $wxpay->refundByOutTradeNo($out_trade_no,$out_refund_no,$total_fee,$refund_fee);
```
* 企业付款
```php
$wp = WechatPay::Mchpay($cfg);
//付款到零钱
$result = $wp->transferWallet($partner_trade_no,$openid,$amount,$desc);
//付款到银行卡
$result = $wp->transferBankCard($partner_trade_no,$bank_no,$true_name,$bank_code,$amount,$desc);
```
* 红包
```php
$wp = WechatPay::Redpack($cfg);
//发放普通红包
$result = $wp->sendRedPack($mch_billno,$send_name,$re_openid,$total_amount,$total_num,$wishing,$act_name,$remark);
//发放裂变红包
$result = $wp->sendGroupRedPack($mch_billno,$send_name,$re_openid,$total_amount,$total_num,$wishing,$act_name,$remark);
```
* 代金券
```php
$wp = WechatPay::Coupon($cfg);
//发放代金券
$result = $wp->sendCoupon($coupon_stock_id,$open_id,$partner_trade_no);
//查询代金券批次
$result = $wp->queryCouponStock($coupon_stock_id);
```