Commit ff8b4076 authored by 王源's avatar 王源
Browse files

删除旧message中心文件

parent 994bd8cc
Loading
Loading
Loading
Loading

publish/message.php

deleted100644 → 0
+0 −12
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

return [
    'center' => [
        'ip' => env('MESSAGE_CENTER_IP', '127.0.0.1'),
        'domain' => env('MESSAGE_CENTER_DOMAIN', 'http://localhost'),
        'proxy' => env('MESSAGE_CENTER_PROXY'),
        'proxy_port' => env('MESSAGE_CENTER_PROXY_PORT', 80),
    ]
];
+0 −8
Original line number Diff line number Diff line
@@ -39,14 +39,6 @@ class ConfigProvider
                    ],
                ],
            ],
            'publish' => [
                [
                    'id' => 'message',
                    'description' => 'message',
                    'source' => __DIR__ . '/../publish/message.php',
                    'destination' => BASE_PATH . '/config/autoload/message.php',
                ],
            ],
        ];
    }
}

src/Message/MessageCenter.php

deleted100644 → 0
+0 −83
Original line number Diff line number Diff line
<?php
/**
 * Created by PhpStorm.
 * User: Zero
 * Date: 2020/4/15
 * Time: 9:19
 */

namespace Meibuyu\Micro\Message;

use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use Hyperf\Contract\ConfigInterface;
use Hyperf\Guzzle\CoroutineHandler;
use Hyperf\Guzzle\HandlerStackFactory;

class MessageCenter
{
    /**
     * @var Client
     */
    protected $client;

    /**
     * @var ConfigInterface
     */
    private $config;

    /**
     * @var HandlerStackFactory
     */
    protected $stackFactory;

    public function __construct(ConfigInterface $config, HandlerStackFactory $stackFactory)
    {
        $this->config = $config;
        $this->stackFactory = $stackFactory;
        $this->initClient();
    }

    public function initClient()
    {
        $options = [
            'base_uri' => $this->config->get('message.center.domain') . '/api/',
            'handler' => HandlerStack::create(new CoroutineHandler()),
            'timeout' => 60,
        ];
        $proxy = $this->config->get('message.center.proxy');
        if ($proxy) {
            $options = array_merge($options, [
                'proxy' => $proxy,
                'swoole' => [
                    'http_proxy_port' => $this->config->get('message.center.proxy_port'),
                ]
            ]);
        }
        $this->client = make(Client::class, ['config' => $options]);
    }

    public function request($type, $uri, $data = [])
    {
        return $this->client->request($type, $uri, [
            'body' => json_encode($data),
            'headers' => ['content-type' => 'application/json']
        ]);
    }

    public function syncDingUser()
    {
        $response = $this->client->request('GET', 'synchronizationDingUser');
        return json_decode($response->getBody()->getContents(), true);
    }

    public function sendDing($userId, $message)
    {
        $response = $this->client->request('POST', 'sendDing', [
            'body' => json_encode(['userId' => $userId, 'message' => $message]),
            'headers' => ['content-type' => 'application/json']
        ]);
        return json_decode($response->getBody()->getContents(), true);
    }

}
 No newline at end of file