PHPackages                             tourze/yunpian-sms-bundle - 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. [Mail &amp; Notifications](/categories/mail)
4. /
5. tourze/yunpian-sms-bundle

ActiveSymfony-bundle[Mail &amp; Notifications](/categories/mail)

tourze/yunpian-sms-bundle
=========================

云片短信服务集成包，提供短信发送、模板管理、签名管理等功能

0.1.0(6mo ago)00MITPHPCI failing

Since May 25Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/tourze/yunpian-sms-bundle)[ Packagist](https://packagist.org/packages/tourze/yunpian-sms-bundle)[ RSS](/packages/tourze-yunpian-sms-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (40)Versions (3)Used By (0)

YunpianSmsBundle
================

[](#yunpiansmsbundle)

[English](README.md) | [中文](README.zh-CN.md)

[![Latest Version](https://camo.githubusercontent.com/cc2d239e80786ad949823810abb7dd71301aa313e8729b6e278790fb1f264db8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f75727a652f79756e7069616e2d736d732d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/yunpian-sms-bundle)[![Total Downloads](https://camo.githubusercontent.com/b0d099d6b4fe1fe797dffc8d980d7a5e3731d2406bbdeee7bec49c69f93c64d6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f75727a652f79756e7069616e2d736d732d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/yunpian-sms-bundle)[![License](https://camo.githubusercontent.com/e80ea4112e2b39788cea9746bc52bdf496457bd24b418452381bff64933b6cce/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746f75727a652f79756e7069616e2d736d732d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/yunpian-sms-bundle)[![PHP Version](https://camo.githubusercontent.com/0aac200a1ee69412bef7774788a40377094d66f4de2e25a24437992126710bec/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746f75727a652f79756e7069616e2d736d732d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/yunpian-sms-bundle)[![Code Coverage](https://camo.githubusercontent.com/5f23127cbf3f724cb6b9d4214493c3f3bcdccc22b7543a7faf07b827908d68b9/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f746f75727a652f7068702d6d6f6e6f7265706f2f6d61696e2e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/gh/tourze/php-monorepo)

A Symfony bundle that integrates with [Yunpian SMS Service](https://www.yunpian.com/official/document/sms/zh_CN/domestic_list) API for sending and managing SMS messages.

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Requirements](#requirements)
- [Installation](#installation)
- [Configuration](#configuration)
- [Quick Start](#quick-start)
- [Console Commands](#console-commands)
- [Advanced Usage](#advanced-usage)
- [API Documentation](#api-documentation)
- [Testing](#testing)
- [Contributing](#contributing)
- [Security](#security)
- [Credits](#credits)
- [License](#license)

Features
--------

[](#features)

- Send domestic SMS messages
- Manage SMS templates
- Query sending records
- Check account balance
- Sign management
- Daily consumption statistics
- Full integration with Symfony framework

Requirements
------------

[](#requirements)

- PHP &gt;= 8.1
- Symfony Framework &gt;= 6.4
- Doctrine ORM

Installation
------------

[](#installation)

### Step 1: Add the dependency with Composer

[](#step-1-add-the-dependency-with-composer)

```
composer require tourze/yunpian-sms-bundle
```

### Step 2: Register the bundle in `config/bundles.php`

[](#step-2-register-the-bundle-in-configbundlesphp)

```
return [
    // ...
    YunpianSmsBundle\YunpianSmsBundle::class => ['all' => true],
];
```

Configuration
-------------

[](#configuration)

This bundle requires you to create at least one account in the database. The `Account` entity stores the API key required for authentication with Yunpian's services.

You can create an account by inserting a record into the `ims_yunpian_account` table or use the admin interface if available:

```
use YunpianSmsBundle\Entity\Account;

// Create a new account
$account = new Account();
$account->setApiKey('your_yunpian_api_key');
$account->setValid(true);
$account->setRemark('Main Account');

// Persist the account
$entityManager->persist($account);
$entityManager->flush();
```

Quick Start
-----------

[](#quick-start)

### 1. Send SMS

[](#1-send-sms)

```
use YunpianSmsBundle\Service\SendLogService;
use YunpianSmsBundle\Repository\AccountRepository;

class YourService
{
    public function __construct(
        private readonly SendLogService $sendLogService,
        private readonly AccountRepository $accountRepository,
    ) {
    }

    public function sendMessage(): void
    {
        $account = $this->accountRepository->findOneBy(['valid' => true]);

        $this->sendLogService->send(
            account: $account,
            mobile: '13800138000',
            content: 'Your verification code is 1234'
        );
    }
}
```

### 2. Send SMS using template

[](#2-send-sms-using-template)

```
use YunpianSmsBundle\Repository\TemplateRepository;

// In your service method
$account = $this->accountRepository->findOneBy(['valid' => true]);
$template = $this->templateRepository->findOneBy(['tplId' => 'your_template_id']);

$this->sendLogService->sendTpl(
    account: $account,
    template: $template,
    mobile: '13800138000',
    tplValue: ['code' => '1234']
);
```

### 3. Query send records

[](#3-query-send-records)

```
// Set up request parameters
$request = new GetSendRecordRequest();
$request->setAccount($account);
$request->setStartTime(new \DateTime('-7 days'));
$request->setEndTime(new \DateTime());

// Get the records
$response = $this->apiClient->request($request);
```

### 4. Manage templates

[](#4-manage-templates)

```
// Sync templates from Yunpian to local database
$this->templateService->syncTemplates($account);

// Get all templates
$templates = $this->templateRepository->findBy(['account' => $account]);
```

Console Commands
----------------

[](#console-commands)

This bundle provides several console commands for synchronizing data with Yunpian SMS platform:

### `yunpian:sync-daily-consumption`

[](#yunpiansync-daily-consumption)

Synchronize daily SMS consumption data for all valid accounts.

```
# Sync yesterday's consumption data (default)
php bin/console yunpian:sync-daily-consumption

# Sync consumption data for a specific date
php bin/console yunpian:sync-daily-consumption --date=2024-01-15
```

**Options:**

- `--date` / `-d`: Sync data for a specific date (format: Y-m-d)

**Scheduled Task:** This command runs automatically every 4 hours at the 15th minute (cron: `15 */4 * * *`)

### `yunpian:sync-send-record`

[](#yunpiansync-send-record)

Synchronize SMS sending records for all valid accounts.

```
# Sync recent send records
php bin/console yunpian:sync-send-record

# Sync records within a specific time range
php bin/console yunpian:sync-send-record \
  --start-time="2024-01-01 00:00:00" \
  --end-time="2024-01-31 23:59:59"

# Sync records for a specific mobile number
php bin/console yunpian:sync-send-record --mobile=13800138000
```

**Options:**

- `--start-time` / `-s`: Start time for synchronization (format: Y-m-d H:i:s)
- `--end-time` / `-e`: End time for synchronization (format: Y-m-d H:i:s)
- `--mobile` / `-m`: Filter by mobile number

**Scheduled Task:** This command runs automatically every 4 hours (cron: `0 */4 * * *`)

### `yunpian:sync-send-status`

[](#yunpiansync-send-status)

Synchronize SMS sending status updates for pending messages.

```
php bin/console yunpian:sync-send-status
```

**Scheduled Task:** This command runs automatically every 5 minutes (cron: `*/5 * * * *`)

### `yunpian:sync-sign`

[](#yunpiansync-sign)

Synchronize SMS signatures from Yunpian platform.

```
php bin/console yunpian:sync-sign
```

**Note:** This command needs to be run manually when signature updates are required.

### `yunpian:sync-template`

[](#yunpiansync-template)

Synchronize SMS templates from Yunpian platform.

```
php bin/console yunpian:sync-template
```

**Note:** This command needs to be run manually when template updates are required.

Advanced Usage
--------------

[](#advanced-usage)

### Custom SMS Transport

[](#custom-sms-transport)

You can use the Yunpian SMS transport with Symfony Notifier:

```
use YunpianSmsBundle\Service\NotifierSmsTransport;
use Symfony\Component\Notifier\Notification\Notification;
use Symfony\Component\Notifier\Recipient\SmsRecipientInterface;

// In your service
$transport = $this->container->get(NotifierSmsTransport::class);
$notification = new Notification('Your verification code is 1234');
$recipient = new SmsRecipient('13800138000');

$transport->send($notification, $recipient);
```

### Event Subscribers

[](#event-subscribers)

The bundle provides event subscribers for automatic template and signature synchronization:

- `TemplateSubscriber`: Automatically syncs templates when template entities are modified
- `SignSubscriber`: Automatically syncs signatures when sign entities are modified

### Admin Interface

[](#admin-interface)

If you're using EasyAdmin, this bundle provides CRUD controllers for managing:

- Accounts (`AccountCrudController`)
- Templates (`TemplateCrudController`)
- Send Logs (`SendLogCrudController`)
- Signs (`SignCrudController`)
- Daily Consumption (`DailyConsumptionCrudController`)

API Documentation
-----------------

[](#api-documentation)

For detailed API documentation, please refer to the [Yunpian SMS Official Documentation](https://www.yunpian.com/official/document/sms/zh_CN/domestic_list)

Testing
-------

[](#testing)

Run the test suite with PHPUnit:

```
./vendor/bin/phpunit packages/yunpian-sms-bundle/tests
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Tourze](https://github.com/tourze)
- [All Contributors](../../contributors)

License
-------

[](#license)

This bundle is released under the MIT License. See the [LICENSE](LICENSE) file for more details.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance72

Regular maintenance activity

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity28

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.

###  Release Activity

Cadence

Every ~169 days

Total

2

Last Release

182d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e354fdb316da535dfa8ba2e9193a473c403b6bc6fb9170778d1dc50e304c6e9d?d=identicon)[tourze](/maintainers/tourze)

---

Top Contributors

[![tourze](https://avatars.githubusercontent.com/u/13899502?v=4)](https://github.com/tourze "tourze (2 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-yunpian-sms-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/tourze-yunpian-sms-bundle/health.svg)](https://phpackages.com/packages/tourze-yunpian-sms-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

7310.3k29](/packages/open-dxp-opendxp)

PHPackages © 2026

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