karser / sms-bundle
Symfony SMSBundle
dev-master
2014-02-08 12:37 UTC
Requires
- php: >=5.3.2
- symfony/framework-bundle: >=2.1,<3.0
Suggests
- doctrine/doctrine-bundle: >1.0.0
- doctrine/orm: >=2.2.3,<2.4-dev
This package is auto-updated.
Last update: 2024-09-20 06:34:43 UTC
README
先决条件
此版本的包需要Symfony 2.1+和Doctrine ORM 2.2+
安装
步骤 1: 使用composer下载KarserSMSBundle
在composer.json中添加KarserSMSBundle
{ "require": { "karser/sms-bundle": "dev-master", } }
现在运行以下命令让composer下载包
$ php ./composer.phar update
Composer会将包安装到您的项目目录vendor/karser
中。
步骤 2: 启用包
在kernel中启用包
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Karser\SMSBundle\KarserSMSBundle(), ); }
步骤 3: 配置KarserSMSBundle
根据您使用的存储类型,将以下配置添加到您的config.yml
文件中。
# app/config/config.yml karser_sms: sms_task_class: Acme\SMSBundle\Entity\SmsTask default_handler: karser.handler.main_sms #or karser.handler.sms_vesti
更新您的模式
app/console doctrine:schema:update --force
步骤 4: 实现 sms_task 实体
<?php namespace Your\Module\Entity; use Karser\SMSBundle\Entity\SmsTask as BaseClass; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Table * @ORM\Entity * @ORM\HasLifecycleCallbacks */ class SmsTask extends BaseClass { /** * @ORM\Column(type="string", length=20) * * @var string */ protected $ipAddress; /** * @ORM\Column(type="string", length=50) * * @var string */ protected $sessionId; /** * @ORM\Column(type="bigint", nullable=true) * * @var int */ protected $userId; /** * @var \DateTime * * @ORM\Column(type="datetime", nullable=false) */ protected $createdAt; /** * @ORM\PrePersist */ public function prePersist() { $this->createdAt = new \DateTime(); } /** * @param string $sessionId */ public function setSessionId($sessionId) { $this->sessionId = $sessionId; } /** * @return string */ public function getSessionId() { return $this->sessionId; } /** * @param int $userId */ public function setUserId($userId) { $this->userId = $userId; } /** * @return int */ public function getUserId() { return $this->userId; } /** * @param string $ipAddress */ public function setIpAddress($ipAddress) { $this->ipAddress = $ipAddress; } /** * @return string */ public function getIpAddress() { return $this->ipAddress; } /** * Set createdAt * * @param \DateTime $createdAt * @return SmsTask */ public function setCreatedAt($createdAt) { $this->createdAt = $createdAt; return $this; } /** * Get createdAt * * @return \DateTime */ public function getCreatedAt() { return $this->createdAt; } }
步骤 5: 可用后端
使用步骤
$task = new \Your\Module\Entity\SmsTask(); $task->setPhoneNumber('+799999999999'); $task->setMessage('ni hao'); $task->setSender('your_friend'); $handler = $container->get('karser.sms.manager')->getDefaultHandler(); $msg_id = $handler->send($task); $status = $handler->checkStatus($task->getMessageId()); if ($status === SMSTaskInterface::STATUS_PROCESSING) { //is sent }