tourze/wechat-pay-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tourze/wechat-pay-bundle

Composer 安装命令:

composer require tourze/wechat-pay-bundle

包简介

微信支付集成包,提供统一支付接口和账单管理功能

README 文档

README

Latest Version PHP Version License Test Status Code Coverage Total Downloads

English | 中文

WeChat Pay integration for Symfony applications, providing payment order management, refund processing, and automated bill synchronization.

Table of Contents

Features

  • WeChat Pay order creation and management
  • Refund order processing
  • Automated bill downloading
  • Order status synchronization
  • Multi-merchant support
  • Payment callback handling

Installation

composer require tourze/wechat-pay-bundle

Configuration

Register the bundle in your Symfony application:

// config/bundles.php
return [
    // ...
    WechatPayBundle\WechatPayBundle::class => ['all' => true],
];

Console Commands

Download Fund Flow Bill

php bin/console wechat:pay:download-fund-flow-bill

Downloads WeChat Pay fund flow bills. Runs automatically at 10:00 and 11:00 daily, fetching the last 7 days of fund statements.

Download Trade Bill

php bin/console wechat:pay:download-trade-bill

Downloads WeChat Pay trade bills. Runs automatically at 10:00 and 11:00 daily, fetching the last 7 days of transaction records.

Check Order Expiration

php bin/console wechat:pay:check-order-expire

Checks and updates expired payment orders. Runs every minute to query orders that have expired but are still in INIT status.

Check Refund Status

php bin/console wechat:refund:check-order-status

Checks and updates refund order status. Runs every minute to query refunds in PROCESSING status and update their actual status.

Entities

  • PayOrder - Payment order entity with order management
  • RefundOrder - Refund order entity with goods detail support
  • RefundGoodsDetail - Refund goods detail entity
  • Merchant - Merchant configuration entity
  • TradeBill - Trade bill record entity
  • FundFlowBill - Fund flow bill record entity

Enums

  • PayOrderStatus - Payment order status enumeration
  • AccountType - WeChat Pay account type enumeration
  • BillType - Bill type enumeration

Services

  • UnifiedOrder - Creates payment orders for various trade types
  • WechatAppPayService - Handles APP payment order creation
  • WechatJsApiPayService - Handles JSAPI payment order creation
  • WechatPayBuilder - Builds WeChat Pay API clients
  • AttributeControllerLoader - Loads controller attributes for routing

Usage Example

// Create a payment order
$params = new AppOrderParams();
$params->setMchId('your_merchant_id');
$params->setAppId('your_app_id');
// ... set other parameters
$payOrder = $unifiedOrder->createAppOrder($params);

// Refund processing is handled automatically via RefundOrder entity
$refundOrder = new RefundOrder();
$refundOrder->setPayOrder($payOrder);
$refundOrder->setMoney($amount);
$refundOrder->setReason($reason);
$entityManager->persist($refundOrder);
$entityManager->flush(); // This triggers the refund via RefundOrderListener

Advanced Usage

Custom Payment Processing

use WechatPayBundle\Service\UnifiedOrder;
use WechatPayBundle\Request\AppOrderParams;

class CustomPaymentService
{
    public function __construct(private UnifiedOrder $unifiedOrder) {}
    
    public function processCustomPayment(array $orderData): array
    {
        $params = new AppOrderParams();
        $params->setMchId($orderData['merchant_id']);
        $params->setAppId($orderData['app_id']);
        $params->setContractId($orderData['order_id']);
        $params->setDescription($orderData['description']);
        $params->setMoney($orderData['amount']);
        
        return $this->unifiedOrder->createAppOrder($params);
    }
}

Handling Payment Callbacks

use WechatPayBundle\Entity\PayOrder;
use WechatPayBundle\Enum\PayOrderStatus;

class PaymentCallbackHandler
{
    public function handleCallback(array $callbackData): void
    {
        $orderId = $callbackData['out_trade_no'];
        $payOrder = $this->findPayOrder($orderId);
        
        if ($callbackData['result_code'] === 'SUCCESS') {
            $payOrder->setStatus(PayOrderStatus::SUCCESS);
            $payOrder->setPayTime(new \DateTime());
        } else {
            $payOrder->setStatus(PayOrderStatus::FAIL);
        }
        
        $this->entityManager->flush();
    }
}

Multi-Merchant Configuration

use WechatPayBundle\Entity\Merchant;

class MerchantService
{
    public function configureMerchant(string $mchId, string $pemKey): Merchant
    {
        $merchant = new Merchant();
        $merchant->setMchId($mchId);
        $merchant->setPemKey($pemKey);
        $merchant->setIsActive(true);
        
        $this->entityManager->persist($merchant);
        $this->entityManager->flush();
        
        return $merchant;
    }
}

Development Guide

Database Migrations

Use Doctrine migrations to manage database schema:

php bin/console doctrine:migrations:migrate

Testing

Run unit tests:

./vendor/bin/phpunit packages/wechat-pay-bundle/tests

Events

This bundle provides the following events:

  • AppPayCallbackSuccessEvent - Triggered after successful APP payment callback
  • JSAPIPayCallbackSuccessEvent - Triggered after successful JSAPI payment callback
  • NativePayCallbackSuccessEvent - Triggered after successful Native payment callback

Entity Listeners

  • PayOrderListener - Handles payment order lifecycle events
  • RefundOrderListener - Handles refund order lifecycle events

Dependencies

This bundle requires the following packages:

Core Dependencies

  • php: ^8.1
  • symfony/framework-bundle: ^7.3
  • doctrine/orm: ^3.0
  • wechatpay/wechatpay: ^1.4
  • nesbot/carbon: ^2.72 || ^3
  • league/flysystem: ^3.10
  • yiisoft/json: ^1.0
  • yiisoft/arrays: ^3

Tourze Internal Dependencies

  • tourze/doctrine-snowflake-bundle: 0.1.*
  • tourze/symfony-snowflake-bundle: 0.0.*
  • tourze/http-client-bundle: 0.1.*
  • tourze/symfony-cron-job-bundle: 0.1.*
  • tourze/doctrine-timestamp-bundle: 0.0.*
  • tourze/doctrine-track-bundle: 0.1.*
  • tourze/enum-extra: 0.1.*
  • tourze/file-storage-bundle: 0.0.*
  • tourze/xml-helper: 0.0.*

Contributing

We welcome Pull Requests and Issues. Please ensure:

  1. Follow PSR-12 coding standards
  2. Add appropriate unit tests
  3. Update relevant documentation

License

This bundle is part of the Tourze monorepo project.

tourze/wechat-pay-bundle 适用场景与选型建议

tourze/wechat-pay-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 391 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 05 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 tourze/wechat-pay-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 tourze/wechat-pay-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 tourze/wechat-pay-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 391
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 8
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-09