定制 botika/socket 二次开发

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

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

botika/socket

最新稳定版本:v1.0.8

Composer 安装命令:

composer require botika/socket

包简介

Library for interacting with the Botika Socket REST API

README 文档

README

PHP library for interacting with the Botika Socket HTTP API.

Installation

You can get the Botika Socket PHP library via a composer package called socket. See https://packagist.org/packages/botika/socket

composer require botika/socket

Or add to composer.json:

"require": {
    "botika/socket": "^1.0"
}

then run composer update.

Supported platforms

  • PHP - supports PHP versions 7.0, and above.

Botika Socket constructor

Use the credentials from your Botika Socket application to create a new Botika\Socket instance.

$baseURL = 'https://socket.example.com';
$username = 'USERNAME';
$password = 'PASSWORD';
$auth = new \Botika\Socket\Auth($username, $password);

// Initialize socket
$socket = new \Botika\Socket\Socket($baseURL, $auth);

Logging configuration

The recommended approach of logging is to use a PSR-3 compliant logger implementing Psr\Log\LoggerInterface. The Socket object implements Psr\Log\LoggerAwareInterface, meaning you call setLogger(LoggerInterface $logger) to set the logger instance.

// where $logger implements `LoggerInterface`

$socket->setLogger($logger);

Publishing/Triggering events

To trigger an event on one or more channels use the trigger function.

A single channel

// Options get from https://docs.guzzlephp.org/en/stable/request-options.html
$options = [];
$socket->trigger('my-channel', 'my_event', 'hello world', $options);

Multiple channels

// Options get from https://docs.guzzlephp.org/en/stable/request-options.html
$options = [];
$socket->trigger([ 'channel-1', 'channel-2' ], 'my_event', 'hello world', $options);

Asynchronous interface

Both trigger have asynchronous counterparts in triggerAsync. These functions return Guzzle promises which can be chained with ->then:

// Options get from https://docs.guzzlephp.org/en/stable/request-options.html
$options = [];
$promise = $socket->triggerAsync(['channel-1', 'channel-2'], 'my_event', 'hello world', $options);
$promise->then(
    function (ResponseInterface $res) {
        echo $res->getStatusCode() . "\n";
    },
    function (RequestException $e) {
        echo $e->getMessage() . "\n";
        echo $e->getRequest()->getMethod();
    }
);
$promise->wait();

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-09-08