scottybo/textlocal

Laravel Text Local Package

1.3.0.0 2017-09-12 09:18 UTC

This package is not auto-updated.

Last update: 2024-09-15 01:59:00 UTC


README

简介

此包允许您在 Laravel 5.5+ 应用中使用 TextLocal API。核心类是 TextLocal 在以下链接提供的示例类的修改版:http://api.txtlocal.com/docs/phpclass,使用 Guzzle 连接到 API,并提供了一些在示例类中不可用的额外功能。

安装

步骤 1. 以两种方式之一安装包

方式一 通过 composer

composer require scottybo/textlocal

在您的 composer.json 文件中添加以下内容并运行 "composer update"

"require": {
    ...
    "scottybo/textlocal": "1.3.*"
}

步骤 2. 在您的 config/app.php 文件中添加 "TextLocal" 门面

'aliases' => [
    ...
    'TextLocal' => Illuminate\Support\Facades\TextLocal::class,
];

步骤 3. 您现在需要使用以下命令发布配置文件。将会创建一个文件:config/textlocal.php

php artisan vendor:publish --provider="App\TextLocalApi\TextLocalServiceProvider" --tag="config"

步骤 4. 将您的 TextLocal 凭证添加到 .env 文件中

注意 请指定密钥或哈希值中的一个 - 不要同时输入两者!

TEXTLOCAL_KEY=
TEXTLOCAL_USERNAME=
TEXTLOCAL_HASH=

示例用法

注意:查看 API 文档以了解您可以使用的命令

在这个例子中,我们将创建一个命令来获取接收到的消息并在控制台中显示它们,使用命令 php artisan textlocal:get-received-messages

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use TextLocal;

class GetReceivedMessages extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'textlocal:get-received-messages';
    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Find and store and messages received into Text Local';
    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }
    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        // Load our inboxes
        $inboxes = TextLocal::getInboxes();
        
        $start = 0;
        $limit = 1000;
        $min_time = strtotime('-1 day');
        $max_time = time(); // now
        
        // Loop through the inboxes
        foreach($inboxes->inboxes as $inbox) {
            
            // Load the messages for the current inbox (which we will call a folder)
            $folder = TextLocal::getMessages($inbox->id, $start, $limit, $min_time,$max_time);
            
            // If there are messages in the folder...
            if(sizeof($folder->messages) > 0) {
                foreach($folder->messages as $message) {
                    dump($message->message);
                }
            }
        }
    }
}

可用命令

  • getLastRequest ()
  • sendSms ($numbers, $message, $sender, $sched=null, $test=false, $receiptURL=null, $custom=null, $optouts=false, $simpleReplyService=false)
  • sendSmsGroup ($groupId, $message, $sender=null, $sched=null, $test=false, $receiptURL=null, $custom=null, $optouts=false, $simpleReplyService=false)
  • sendMms ($numbers, $fileSource, $message, $sched=null, $test=false, $optouts=false)
  • sendMmsGroup ($groupId, $fileSource, $message, $sched=null, $test=false, $optouts=false)
  • getUsers ()
  • transferCredits ($user, $credits)
  • getTemplates ()
  • checkKeyword ($keyword)
  • createGroup ($name)
  • getContacts ($groupId, $limit, $startPos=0)
  • createContacts ($numbers, $groupid= '5')
  • createContactsBulk ($contacts, $groupid= '5')
  • getGroups ()
  • getMessageStatus ($messageid)
  • getBatchStatus ($batchid)
  • getSenderNames ()
  • getInboxes ()
  • getBalance ()
  • getMessages ($inbox, $start, $limit, $min_time, $max_time)
  • cancelScheduledMessage ($id)
  • getScheduledMessages ()
  • deleteContact ($number, $groupid=5)
  • deleteGroup ($groupid)
  • getSingleMessageHistory ($start, $limit, $min_time, $max_time)
  • getAPIMessageHistory ($start, $limit, $min_time, $max_time)
  • getEmailToSMSHistory ($start, $limit, $min_time, $max_time)
  • getGroupMessageHistory ($start, $limit, $min_time, $max_time)
  • getSurveys ()
  • getSurveyDetails ()
  • getSurveyResults ($surveyid, $start, $end)
  • getOptouts ($time=null)

开发

想要贡献?太好了 - 开始吧!

待办事项

  • 测试未正确实现

许可协议:MIT