定制 laravel-notification-channels/vodafone 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

laravel-notification-channels/vodafone

Composer 安装命令:

composer require laravel-notification-channels/vodafone

包简介

Send Laravel Notifications via the Vodafone SMS API

README 文档

README

Latest Version on Packagist Software License Build Status StyleCI Quality Score Code Coverage Total Downloads

This package makes it easy to send sms notifications using Vodafone with Laravel 5.5+ and 6.x

Building on Laravel's Notification channel, this package allows you to send SMS notifications via the Vodafone SMS gateway service.

Sending an SMS to a user becomes as simple as using:

$user->notify(new Notification())

Contents

Installation

Install the package using composer

composer require laravel-notification-channels/vodafone

Add the configuration to your services.php config file:

'vodafone' => [
    'username' => env('VODAFONE_USERNAME'),
    'password' => env('VODAFONE_PASSWORD'),
]

Setting up the Vodafone service

Using the Vodafone SMS service requires an account with Vodafone, which can be arranged from this location: https://www.vodafone.com.au/messaging/smser

After being provided with your Vodafone account you will receive an API username and password, these need to be entered into your env or config file.

The Vodafone service has the option to send messages with an alpha tag so instead of appearing from a miscellaneous number they come from a pre-defined name.

Usage

Sending Text Message

Within your notification you need to add the Vodafone channel to your via() method:

use Illuminate\Notifications\Notification;
use NotificationChannels\Vodafone\VodafoneChannel;
use NotificationChannels\Vodafone\VodafoneMessage;

class Invitation extends Notification
{
    public function via($notifiable)
    {
        return [VodafoneChannel::class];
    }

    public function toVodafone($notifiable)
    {
        return (new VodafoneMessage)
            ->content($this->content)
            ->from('My App');
    }

In your notifiable model, make sure to include a routeNotificationForVodafone() method, which should return a full mobile number including country code.

public function routeNotificationForVodafone()
{
    return $this->phone;
}

Available Message methods

content(): Sets the message content of the SMS

from(): Sets the qualified sender of the message

Retrieving Text Messages

The VodafoneClient class comes with a 'receive' method for retrieving messages from the Vodafone server.

Note: It only returns unread messages and once the Vodafone endpoint has been hit all unread messages are then marked as read. So you only have one opportunity to further process incoming messages.

use NotificationChannels\Vodafone\VodafoneClient;

$vc = new VodafoneClient();
$vc->receive();

// A static method is also available
VodafoneClient::getUnread();

Since the Vodafone API only returns one unread message at a time a loop will need to be used to retrieve all the unread messages.

Vodafone will return an Error (code: 201) when there are no more unread messages, so breaking the loop on an Exception means there are no more messages to be retrieved.

use NotificationChannels\Vodafone\VodafoneClient;

$ex = false;
do {
    try {
        $message = VodafoneClient::getUnread();
        // Process Message
    } catch (\Exception $ex) {}
} while (!$ex);

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 32
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 4
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-03-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固