初始化小程序端

This commit is contained in:
2025-12-11 11:06:11 +08:00
parent a2c0d17210
commit f9988ae675
531 changed files with 235994 additions and 114 deletions

35
WxCheckApi/.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,35 @@
{
"version": "0.2.0",
"configurations": [
{
// 使用 IntelliSense 找出 C# 调试存在哪些属性
// 将悬停用于现有属性的说明
// 有关详细信息,请访问 https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md。
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// 如果已更改目标框架,请确保更新程序路径。
"program": "${workspaceFolder}/bin/Debug/net8.0/WxCheckApi.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
// 启用在启动 ASP.NET Core 时启动 Web 浏览器。有关详细信息: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}

41
WxCheckApi/.vscode/tasks.json vendored Normal file
View File

@@ -0,0 +1,41 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/WxCheckApi.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/WxCheckApi.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/WxCheckApi.csproj"
],
"problemMatcher": "$msCompile"
}
]
}

View File

@@ -173,7 +173,56 @@
## 2. Check控制器接口
### 2.1 添加会话记录接口
### 2.1 检查地址接口
#### 接口描述
根据会话记录的GUID查询经纬度信息并转换为详细地址更新到数据库中。
#### 接口路径
`/api/Check/CheckAddress`
#### 请求参数
| 参数名 | 类型 | 必填 | 描述 |
|--------|------|------|------|
| Guid | string | 是 | 会话唯一标识 |
#### 请求示例
```json
{
"Guid": "会话唯一标识"
}
```
#### 响应示例
**成功响应:**
```json
{
"success": true,
"message": "地址更新成功",
"address": "北京市海淀区中关村南大街5号"
}
```
**失败响应:**
```json
{
"success": false,
"message": "记录不存在或已被删除"
}
```
```json
{
"success": false,
"message": "更新失败",
"error": "数据库操作错误"
}
```
### 2.2 添加会话记录接口
#### 接口描述
添加新的会话记录到系统中。
@@ -188,8 +237,9 @@
| UserKey | string | 是 | 用户唯一标识键 |
| ConversationContent | string | 是 | 会话内容 |
| SendMethod | string | 是 | 发送方式 |
| UserLocation | string | 否 | 用户定位信息 |
| UserLocation | string | 否 | 用户定位信息(经纬度格式:"纬度,经度" |
| MessageType | int | 否 | 1:公有消息2:私有消息 |
| Guid | string | 否 | 会话唯一标识(不提供则系统自动生成) |
#### 请求示例
@@ -198,8 +248,8 @@
"UserKey": "user_123456",
"ConversationContent": "这是一条测试消息",
"SendMethod": "文本",
"UserLocation": "北京市海淀区",
"MessageType": 0
"UserLocation": "39.9087,116.3975",
"MessageType": 1
}
```
@@ -209,7 +259,9 @@
```json
{
"success": true,
"message": "收到!"
"message": "收到!",
"conversationGuid": "会话唯一标识",
"receivedTime": "2023-10-31 10:05:00"
}
```
@@ -222,7 +274,7 @@
}
```
### 2.2 查询会话记录接口
### 2.3 查询会话记录接口
#### 接口描述
根据用户唯一标识键查询该用户的所有会话记录。
@@ -255,27 +307,33 @@
"data": [
{
"Id": 1,
"Guid": "会话唯一标识",
"UserKey": "user_123456",
"ConversationContent": "这是一条测试消息",
"SendMethod": "文本",
"UserLocation": "北京市海淀区",
"Latitude": "39.9087",
"Longitude": "116.3975",
"RecordTime": "2023-10-31T10:05:00",
"RecordTimeUTCStamp": 1698732300000,
"IsDeleted": false,
"CreateTime": "2023-10-31T10:05:00",
"MessageType": 0
"MessageType": 1
},
{
"Id": 2,
"Guid": "会话唯一标识",
"UserKey": "user_123456",
"ConversationContent": "这是第二条测试消息",
"SendMethod": "图片",
"UserLocation": "北京市朝阳区",
"Latitude": "39.9180",
"Longitude": "116.4272",
"RecordTime": "2023-10-31T10:06:00",
"RecordTimeUTCStamp": 1698732360000,
"IsDeleted": false,
"CreateTime": "2023-10-31T10:06:00",
"MessageType": 1
"MessageType": 2
}
]
}
@@ -290,7 +348,7 @@
}
```
### 2.3 分页查询会话记录接口
### 2.4 分页查询会话记录接口
#### 接口描述
分页查询用户的会话记录每页默认10条按时间戳从**最新到最旧**排序,支持根据消息类型进行过滤。
@@ -328,27 +386,33 @@
"conversations": [
{
"Id": 1,
"Guid": "会话唯一标识",
"UserKey": "user_123456",
"ConversationContent": "这是一条测试消息",
"SendMethod": "文本",
"UserLocation": "北京市海淀区",
"Latitude": "39.9087",
"Longitude": "116.3975",
"RecordTime": "2023-10-31T10:00:00",
"RecordTimeUTCStamp": 1698727200000,
"IsDeleted": false,
"CreateTime": "2023-10-31T10:00:00",
"MessageType": 0
"MessageType": 1
},
{
"Id": 2,
"Guid": "会话唯一标识",
"UserKey": "user_123456",
"ConversationContent": "这是一条私有消息",
"SendMethod": "文本",
"UserLocation": "北京市朝阳区",
"Latitude": "39.9180",
"Longitude": "116.4272",
"RecordTime": "2023-10-31T09:55:00",
"RecordTimeUTCStamp": 1698724500000,
"IsDeleted": false,
"CreateTime": "2023-10-31T09:55:00",
"MessageType": 1
"MessageType": 2
}
],
"totalCount": 25,
@@ -368,10 +432,73 @@
}
```
### 2.3 更新会话记录接口
### 2.5 根据GUID查询会话记录接口
#### 接口描述
更新指定ID的会话记录需要验证UserKey的权限
根据会话唯一标识GUID查询会话记录详情不考虑IsDeleted状态
#### 接口路径
`/api/Check/GetConversationByGuid`
#### 请求参数
| 参数名 | 类型 | 必填 | 描述 |
|--------|------|------|------|
| Guid | string | 是 | 会话唯一标识 |
#### 请求示例
```json
{
"Guid": "会话唯一标识"
}
```
#### 响应示例
**成功响应:**
```json
{
"success": true,
"message": "查询成功",
"data": {
"Id": 1,
"Guid": "会话唯一标识",
"UserKey": "user_123456",
"ConversationContent": "这是一条测试消息",
"SendMethod": "文本",
"UserLocation": "北京市海淀区",
"Latitude": "39.9087",
"Longitude": "116.3975",
"RecordTime": "2023-10-31T10:05:00",
"RecordTimeUTCStamp": 1698732300000,
"IsDeleted": false,
"CreateTime": "2023-10-31T10:05:00",
"MessageType": 1
}
}
```
**失败响应:**
```json
{
"success": false,
"message": "未找到该记录"
}
```
```json
{
"success": false,
"message": "查询失败",
"error": "数据库操作错误"
}
```
### 2.6 更新会话记录接口
#### 接口描述
更新指定GUID的会话记录需要验证UserKey的权限。每次更新时RecordTime会自动更新为当前时间。
#### 接口路径
`/api/Check/UpdateConversation`
@@ -380,7 +507,7 @@
| 参数名 | 类型 | 必填 | 描述 |
|--------|------|------|------|
| Id | long | 是 | 会话记录ID |
| Guid | string | 是 | 会话唯一标识 |
| UserKey | string | 是 | 用户唯一标识键(用于权限验证) |
| ConversationContent | string | 是 | 新的会话内容 |
| SendMethod | string | 是 | 新的发送方式 |
@@ -391,12 +518,12 @@
```json
{
"Id": 1,
"Guid": "会话唯一标识",
"UserKey": "user_123456",
"ConversationContent": "更新后的会话内容",
"SendMethod": "文本",
"UserLocation": "北京市西城区",
"MessageType": 0
"MessageType": 1
}
```
@@ -406,7 +533,8 @@
```json
{
"success": true,
"message": "会话更新成功"
"message": "更新成功",
"receivedTime": "2023-10-31 10:10:00"
}
```
@@ -414,7 +542,7 @@
```json
{
"success": false,
"message": "会话记录不存在或无权限修改"
"message": "记录不存在或无权限修改"
}
```
@@ -426,7 +554,7 @@
}
```
### 2.4 删除会话记录接口
### 2.7 删除会话记录接口
#### 接口描述
软删除会话记录将IsDeleted标记为1需要验证UserKey的权限。
@@ -438,14 +566,14 @@
| 参数名 | 类型 | 必填 | 描述 |
|--------|------|------|------|
| Id | long | 是 | 会话记录ID |
| Guid | string | 是 | 会话唯一标识 |
| UserKey | string | 是 | 用户唯一标识键(用于权限验证) |
#### 请求示例
```json
{
"Id": 1,
"Guid": "会话唯一标识",
"UserKey": "user_123456"
}
```
@@ -456,7 +584,7 @@
```json
{
"success": true,
"message": "会话删除成功"
"message": "删除成功"
}
```
@@ -464,7 +592,7 @@
```json
{
"success": false,
"message": "会话记录不存在或已被删除"
"message": "记录不存在或已被删除"
}
```
@@ -476,6 +604,73 @@
}
```
### 2.8 从Redis Stream读取消息接口
#### 接口描述
从Redis Stream读取新的会话消息。
#### 接口路径
`/api/Check/ReadMessageFromRedis`
#### 请求参数
| 参数名 | 类型 | 必填 | 描述 |
|--------|------|------|------|
| GroupName | string | 否 | 消费组名称默认xcx_group |
| ConsumerName | string | 否 | 消费者名称默认consumer_时间戳 |
| Count | int | 否 | 读取消息数量默认1 |
#### 请求示例
```json
{
"GroupName": "xcx_group",
"ConsumerName": "consumer_1",
"Count": 5
}
```
#### 响应示例
**成功响应:**
```json
{
"success": true,
"message": "成功读取消息",
"data": [
{
"MessageId": "1635739200000-0",
"Id": "1",
"Guid": "会话唯一标识",
"UserKey": "user_123456",
"ConversationContent": "测试消息",
"SendMethod": "文本",
"UserLocation": "北京市海淀区",
"Latitude": "39.9087",
"Longitude": "116.3975",
"RecordTime": "2023-10-31T10:00:00",
"RecordTimeUTCStamp": "1698727200000",
"IsDeleted": "false",
"CreateTime": "2023-10-31T10:00:00",
"MessageType": "1",
"UserName": "张三",
"WeChatName": "张三的微信",
"PhoneNumber": "13800138000",
"AvatarUrl": "https://example.com/avatar.jpg"
}
]
}
```
**失败响应:**
```json
{
"success": false,
"message": "读取消息失败",
"error": "Redis操作错误"
}
```
## 3. 接口调用说明
### 3.1 HTTP客户端调用示例JavaScript
@@ -568,4 +763,4 @@ async function addConversation() {
- **最后更新时间**2023-11-01
- **维护人员**:系统管理员
- **版本号**v1.1.0
- **版本号**v1.2.0

View File

@@ -208,9 +208,9 @@ namespace WxCheckApi.Controllers
string latitude = "";
string longitude = "";
using (MySqlCommand cmd = new MySqlCommand("SELECT Latitude, Longitude FROM xcx_conversation WHERE Id = @Id AND IsDeleted = 0", _connection))
using (MySqlCommand cmd = new MySqlCommand("SELECT Latitude, Longitude FROM xcx_conversation WHERE Guid = @Guid AND IsDeleted = 0", _connection))
{
cmd.Parameters.AddWithValue("@Id", request.Id);
cmd.Parameters.AddWithValue("@Guid", request.Guid);
using (var reader = await cmd.ExecuteReaderAsync())
{
@@ -230,9 +230,9 @@ namespace WxCheckApi.Controllers
var address = await ConvertCoordinatesToAddress(longitude, latitude);
// 更新数据库中的UserLocation字段
using (MySqlCommand cmd = new MySqlCommand("UPDATE xcx_conversation SET UserLocation = @UserLocation WHERE Id = @Id AND IsDeleted = 0", _connection))
using (MySqlCommand cmd = new MySqlCommand("UPDATE xcx_conversation SET UserLocation = @UserLocation WHERE Guid = @Guid AND IsDeleted = 0", _connection))
{
cmd.Parameters.AddWithValue("@Id", request.Id);
cmd.Parameters.AddWithValue("@Guid", request.Guid);
cmd.Parameters.AddWithValue("@UserLocation", address);
int rowsAffected = await cmd.ExecuteNonQueryAsync();
@@ -261,6 +261,7 @@ namespace WxCheckApi.Controllers
[HttpPost]
public async Task<IActionResult> AddConversation([FromBody] ConversationRequest request)
{
DateTime nowtime = DateTime.Now;
try
{
if (_connection.State != ConnectionState.Open)
@@ -288,8 +289,10 @@ namespace WxCheckApi.Controllers
}
}
// 生成GUID
string conversationGuid = string.IsNullOrEmpty(request.Guid) ? Guid.NewGuid().ToString("N") : request.Guid;
long conversationId = 0;
using (MySqlCommand cmd = new MySqlCommand("INSERT INTO xcx_conversation (UserKey, ConversationContent, SendMethod, UserLocation, Latitude, Longitude, RecordTime, RecordTimeUTCStamp, IsDeleted, CreateTime, MessageType) VALUES (@UserKey, @ConversationContent, @SendMethod, @UserLocation, @Latitude, @Longitude, @RecordTime, @RecordTimeUTCStamp, @IsDeleted, NOW(), @MessageType); SELECT LAST_INSERT_ID();", _connection))
using (MySqlCommand cmd = new MySqlCommand("INSERT INTO xcx_conversation (UserKey, ConversationContent, SendMethod, UserLocation, Latitude, Longitude, RecordTime, RecordTimeUTCStamp, IsDeleted, CreateTime, MessageType, Guid, SpeakingTime) VALUES (@UserKey, @ConversationContent, @SendMethod, @UserLocation, @Latitude, @Longitude, @RecordTime, @RecordTimeUTCStamp, @IsDeleted, @CreateTime, @MessageType, @Guid, @SpeakingTime); SELECT LAST_INSERT_ID();", _connection))
{
cmd.Parameters.AddWithValue("@UserKey", request.UserKey);
cmd.Parameters.AddWithValue("@MessageType", request.MessageType);
@@ -298,9 +301,12 @@ namespace WxCheckApi.Controllers
cmd.Parameters.AddWithValue("@UserLocation", address);
cmd.Parameters.AddWithValue("@Latitude", latitude);
cmd.Parameters.AddWithValue("@Longitude", longitude);
cmd.Parameters.AddWithValue("@RecordTime", DateTime.Now);
cmd.Parameters.AddWithValue("@RecordTime", nowtime);
cmd.Parameters.AddWithValue("@CreateTime", nowtime);
cmd.Parameters.AddWithValue("@RecordTimeUTCStamp", DateTimeOffset.UtcNow.ToUnixTimeMilliseconds());
cmd.Parameters.AddWithValue("@IsDeleted", 0);
cmd.Parameters.AddWithValue("@Guid", conversationGuid);
cmd.Parameters.AddWithValue("@SpeakingTime", request.SpeakingTime);
object result = await cmd.ExecuteScalarAsync();
conversationId = Convert.ToInt64(result);
@@ -309,18 +315,17 @@ namespace WxCheckApi.Controllers
// 查询刚插入的记录,并左连接用户表
if (conversationId > 0)
{
string query = @"SELECT convs.Id, convs.UserKey, convs.ConversationContent, convs.SendMethod,
string query = @"SELECT convs.Id, convs.Guid, convs.UserKey, convs.ConversationContent, convs.SendMethod,
convs.UserLocation, convs.Latitude, convs.Longitude, convs.RecordTime,
convs.RecordTimeUTCStamp, convs.IsDeleted, convs.CreateTime, convs.MessageType,
convs.RecordTimeUTCStamp, convs.IsDeleted, convs.CreateTime, convs.MessageType, convs.SpeakingTime,
users.UserName, users.WeChatName, users.PhoneNumber, users.AvatarUrl
FROM xcx_conversation AS convs
LEFT JOIN xcx_users AS users ON convs.UserKey = users.UserKey
WHERE convs.Id = @Id";
WHERE convs.Guid = @Guid";
using (MySqlCommand cmd = new MySqlCommand(query, _connection))
{
cmd.Parameters.AddWithValue("@Id", conversationId);
cmd.Parameters.AddWithValue("@Guid", conversationGuid);
using (var reader = await cmd.ExecuteReaderAsync())
{
if (await reader.ReadAsync())
@@ -329,21 +334,23 @@ namespace WxCheckApi.Controllers
var messageData = new Dictionary<string, string>
{
["Id"] = reader.GetInt64(0).ToString(),
["UserKey"] = reader.GetString(1),
["ConversationContent"] = reader.GetString(2),
["SendMethod"] = reader.GetString(3),
["UserLocation"] = reader.IsDBNull(4) ? "" : reader.GetString(4),
["Latitude"] = reader.IsDBNull(5) ? "" : reader.GetString(5),
["Longitude"] = reader.IsDBNull(6) ? "" : reader.GetString(6),
["RecordTime"] = reader.GetDateTime(7).ToString("yyyy-MM-dd HH:mm:ss"),
["RecordTimeUTCStamp"] = reader.GetInt64(8).ToString(),
["IsDeleted"] = reader.GetBoolean(9).ToString(),
["CreateTime"] = reader.GetDateTime(10).ToString("yyyy-MM-dd HH:mm:ss"),
["MessageType"] = reader.GetInt32(11).ToString(),
["UserName"] = reader.IsDBNull(12) ? "" : reader.GetString(12),
["WeChatName"] = reader.IsDBNull(13) ? "" : reader.GetString(13),
["PhoneNumber"] = reader.IsDBNull(14) ? "" : reader.GetString(14),
["AvatarUrl"] = reader.IsDBNull(15) ? "" : reader.GetString(15)
["Guid"] = reader.IsDBNull(1) ? "" : reader.GetString(1),
["UserKey"] = reader.GetString(2),
["ConversationContent"] = reader.GetString(3),
["SendMethod"] = reader.GetString(4),
["UserLocation"] = reader.IsDBNull(5) ? "" : reader.GetString(5),
["Latitude"] = reader.IsDBNull(6) ? "" : reader.GetString(6),
["Longitude"] = reader.IsDBNull(7) ? "" : reader.GetString(7),
["RecordTime"] = reader.GetDateTime(8).ToString("yyyy-MM-dd HH:mm:ss"),
["RecordTimeUTCStamp"] = reader.GetInt64(9).ToString(),
["IsDeleted"] = reader.GetBoolean(10).ToString(),
["CreateTime"] = reader.GetDateTime(11).ToString("yyyy-MM-dd HH:mm:ss"),
["MessageType"] = reader.GetInt32(12).ToString(),
["SpeakingTime"] = reader.IsDBNull(13) ? "" : reader.GetInt32(13).ToString(),
["UserName"] = reader.IsDBNull(14) ? "" : reader.GetString(14),
["WeChatName"] = reader.IsDBNull(15) ? "" : reader.GetString(15),
["PhoneNumber"] = reader.IsDBNull(16) ? "" : reader.GetString(16),
["AvatarUrl"] = reader.IsDBNull(17) ? "" : reader.GetString(17)
};
// 发送到Redis Stream
@@ -371,7 +378,7 @@ namespace WxCheckApi.Controllers
}
}
return Ok(new { success = true, message = "收到!", conversationId = conversationId });
return Ok(new { success = true, message = "收到!", conversationGuid, receivedTime = nowtime.ToString("yyyy-MM-dd HH:mm:ss") });
}
catch (Exception ex)
{
@@ -400,7 +407,7 @@ namespace WxCheckApi.Controllers
List<ConversationResponse> conversations = new List<ConversationResponse>();
// 构建查询SQL根据MessageType参数决定是否添加过滤条件
string query = "SELECT Id, UserKey, ConversationContent, SendMethod, UserLocation, Latitude, Longitude, RecordTime, RecordTimeUTCStamp, IsDeleted, CreateTime, MessageType FROM xcx_conversation WHERE UserKey = @UserKey AND IsDeleted = 0";
string query = "SELECT Id, Guid, UserKey, ConversationContent, SendMethod, UserLocation, Latitude, Longitude, RecordTime, RecordTimeUTCStamp, IsDeleted, CreateTime, MessageType, SpeakingTime FROM xcx_conversation WHERE UserKey = @UserKey AND IsDeleted = 0";
if (request.MessageType == 1)
{
query += " AND MessageType = @MessageType";
@@ -418,17 +425,19 @@ namespace WxCheckApi.Controllers
conversations.Add(new ConversationResponse
{
Id = reader.GetInt64(0),
UserKey = reader.GetString(1),
ConversationContent = reader.GetString(2),
SendMethod = reader.GetString(3),
UserLocation = reader.IsDBNull(4) ? "" : reader.GetString(4),
Latitude = reader.IsDBNull(5) ? "" : reader.GetString(5),
Longitude = reader.IsDBNull(6) ? "" : reader.GetString(6),
RecordTime = reader.GetDateTime(7),
RecordTimeUTCStamp = reader.GetInt64(8),
IsDeleted = reader.GetBoolean(9),
CreateTime = reader.GetDateTime(10),
MessageType = reader.GetInt32(11)
Guid = reader.IsDBNull(1) ? "" : reader.GetString(1),
UserKey = reader.GetString(2),
ConversationContent = reader.GetString(3),
SendMethod = reader.GetString(4),
UserLocation = reader.IsDBNull(5) ? "" : reader.GetString(5),
Latitude = reader.IsDBNull(6) ? "" : reader.GetString(6),
Longitude = reader.IsDBNull(7) ? "" : reader.GetString(7),
RecordTime = reader.GetDateTime(8),
RecordTimeUTCStamp = reader.GetInt64(9),
IsDeleted = reader.GetBoolean(10),
CreateTime = reader.GetDateTime(11),
MessageType = reader.GetInt32(12),
SpeakingTime = reader.IsDBNull(13) ? null : reader.GetInt32(13)
});
}
}
@@ -460,14 +469,16 @@ namespace WxCheckApi.Controllers
await _connection.OpenAsync();
}
using (MySqlCommand cmd = new MySqlCommand("UPDATE xcx_conversation SET ConversationContent = @ConversationContent, SendMethod = @SendMethod, UserLocation = @UserLocation, MessageType = @MessageType WHERE Id = @Id AND UserKey = @UserKey", _connection))
DateTime nowtime = DateTime.Now;
using (MySqlCommand cmd = new MySqlCommand("UPDATE xcx_conversation SET ConversationContent = @ConversationContent, SendMethod = @SendMethod, UserLocation = @UserLocation, MessageType = @MessageType, RecordTime = @RecordTime WHERE Guid = @Guid AND UserKey = @UserKey", _connection))
{
cmd.Parameters.AddWithValue("@Id", request.Id);
cmd.Parameters.AddWithValue("@Guid", request.Guid);
cmd.Parameters.AddWithValue("@UserKey", request.UserKey);
cmd.Parameters.AddWithValue("@ConversationContent", request.ConversationContent);
cmd.Parameters.AddWithValue("@SendMethod", request.SendMethod);
cmd.Parameters.AddWithValue("@UserLocation", request.UserLocation ?? "");
cmd.Parameters.AddWithValue("@MessageType", request.MessageType);
cmd.Parameters.AddWithValue("@RecordTime", nowtime);
int rowsAffected = await cmd.ExecuteNonQueryAsync();
@@ -477,7 +488,7 @@ namespace WxCheckApi.Controllers
}
}
return Ok(new { success = true, message = "更新成功" });
return Ok(new { success = true, message = "更新成功" , receivedTime = nowtime.ToString("yyyy-MM-dd HH:mm:ss") });
}
catch (Exception ex)
{
@@ -503,9 +514,9 @@ namespace WxCheckApi.Controllers
await _connection.OpenAsync();
}
using (MySqlCommand cmd = new MySqlCommand("UPDATE xcx_conversation SET IsDeleted = 1 WHERE Id = @Id AND UserKey = @UserKey AND IsDeleted = 0", _connection))
using (MySqlCommand cmd = new MySqlCommand("UPDATE xcx_conversation SET IsDeleted = 1 WHERE Guid = @Guid AND UserKey = @UserKey AND IsDeleted = 0", _connection))
{
cmd.Parameters.AddWithValue("@Id", request.Id);
cmd.Parameters.AddWithValue("@Guid", request.Guid);
cmd.Parameters.AddWithValue("@UserKey", request.UserKey);
int rowsAffected = await cmd.ExecuteNonQueryAsync();
@@ -530,6 +541,70 @@ namespace WxCheckApi.Controllers
}
}
}
// 根据GUID查询会话记录不考虑IsDeleted状态
[HttpPost]
public async Task<IActionResult> GetConversationByGuid([FromBody] GetConversationByGuidRequest request)
{
try
{
if (_connection.State != ConnectionState.Open)
{
await _connection.OpenAsync();
}
// 查询记录不考虑IsDeleted状态
string query = @"SELECT Id, Guid, UserKey, ConversationContent, SendMethod, UserLocation,
Latitude, Longitude, RecordTime, RecordTimeUTCStamp, IsDeleted, CreateTime, MessageType, SpeakingTime
FROM xcx_conversation
WHERE Guid = @Guid";
using (MySqlCommand cmd = new MySqlCommand(query, _connection))
{
cmd.Parameters.AddWithValue("@Guid", request.Guid);
using (var reader = await cmd.ExecuteReaderAsync())
{
if (await reader.ReadAsync())
{
var conversation = new ConversationResponse
{
Id = reader.GetInt64(0),
Guid = reader.IsDBNull(1) ? "" : reader.GetString(1),
UserKey = reader.GetString(2),
ConversationContent = reader.GetString(3),
SendMethod = reader.GetString(4),
UserLocation = reader.IsDBNull(5) ? "" : reader.GetString(5),
Latitude = reader.IsDBNull(6) ? "" : reader.GetString(6),
Longitude = reader.IsDBNull(7) ? "" : reader.GetString(7),
RecordTime = reader.GetDateTime(8),
RecordTimeUTCStamp = reader.GetInt64(9),
IsDeleted = reader.GetBoolean(10),
CreateTime = reader.GetDateTime(11),
MessageType = reader.GetInt32(12),
SpeakingTime = reader.IsDBNull(13) ? null : reader.GetInt32(13)
};
return Ok(new { success = true, message = "查询成功", data = conversation });
}
else
{
return NotFound(new { success = false, message = "未找到该记录" });
}
}
}
}
catch (Exception ex)
{
return StatusCode(500, new { success = false, message = "查询失败", error = ex.Message });
}
finally
{
if (_connection.State == ConnectionState.Open)
{
await _connection.CloseAsync();
}
}
}
// 分页查询会话记录
[HttpPost]
@@ -551,7 +626,7 @@ namespace WxCheckApi.Controllers
List<ConversationResponse> conversations = new List<ConversationResponse>();
// 构建分页查询SQL根据MessageType参数决定是否添加过滤条件
string query = @"SELECT Id, UserKey, ConversationContent, SendMethod, UserLocation, Latitude, Longitude, RecordTime, RecordTimeUTCStamp, IsDeleted, CreateTime, MessageType
string query = @"SELECT Id, Guid, UserKey, ConversationContent, SendMethod, UserLocation, Latitude, Longitude, RecordTime, RecordTimeUTCStamp, IsDeleted, CreateTime, MessageType, SpeakingTime
FROM xcx_conversation
WHERE UserKey = @UserKey AND IsDeleted = 0";
if (request.MessageType == 1)
@@ -577,17 +652,19 @@ namespace WxCheckApi.Controllers
conversations.Add(new ConversationResponse
{
Id = reader.GetInt64(0),
UserKey = reader.GetString(1),
ConversationContent = reader.GetString(2),
SendMethod = reader.GetString(3),
UserLocation = reader.IsDBNull(4) ? "" : reader.GetString(4),
Latitude = reader.IsDBNull(5) ? "" : reader.GetString(5),
Longitude = reader.IsDBNull(6) ? "" : reader.GetString(6),
RecordTime = reader.GetDateTime(7),
RecordTimeUTCStamp = reader.GetInt64(8),
IsDeleted = reader.GetBoolean(9),
CreateTime = reader.GetDateTime(10),
MessageType = reader.GetInt32(11)
Guid = reader.IsDBNull(1) ? "" : reader.GetString(1),
UserKey = reader.GetString(2),
ConversationContent = reader.GetString(3),
SendMethod = reader.GetString(4),
UserLocation = reader.IsDBNull(5) ? "" : reader.GetString(5),
Latitude = reader.IsDBNull(6) ? "" : reader.GetString(6),
Longitude = reader.IsDBNull(7) ? "" : reader.GetString(7),
RecordTime = reader.GetDateTime(8),
RecordTimeUTCStamp = reader.GetInt64(9),
IsDeleted = reader.GetBoolean(10),
CreateTime = reader.GetDateTime(11),
MessageType = reader.GetInt32(12),
SpeakingTime = reader.IsDBNull(13) ? null : reader.GetInt32(13)
});
}
}
@@ -718,6 +795,8 @@ namespace WxCheckApi.Controllers
public double Latitude { get; set; }
public double Longitude { get; set; }
public int MessageType { get; set; } = 1; // 1:公有2:私有
public string? Guid { get; set; } // 会话唯一标识
public int? SpeakingTime { get; set; } // 对话时长
}
public class UserKeyRequest
@@ -736,27 +815,37 @@ namespace WxCheckApi.Controllers
public class UpdateConversationRequest
{
public long Id { get; set; }
public long? Id { get; set; }
public string Guid { get; set; } // 会话唯一标识
public string UserKey { get; set; }
public string ConversationContent { get; set; }
public string SendMethod { get; set; }
public string UserLocation { get; set; }
public int MessageType { get; set; } = 0;
public int? SpeakingTime { get; set; }
}
public class DeleteConversationRequest
{
public long Id { get; set; }
public long? Id { get; set; }
public string Guid { get; set; } // 会话唯一标识
public string UserKey { get; set; }
}
public class CheckAddressRequest
{
public long Id { get; set; }
public long? Id { get; set; }
public string Guid { get; set; } // 会话唯一标识
}
public class GetConversationByGuidRequest
{
public long? Id { get; set; }
public string Guid { get; set; } // 会话唯一标识
}
public class ConversationResponse
{
public long Id { get; set; }
public string Guid { get; set; } // 会话唯一标识
public string UserKey { get; set; }
public string ConversationContent { get; set; }
public string SendMethod { get; set; }
@@ -768,6 +857,7 @@ namespace WxCheckApi.Controllers
public bool IsDeleted { get; set; }
public DateTime CreateTime { get; set; }
public int MessageType { get; set; } // 1:公有消息2:私有消息
public int? SpeakingTime { get; set; }
}
public class RedisMessageRequest

View File

@@ -11,7 +11,7 @@ using System.Threading.Tasks;
using System.Net.Http;
using System.Text.Json;
namespace WxCheckApi.Controllers
namespace WxCheckMvc.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- https://go.microsoft.com/fwlink/?LinkID=208121. -->
<Project>
<PropertyGroup>
<DeleteExistingFiles>true</DeleteExistingFiles>
<ExcludeApp_Data>false</ExcludeApp_Data>
<LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<PublishProvider>FileSystem</PublishProvider>
<PublishUrl>bin\Release\net8.0\publish\</PublishUrl>
<WebPublishMethod>FileSystem</WebPublishMethod>
<_TargetId>Folder</_TargetId>
<SiteUrlToLaunchAfterPublish />
<TargetFramework>net8.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<ProjectGuid>e545c738-a21b-71f3-9fb9-a68d8018822d</ProjectGuid>
<SelfContained>false</SelfContained>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- https://go.microsoft.com/fwlink/?LinkID=208121. -->
<Project>
<PropertyGroup>
<_PublishTargetUrl>E:\Project_Class\WX_XCX\WxCheck_Wx_Prod\WxCheckApi\bin\Release\net8.0\publish\</_PublishTargetUrl>
<History>True|2025-12-05T03:46:42.6952752Z||;True|2025-12-03T17:28:08.6000818+08:00||;True|2025-12-03T15:36:17.3153352+08:00||;True|2025-12-03T15:34:35.0408800+08:00||;True|2025-12-03T15:32:13.7754473+08:00||;True|2025-12-03T15:23:43.3405041+08:00||;True|2025-12-03T11:08:15.0823391+08:00||;True|2025-12-03T11:04:29.8829020+08:00||;True|2025-12-03T11:00:07.4056298+08:00||;True|2025-12-03T10:56:38.5220608+08:00||;True|2025-12-03T10:51:59.6142114+08:00||;</History>
<LastFailureDetails />
</PropertyGroup>
</Project>

View File

@@ -1,3 +1,4 @@
<Solution>
<Project Path="../WxCheckMvc/WxCheckMvc.csproj" Id="5f5aee53-ea7f-4a13-a039-d664f136a7f8" />
<Project Path="WxCheckApi.csproj" />
</Solution>

View File

@@ -11,7 +11,7 @@
Target Server Version : 120002 (12.0.2-MariaDB)
File Encoding : 65001
Date: 07/11/2025 15:03:55
Date: 05/12/2025 11:40:09
*/
SET NAMES utf8mb4;
@@ -34,13 +34,16 @@ CREATE TABLE `xcx_conversation` (
`CreateTime` datetime NULL DEFAULT current_timestamp() COMMENT '创建时间',
`Latitude` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '纬度',
`Longitude` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '经度',
`Guid` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT 'GUID',
`SpeakingTime` int(11) NULL DEFAULT NULL COMMENT '对话时长',
PRIMARY KEY (`Id`) USING BTREE,
INDEX `idx_userkey`(`UserKey` ASC) USING BTREE,
INDEX `idx_utcstamp`(`RecordTimeUTCStamp` ASC) USING BTREE,
INDEX `idx_deleted`(`IsDeleted` ASC) USING BTREE,
INDEX `idx_recordtime`(`RecordTime` ASC) USING BTREE,
INDEX `idx_messagetype`(`MessageType` ASC) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 57 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '会话记录表' ROW_FORMAT = Dynamic;
INDEX `idx_messagetype`(`MessageType` ASC) USING BTREE,
INDEX `idx_guid`(`Guid` ASC) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 418 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '会话记录表' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for xcx_log
@@ -78,6 +81,6 @@ CREATE TABLE `xcx_users` (
UNIQUE INDEX `idx_userkey`(`UserKey` ASC) USING BTREE,
INDEX `idx_disabled`(`IsDisabled` ASC) USING BTREE,
INDEX `idx_logintime`(`FirstLoginTime` ASC) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 10 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '小程序用户表' ROW_FORMAT = Dynamic;
) ENGINE = InnoDB AUTO_INCREMENT = 22 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '小程序用户表' ROW_FORMAT = Dynamic;
SET FOREIGN_KEY_CHECKS = 1;