定制 jlorente/laravel-connectus 二次开发

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

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

jlorente/laravel-connectus

最新稳定版本:1.0.2

Composer 安装命令:

composer require jlorente/laravel-connectus

包简介

Laravel integration for the Jlorente Connectus php sdk.

README 文档

README

Laravel integration for the Connectus SDK including a notification channel.

Installation

The preferred way to install this extension is through composer.

With Composer installed, you can then install the extension using the following commands:

$ php composer.phar require jlorente/laravel-connectus

or add

...
    "require": {
        "jlorente/laravel-connectus": "*"
    }

to the require section of your composer.json file.

Configuration

  1. Register the ServiceProvider in your config/app.php service provider list.

config/app.php

return [
    //other stuff
    'providers' => [
        //other stuff
        \Jlorente\Laravel\Connectus\ConnectusServiceProvider::class,
    ];
];
  1. Add the following facade to the $aliases section.

config/app.php

return [
    //other stuff
    'aliases' => [
        //other stuff
        'Connectus' => \Jlorente\Laravel\Connectus\Facades\Connectus::class,
    ];
];
  1. Publish the package configuration file.
$ php artisan vendor:publish --provider='Jlorente\Laravel\Connectus\ConnectusServiceProvider'
  1. Set the api_key and api_secret in the config/connectus.php file or use the predefined env variables.

config/connectus.php

return [
    'api_key' => 'YOUR_API_KEY',
    'account_id' => 'YOUR_ACCOUNT_ID',
    //other configuration
];

or .env

//other configurations
CONNECTUS_API_KEY=<YOUR_API_KEY>
CONNECTUS_ACCOUNT_ID=<YOUR_ACCOUNT_ID>

Usage

You can use the facade alias Connectus to execute api calls. The authentication params will be automaticaly injected.

Connectus::api()->checkSmsBalance();

Notification Channels

A notification channel is included in this package and allow you to integrate the Connectus send SMS service.

You can find more info about Laravel notifications in this page.

ConnectusSmsChannel

If you want to send an SMS through Connectus, you should define a toConnectusSms method on the notification class. This method will receive a $notifiable entity and should return a string with the message to be sent on the SMS:

/**
 * Get the SMS message.
 *
 * @param  mixed  $notifiable
 * @return string
 */
public function toConnectusSms($notifiable)
{
    return 'Hello, this is an SMS sent through Connectus API';
}

Once done, you must add the notification channel in the array of the via() method of the notification:

/**
 * Get the notification channels.
 *
 * @param  mixed  $notifiable
 * @return array|string
 */
public function via($notifiable)
{
    return [ConnectusSmsChannel::class];
}

Routing the Notifications

When sending notifications via Connectus channel, the notification system will automatically look for a phone_number attribute on the notifiable entity. If you would like to customize the number you should define a routeNotificationForConnectusSms method on the entity:

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;

    /**
     * Route notifications for the Connectus SMS channel.
     *
     * @param  \Illuminate\Notifications\Notification  $notification
     * @return string
     */
    public function routeNotificationForConnectusSms($notification)
    {
        return $this->phone;
    }
}

License

Copyright © 2021 José Lorente Martín jose.lorente.martin@gmail.com.

Licensed under the BSD 3-Clause License. See LICENSE.txt for details.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2021-02-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固