serwer/sms

这是一个用于与API v2 SerwerSMS.pl通信的Laravel包

dev-master 2024-08-19 09:46 UTC

This package is not auto-updated.

Last update: 2024-09-24 11:04:43 UTC


README

PHP客户端,用于远程通信API v2 SerwerSMS.pl

建议通过HTTPS API进行通信,使用专门为通过API连接而创建的登录名。您可以在客户面板 → 设置接口 → HTTP API → API用户中创建API用户账户。

安装

安装通过composer进行,将以下代码添加到composer.json文件中

    {
        "require": {
            "serwer/sms": "dev-master"
        }
        ...
        "repositories" : [{
            "type" : "vcs",
            "url" : "https://github.com/SerwerSMSpl/serwersms-laravel5.git"
         }],
    }

发送短信

app/config/app.php

    return [
	    ...
	    ...
	    'providers' => [
	        ...
	        ...
	        Serwer\Sms\SmsServiceProvider::class,
	    ],
	    'sms'=>[
			'username' => 'username',
			'password' => 'password',
			'api_url'  => 'https://api2.serwersms.pl/',
			'format'   => 'json'
		]
    ]

Controller.php

	try{
	
	    $serwersms = new \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();
	}

发送个性化短信

	try{
	
	    $serwersms = new \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 = new \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 = new \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 >=7.*

Laravel = 5.*

文档

http://dev.serwersms.pl

API控制台

http://apiconsole.serwersms.pl/