REAPI/app/robot/controller/WxWorkBot.php
mzeros 21e4c1e37a feat(queue): 添加渠道余额监控预警功能
- 新增 ChannelBalanceMonitor 类实现渠道余额监控
- 在 MerchantBalanceMonitor 中增加余额恢复提醒功能
- 添加 WxWorkBot 类用于发送微信工作台消息- 在 Test 控制器中整合渠道余额监控逻辑
- 更新 sys.php 添加新的渠道余额监控命令
2025-01-06 13:08:15 +08:00

128 lines
2.7 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\robot\controller;
use app\gateway\service\CurlService;
use think\admin\Controller;
#微信机器人 #
class WxWorkBot extends Controller
{
protected array $status_map=array(
-1=>'暂无订单',
-2=>'暂无卡密',
1=>'成功'
);
protected string $host = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send';
public function initialize(): void
{
#47609e509f946ecbfdba27f16db341c4
parent::initialize();
#获取wechat信息
$this->key='47609e509f946ecbfdba27f16db341c4';
}
#发送文本
public function send_text($content,$key = false,$receiver = false)
{
$text = [
'content' =>$content,
];
if($receiver){
$text['mentioned_mobile_list'] = $receiver;
}
$request = [
'msgtype'=>'text',
'text'=>$text
];
$url = $this->host.'?key='.$this->key;
if($key){
$url = $this->host.'?key='.$key;
}
return $this->curl('post', $url,$request,true);
}
#发送markdown
public function send_markdown($content,$key = false)
{
$markdown = [
'content' =>$content,
];
$request = [
'msgtype'=>'markdown',
'markdown'=>$markdown
];
$url = $this->host.'?key='.$this->key;
if($key){
$url = $this->host.'?key='.$key;
}
// var_dump($request);die;
return $this->send_post($url,$request,'POST');
}
public function send_post($notify_url, $post_data, $type): mixed
{
$postdate = json_encode($post_data);
// $postdate = http_build_query($post_data);
$options = array(
'http' => array(
'method' => $type,
'header' => 'Content-type:application/json',
'content' => $postdate,
'timeout' => 15 * 60 // 超时时间(单位:s
)
);
$context = stream_context_create($options);
return file_get_contents($notify_url, false, $context);
}
protected function curl($method, $url, $param = array(), $json = false, $header = false):mixed
{
if ($param) {
$log['type'] = 'request';
$log['url'] = $url;
$log['param'] = $param;
$this->log($log);
}
$curl = CurlService::getInstance($url, $param, $method, $json, $header);
$curl->setTimeOut(3600);
return $curl->result();
}
protected static function log($data, $type = 'request'):void
{
\dever\Log::write('WxWork', $type, $data);
// \dever\Log::write('jingdong', $type, $data);
}
}