abdulmatinsanni/api-x 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

abdulmatinsanni/api-x

Composer 安装命令:

composer require abdulmatinsanni/api-x

包简介

An unofficial laravel package for SmartSMSSolutions' APIx. The Package that helps deliver SMS to phone numbers on Do Not Disturb (DND).

README 文档

README

Latest Version on Packagist Software License Total Downloads

An unofficial laravel package for SmartSMSSolutions' API-x. The Package that helps deliver SMS to phone numbers on Do Not Disturb (DND).

Structure

Below is the file structure of this package.

\---src
    |   APIx.php
    |   APIxMessage.php
    |   APIxServiceProvider.php
    |
    +---Channels
    |       SmartSMSChannel.php
    |
    +---Commands
    |   \---Log
    |           ClearCommand.php
    |           DisplayCommand.php
    |
    +---config
    |       api-x.php
    |
    +---Controllers
    |       LogController.php
    |
    +---Exceptions
    |       CouldNotSendNotification.php
    |       InvalidConfiguration.php
    |
    +---Facades
    |       APIxFacade.php
    |
    \---resources
        \---views
                log.blade.php

Install

You can install the package via composer:

$ composer require abdulmatinsanni/api-x

Add the service provider (only required on Laravel 5.4 or lower):

// config/app.php

'providers' => [
    ...
    AbdulmatinSanni\APIx\APIxServiceProvider::class,
],

'aliases' => [
    'APIx' => AbdulmatinSanni\APIx\Facades\APIxFacade::class,
],

Setting up your API-x account

Add your API-x API Token (string), Log Message (boolean), Mock SMS (boolean) and Sender Name (optional|string) to your .env (environment) file:

SMARTSMSSOLUTIONS_API_TOKEN=apixtokenhere
SMARTSMSSOLUTIONS_LOG_MESSAGES=true
SMARTSMSSOLUTIONS_FAKE_SMS=true
SMARTSMSSOLUTIONS_SENDER_NAME=sendernamehere

Usage

In Controllers:

Below is an example of API-x usage in controllers.

...

use APIx;

class SMSController extends Controller
{
    public function send(Request $request)
    {
        $response = APIx::to($request->recipient)
            ->from($request->name)
            ->message($request->message)
            ->send();
        
        return $response;
    }
}

For Notifications:

Setting up in model:

...

class User extends Model
{
    use Notifiable;

    public function routeNotificationForSmartSMS($notification)
    {
        return $this->phone_column;
    }
}

Setting up in notifications

...

use AbdulmatinSanni\APIx\APIxMessage;
use AbdulmatinSanni\APIx\Channels\SmartSMSChannel;

class DemoNotification extends Notification
{
    use Queueable;
    
    ...
    
    public function via($notifiable)
    {
        return [SmartSMSChannel::class];
    }

    ...
    
    public function toSmartSMS($notifiable)
    {
        return (new APIxMessage())
                    ->from($this->from)
                    ->message($this->message);
    }
}

Setting up in controllers

...

public class NotificationsController extends Controller
{
    public function notify()
    {
        $user = User::firstOrFail();
        $user->notify(new DemoNotification("SarahFound", "Hi, you are invited to our seminar!!!!!"));
    }
}

Available message methods

  • to([]) : Accepts an array or string of recipients' phone number(s).
  • from('') : Accepts a phone to use as the sms sender.
  • message('') : Accepts a string value for the sms body.
  • send() : Does the sending of the sms. Can also accept a string which represent sms body if message('') was skipped.

Command line

Showing all entries of log:

$ php artisan api-x:log

Showing the last logged sms:

$ php artisan api-x:log --latest

Limiting the entries of log to be displayed:

$ php artisan api-x:log --limit={no_of_messages}

Clearing all entries of log:

$ php artisan api-x:log clear

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

$ composer test (NOT YET)

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

Security

If you discover any security related issues, please email me@abdulmatinsanni.com instead of using the issue tracker.

Credits

License

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

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-04-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固