61 lines
1.7 KiB
PHP
61 lines
1.7 KiB
PHP
<?php
|
|
/**
|
|
* @copyright Copyright (c) 2023-2024 美天智能科技
|
|
* @author 李志强
|
|
* @link http://www.meteteme.com
|
|
*/
|
|
declare(strict_types=1);
|
|
namespace app\api\controller;
|
|
|
|
use app\api\BaseController;
|
|
use think\facade\Db;
|
|
use think\facade\View;
|
|
use app\api\controller\Schedule;
|
|
|
|
class Dingdingrobot extends BaseController
|
|
{
|
|
public function sendto()
|
|
{
|
|
// 获取前端传递的消息
|
|
$message = $this->request->param('message');
|
|
|
|
// 警保项目群机器人地址
|
|
$webhook1 = 'https://oapi.dingtalk.com/robot/send?access_token=46ad1d7d5aa6e365a50a1a08608f1d89f16031a658bf729c32f38d369bcfc520';
|
|
|
|
// 功能测试群机器人地址
|
|
$webhook2 = 'https://oapi.dingtalk.com/robot/send?access_token=4448cd3d356856f7f91739b832f3ef466c2c1d8df6ce43a80e02661b6cfc3ea3';
|
|
|
|
// 选择要使用的webhook地址
|
|
$webhook = $webhook2;
|
|
|
|
// 定义消息内容
|
|
$content = [
|
|
'msgtype' => 'text',
|
|
'text' => [
|
|
'content' => $message
|
|
]
|
|
];
|
|
|
|
// 将消息内容转换为json格式
|
|
$jsonContent = json_encode($content);
|
|
|
|
$options = [
|
|
'http' => [
|
|
'header' => 'Content-Type: application/json',
|
|
'method' => 'POST',
|
|
'content' => $jsonContent
|
|
]
|
|
];
|
|
|
|
$context = stream_context_create($options);
|
|
$result = file_get_contents($webhook, false, $context);
|
|
|
|
if ($result === false) {
|
|
// 发送失败
|
|
return '消息发送失败!';
|
|
} else {
|
|
// 发送成功
|
|
return '消息发送成功!';
|
|
}
|
|
}
|
|
} |