新增ai聊天更新

This commit is contained in:
meimei
2025-04-22 11:39:12 +08:00
parent 8f15282a0a
commit 3bc4b07eda
5 changed files with 130 additions and 6 deletions

View File

@@ -0,0 +1,49 @@
<?php
namespace app\api\logic;
use wanghua\general_utility_tools_php\http\Curl;
use wanghua\general_utility_tools_php\tool\Tools;
class UpdateMessageWechatLogic
{
/**
* 发送更新微信消息请求
*
* 该函数负责构造请求URL和数据并发送POST请求以更新微信消息
* 主要用于向特定的微信用户或群聊发送消息
*
* @param string $url 微信消息更新接口的URL
* @param mixed $content 要发送的消息内容
* @param string $wxid 微信用户的wxid或微信群的chatroom_id
*
* @return mixed 返回微信消息更新接口的响应结果
*
* @throws \Exception 如果URL解析失败或获取URL失败
*/
function getUpdateWechatMessage($url,$content,$wxid)
{
if (empty($url)){
throw new \Exception('获取url失败');
}
$base_url = parse_url($url);
if (!is_array($base_url) || !isset($base_url['scheme']) || !isset($base_url['host'])) {
throw new \Exception("URL解析失败: 输入的URL格式不正确 - {$url}");
}
$url = $base_url['scheme'].'://'.$base_url['host'].'/vip_groups/push_assistant_message';
$data = [
'content'=>$content,//AI微信号消息
'session_id'=> $wxid//AI微信号私聊服务的客户微信号wxid或者群聊服务的微信群chatroom_i
];
Tools::log_to_write_txt(['AI更新历史信息开始$url'=>$url,'$post_data'=>$data]);
$res = Curl::curl_post($url, $data);
Tools::log_to_write_txt(['AI更新历史信息结束$res'=>$res]);
if($res['code'] != 200){
return Tools::set_fail('设置AI更新历史信息失败',$res);
}
$res_data = json_decode($res['data'], true);
return $res_data;
}
}