kagga/telco

封装了AfricasTalking api

1.0.2 2017-01-17 17:33 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:53:17 UTC


README

Telco是一个封装了AfricasTalking api的包。此包是为Laravel 5+开发的。

该包使得从应用程序向手机发送短信变得容易。

安装

与其他Laravel包一样,Telco通过composer安装。

在项目根目录的终端中运行

composer require kagga/telco

然后将服务提供者添加到config/app.php中的提供者部分

'providers' => [ 
            Kagga\Telco\TelcoServiceProvider::class 
    ],

然后也在config/app.php中的别名部分添加Facade别名。

'aliases' => [
        'Telco' => Kagga\Telco\facades\Telco::class,
    ],

配置

现在我们将配置AfricasTalking api。请访问您的账户或注册以获取您的api密钥和用户名,并保存它们。

通过在终端中运行以下命令将包配置文件发布到您的应用程序的config文件夹。

php artisan vendor:publish --tag=config

名为telco.php的配置文件将移动到config/telco.php

然后使用以下密钥将用户名和api密钥添加到.env文件中

SMS_USERNAME=yourUsername
SMS_API_KEY=yourapi-key

配置完成。

你快完成了,只需注意一件事。你可以通过运行php artisan serve来提供你的应用程序并检查https:///telco/send来测试它是否正常工作。该url处的视图仅包含在包中,用于测试目的。

发送消息后,将显示成功消息或错误消息(如果出现错误)。

用法

目前,该包有两种方法,一种用于发送短信的send,另一种是暴露AfricasTalking网关的api

使用api方法,你可以访问AfricasTalkingGateway中的所有公开方法。

示例代码

Illuminate\Support\Facades\Route::post('/telco/send', function (\Kagga\Telco\contracts\TelcoInterface $telco) {

  $phonenumber = request('tel'); //Used the request laravel helper to get the phone number from a phone

  $message = request('message'); //Getting the message from the form
  
  $results = $telco->send($phonenumber, $message);
  
  if ($results != null) {

      return "Message has been sent successful to " . $phonenumber;
  }
});

您还可以使用随包提供的Telco外观来发送消息。

Telco::send($phonenumber, $message);

不要忘记添加外观导入语句use Kagga\Telco\facades\Telco;

就是这样.

感谢您使用此包。

请告诉我您用此包开发了什么。通过发送电子邮件至Johnkagga@gmail.com@johnkagga