新增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

@@ -26,10 +26,19 @@ class PyappLofic
* authorwh
* @throws \Exception
*/
function setFollowupModel($chatroom_id,$return_record){
function setFollowupModel($url,$chatroom_id,$return_record){
$base_url = SundryConfig::val('py_app_base_url');
$url = $base_url.'/vip_groups/follow-up';
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/follow-up';
// $base_url = SundryConfig::val('py_app_base_url');
// $url = $base_url.'/vip_groups/follow-up';
$post_data = [
'chatroom_id' => $chatroom_id,
'is_follow_up' => true,

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;
}
}

View File

@@ -12,6 +12,7 @@ namespace app\index\controller;
use app\api\logic\MessageWechatLogic;
use app\api\logic\PyappLofic;
use app\api\logic\TokenWechatLogic;
use app\api\logic\UpdateMessageWechatLogic;
use think\Controller;
use think\Db;
use wanghua\general_utility_tools_php\Mmodel;
@@ -156,7 +157,11 @@ class Tasktimer extends Controller
//设置AI客服回访模式
$py_logic = new PyappLofic();
$py_logic->setFollowupModel($cust['rel_group'],$return_record);
$py_logic->setFollowupModel($base_url,$cust['rel_group'],$return_record);
//设置AI客服更新信息
$updateMessage_logic = new UpdateMessageWechatLogic();
$updateMessage_logic->getUpdateWechatMessage($base_url,$return_record['visit_msg'],$cust['rel_group']);
return Tools::set_ok('发送成功');
}
@@ -222,6 +227,7 @@ class Tasktimer extends Controller
//@的好友,多个英文逗号分隔。群主或管理员@全部的人,则填写'notify@all'
'ats'=>$customer_record['rel_wx'],
];
$wxid = $customer_record['rel_group'];
$type = 1;
}else{
if(!empty($customer_record['rel_wx'])){
@@ -230,6 +236,7 @@ class Tasktimer extends Controller
'toWxid'=>$customer_record['rel_wx'],//是群则发送群消息,否则发个人私人消息
'content'=>$birthday_record['content'],
];
$wxid = $customer_record['rel_wx'];
$type = 2;
}else{
return Tools::set_fail('客户未绑定微信和群');
@@ -247,6 +254,10 @@ class Tasktimer extends Controller
}
Tools::log_to_write_txt([$msg.'微信群客户,结束:$res'=>$res]);
//设置AI客服更新信息
$updateMessage_logic = new UpdateMessageWechatLogic();
$updateMessage_logic->getUpdateWechatMessage($base_url,$birthday_record['content'],$wxid);
return Tools::set_ok('发送成功');
}
}

View File

@@ -33,12 +33,18 @@ class TokenWechatLogic extends BaseWechatLogic
// $url = 'https://wechat-api-test.excn.vip/vip_groups/auth_info';
$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/auth_info';
$res = \wanghua\general_utility_tools_php\http\Curl::curl_post($url, []);
if(empty($res['data'])){
throw new \Exception('获取token失败');
if (empty($res['data'])) {
throw new \Exception("获取数据失败: 接口返回为空 - URL: {$url}");
}
$res_data = json_decode($res['data'], true);
if (!is_array($res_data) || !isset($res_data['gewe-token']) || !isset($res_data['appId'])) {
throw new \Exception("JSON解析失败或缺少必要字段: 返回数据 - " . print_r($res_data, true));
}
return [
'token' => $res_data['gewe-token'],
'appId' => $res_data['appId'],

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失败
*/
public 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;
}
}