新增ai聊天更新
This commit is contained in:
@@ -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'],
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user