DingService.php 1.3 KB
<?php
/**
 * @author:wlj
 * @date: 2022/8/10 15:02
 */

namespace App\Services;

use App\Enums\Common\RedisKey;
use App\Services\BaseService;
use App\Traits\RedisTrait;
use App\Utils\HttpUtils;

class DingService
{
    use RedisTrait;

    const LINK = 'https://oapi.dingtalk.com/robot/send?access_token=2cdba958f11f24f961f13aba2d1acbcd60ed64c998a184492cc63814696e34e1';
    const INFO = 'INFO';
    const ERROR = 'ERROR';
    const WARNNING = 'WARNNING';
    const OTHER = 'OTHER';


    /**
     * @remark :钉钉发送错误信息
     * @name   :handle
     * @author :lyh
     * @method :post
     * @time   :2025/3/19 18:03
     */
    public function handle(array $body)
    {
        $msgKey = mb_substr($body['msg'], 50);
        if (!$this->getData(RedisKey::DING_MSG . $msgKey)) {
            $arr = [
                'msgtype' => 'text',
                'text' => [
                    'content' => $body['keyword'] . PHP_EOL . $body['msg']
                ],
                'at' => [
                    'atMobiles' => [],
                    'atUserIds' => [],
                    'isAtAll' => $body['isAtAll'],
                ]
            ];
            $re = json_decode(HttpUtils::post(self::LINK, $arr), true);
            $this->setData(RedisKey::DING_MSG . $msgKey, true, 60);
            return $re['errcode'] ?? 0;
        }
        return 0;

    }

}