serwersms / serwersmsbundle
这是一个用于与SerwerSMS.pl API v2通信的Symfony2,3,4 Bundle
1.0.3
2019-05-27 11:33 UTC
Requires
- php: >=5.3.9
This package is auto-updated.
Last update: 2024-09-19 10:03:52 UTC
README
PHP客户端,用于Symfony(版本2,3,4)框架,用于远程通信API v2 SerwerSMS.pl
建议通过HTTPS API进行通信时使用专门用于通过API连接的登录名。可以在“客户面板”→“接口设置”→“HTTP API”→“API用户”中创建API用户账户。
安装
安装通过composer进行,并在composer.json文件中添加以下代码
{ "require": { "serwersms/serwersmsbundle" : "1.0.3" } }
发送SMS Symfony 4
#service.yml
parameters: serwer_sms_username: "username" serwer_sms_password: "password" serwer_sms_api_url: "https://api2.serwersms.pl/" serwer_sms_format: "json"
控制器
namespace App\Controller; use SerwerSMS\SerwerSMSBundle\SerwerSMS\SerwerSMS; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; class TestController extends AbstractController { public function index(SerwerSMS $serwersms) { try{ $result = $serwersms->messages->sendSms( array( '+48500600700', '+48600700800' ), 'Test FULL message', 'INFORMACJA', array( 'test' => true, 'details' => true ) ); die(var_dump($result)); } catch(Exception $e){ echo 'ERROR: '.$e->getMessage(); } } }
发送SMS Symfony 2,3
AppKernel.php
class AppKernel extends Kernel { public function registerBundles() { $bundles = array( ... new SerwerSMS\SerwerSMSBundle\SerwerSMSBundle(), ); ... return $bundles; } }
config.php
parameters: serwer_sms_username: "username" serwer_sms_password: "password" serwer_sms_api_url: "https://api2.serwersms.pl/" serwer_sms_format: "json"
App
try{ $serwersms = $this->get('serwer_sms'); // SMS FULL $result = $serwersms->messages->sendSms( array( '+48500600700', '+48600700800' ), 'Test FULL message', 'INFORMACJA', array( 'test' => true, 'details' => true ) ); // SMS ECO $result = $serwersms->messages->sendSms( array( '+48500600700', '+48600700800' ), 'Test ECO message', null, array( 'test' => true, 'details' => true ) ); // VOICE from text $result = $serwersms->messages->sendVoice( array( '+48500600700', '+48600700800' ), array( 'text' => 'Test message', 'test' => true, 'details' => true ) ); // MMS $list = $serwersms->files->index('mms'); $result = $serwersms->messages->sendMms( array( '+48500600700', '+48600700800' ), 'MMS Title', array( 'test' => true, 'file_id' => $list->items[0]->id, 'details' => true ) ); echo 'Skolejkowano: '.$result->queued.'<br />'; echo 'Niewysłano: '.$result->unsent.'<br />'; foreach($result->items as $sms){ echo 'ID: '.$sms->id.'<br />'; echo 'NUMER: '.$sms->phone.'<br />'; echo 'STATUS: '.$sms->status.'<br />'; echo 'CZĘŚCI: '.$sms->parts.'<br />'; echo 'WIADOMOŚĆ: '.$sms->text.'<br />'; } } catch(Exception $e){ echo 'ERROR: '.$e->getMessage(); }
发送个性化SMS
try{ $serwersms = $this->get('serwer_sms'); $messages[] = array( 'phone' => '500600700', 'text' => 'First message' ); $messages[] = array( 'phone' => '600700800', 'text' => 'Second message' ); $result = $serwersms->messages->sendPersonalized( $messages, 'INFORMACJA', array( 'test' => true, 'details' => true ) ); echo 'Skolejkowano: '.$result->queued.'<br />'; echo 'Niewysłano: '.$result->unsent.'<br />'; foreach($result->items as $sms){ echo 'ID: '.$sms->id.'<br />'; echo 'NUMER: '.$sms->phone.'<br />'; echo 'STATUS: '.$sms->status.'<br />'; echo 'CZĘŚCI: '.$sms->parts.'<br />'; echo 'WIADOMOŚĆ: '.$sms->text.'<br />'; } } catch(Exception $e){ echo 'ERROR: '.$e->getMessage(); }
获取投递报告
try{ $serwersms = $this->get('serwer_sms'); // Get messages reports $result = $serwersms->messages->reports(array('id' => array('aca3944055'))); foreach($result->items as $sms){ echo 'ID: '.$sms->id.'<br />'; echo 'NUMER: '.$sms->phone.'<br />'; echo 'STATUS: '.$sms->status.'<br />'; echo 'SKOLEJKOWANO: '.$sms->queued.'<br />'; echo 'WYSŁANO: '.$sms->sent.'<br />'; echo 'DORĘCZONO: '.$sms->delivered.'<br />'; echo 'NADAWCA: '.$sms->sender.'<br />'; echo 'TYP: '.$sms->type.'<br />'; echo 'WIADOMOŚĆ: '.$sms->text.'<br />'; } } catch(Exception $e){ echo 'ERROR: '.$e->getMessage(); }
获取接收消息
try{ $serwersms = $this->get('serwer_sms'); // Get recived messages $result = $serwersms->messages->recived('ndi'); foreach($result->items as $sms){ echo 'ID: '.$sms->id.'<br />'; echo 'TYP: '.$sms->type.'<br />'; echo 'NUMER: '.$sms->phone.'<br />'; echo 'DATA: '.$sms->recived.'<br />'; echo 'CZARNA LISTA: '.$sms->blacklist.'<br />'; echo 'WIADOMOŚĆ: '.$sms->text.'<br />'; } } catch(Exception $e){ echo 'ERROR: '.$e->getMessage(); }
要求
php >= 5.3.9
symfony >= 2.7.*
文档
API控制台