You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.6 KiB
48 lines
1.6 KiB
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Jobs\Message;
|
|
|
|
use App\Dictionary\SendMessage\Type as MessageType;
|
|
use EasyWeChat\Kernel\HttpClient\Response;
|
|
use EasyWeChat\OfficialAccount\Application as OfficialApplication;
|
|
use EasyWeChat\MiniApp\Application as MiniApplication;
|
|
use EasyWeChat\Work\Application as WorkApplication;
|
|
use Illuminate\Support\Facades\Log;
|
|
use ReflectionException;
|
|
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
|
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
|
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
|
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
|
|
|
abstract class Message
|
|
{
|
|
/**
|
|
* @return OfficialApplication|MiniApplication|WorkApplication
|
|
*/
|
|
abstract public function getApp(): OfficialApplication|MiniApplication|WorkApplication;
|
|
|
|
/**
|
|
* Send Message.
|
|
*
|
|
* @param MessageType $type 消息类型
|
|
* @param array $message 消息数据 json 包
|
|
*
|
|
* @return Response
|
|
*
|
|
* @throws TransportExceptionInterface
|
|
* @throws ClientExceptionInterface
|
|
* @throws RedirectionExceptionInterface
|
|
* @throws ServerExceptionInterface
|
|
*/
|
|
public function send(MessageType $type, array $message): Response
|
|
{
|
|
/** @var Response $response */
|
|
$response = $this->getApp()->getClient()->postJson($type->api()->value, $message);
|
|
|
|
Log::channel('SendWeChatMessage')->info('Push WeChat Message', [$type->label(), $message, $response->getContent(false)]);
|
|
|
|
return $response;
|
|
}
|
|
}
|
|
|