tourze / yunpian-sms-bundle
云片短信
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^8.1
- doctrine/dbal: ^4.0
- doctrine/doctrine-bundle: ^2.13
- doctrine/orm: ^3.0
- doctrine/persistence: ^3.1 || ^4
- psr/log: ^3|^2|^1
- symfony/config: ^6.4
- symfony/console: ^6.4
- symfony/dependency-injection: ^6.4
- symfony/doctrine-bridge: ^6.4
- symfony/framework-bundle: ^6.4
- symfony/http-client: ^6.4
- symfony/http-client-contracts: ^2.5 | ^3.0
- symfony/http-kernel: ^6.4
- symfony/yaml: ^6.4 || ^7.1
- tourze/doctrine-indexed-bundle: 0.0.*
- tourze/doctrine-timestamp-bundle: 0.0.*
- tourze/doctrine-track-bundle: 0.1.*
- tourze/easy-admin-attribute: 0.1.*
- tourze/enum-extra: ~0.0.5
- tourze/symfony-cron-job-bundle: 0.1.*
- yiisoft/json: ^1.0
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2025-06-11 22:09:49 UTC
README
A Symfony bundle that integrates with Yunpian SMS Service API for sending and managing SMS messages.
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
- PHP >= 8.1
- Symfony Framework >= 6.4
- Doctrine ORM
Installation
Step 1: Add the dependency with Composer
composer require tourze/yunpian-sms-bundle
Step 2: Register the bundle in config/bundles.php
return [ // ... YunpianSmsBundle\YunpianSmsBundle::class => ['all' => true], ];
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
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
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
// 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
// Sync templates from Yunpian to local database $this->templateService->syncTemplates($account); // Get all templates $templates = $this->templateRepository->findBy(['account' => $account]);
API Documentation
For detailed API documentation, please refer to the Yunpian SMS Official Documentation
Contributing
Please see CONTRIBUTING.md for details.
License
This bundle is released under the MIT License. See the LICENSE file for more details.