Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Q
qk_backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
quanku
qk_backend
Commits
4837173d
Commit
4837173d
authored
Oct 18, 2023
by
shiyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
IM ai助手
parent
e5cbbcc4
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
102 additions
and
6 deletions
+102
-6
ch-core/src/main/java/com/wwdz/ch/core/entity/OfficialAccountShareSubscribeMsg.java
...wwdz/ch/core/entity/OfficialAccountShareSubscribeMsg.java
+0
-1
ch-core/src/main/java/com/wwdz/ch/core/im/api/ChatUserApi.java
...re/src/main/java/com/wwdz/ch/core/im/api/ChatUserApi.java
+40
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/config/WebMvcConfiguration.java
.../main/java/com/wwdz/ch/wx/config/WebMvcConfiguration.java
+2
-1
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/IMServiceImpl.java
...-api/src/main/java/com/wwdz/ch/wx/impl/IMServiceImpl.java
+5
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/UserServiceImpl.java
...pi/src/main/java/com/wwdz/ch/wx/impl/UserServiceImpl.java
+10
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/service/IMService.java
...x-api/src/main/java/com/wwdz/ch/wx/service/IMService.java
+8
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/web/IMController.java
ch-wx-api/src/main/java/com/wwdz/ch/wx/web/IMController.java
+12
-1
ch-wx-api/src/test/java/com/wwdz/ch/wx/api/ChatApiTest.java
ch-wx-api/src/test/java/com/wwdz/ch/wx/api/ChatApiTest.java
+25
-3
No files found.
ch-core/src/main/java/com/wwdz/ch/core/entity/OfficialAccountShareSubscribeMsg.java
View file @
4837173d
...
...
@@ -2,7 +2,6 @@ package com.wwdz.ch.core.entity;
import
com.xxdxxs.entity.Entity
;
import
lombok.Data
;
import
java.util.HashMap
;
import
java.util.Map
;
...
...
ch-core/src/main/java/com/wwdz/ch/core/im/api/ChatUserApi.java
View file @
4837173d
...
...
@@ -7,6 +7,7 @@ import com.wwdz.ch.core.util.IMUtil;
import
com.wwdz.ch.core.util.OkHttpUtil
;
import
com.wwdz.ch.core.util.RedisUtils
;
import
com.wwdz.ch.db.dao.UserDao
;
import
com.wwdz.ch.db.domain.AiAssistant
;
import
com.wwdz.ch.db.domain.User
;
import
com.xxdxxs.utils.JsonUtils
;
import
org.slf4j.Logger
;
...
...
@@ -86,6 +87,45 @@ public class ChatUserApi {
}
/**
* 导入AI助手信息到IM中
* @return
*/
public
Result
importAiUser
(
AiAssistant
aiAssistant
)
{
String
userSig
=
tlsSigApi
.
getUserSig
(
ADMIN_ID
);
Random
random
=
new
Random
(
4294967295L
);
long
randomNum
=
random
.
nextInt
();
StringBuffer
stringBuffer
=
new
StringBuffer
();
stringBuffer
.
append
(
"?sdkappid="
+
SDKAppID
);
stringBuffer
.
append
(
"&identifier="
+
ADMIN_ID
);
stringBuffer
.
append
(
"&usersig="
+
userSig
);
stringBuffer
.
append
(
"&random="
+
randomNum
);
stringBuffer
.
append
(
"&contenttype=json"
);
String
url
=
ACCOUNT_URL
+
stringBuffer
.
toString
();
logger
.
info
(
"============== IM导入用户请求url : {}"
,
url
);
OkHttpUtil
okHttpUtil
=
OkHttpUtil
.
builder
().
url
(
url
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"UserID"
,
imUtil
.
formatUserId
(
aiAssistant
.
getCode
()));
map
.
put
(
"Nick"
,
aiAssistant
.
getName
());
map
.
put
(
"FaceUrl"
,
aiAssistant
.
getAvatar
());
logger
.
info
(
"============ 导入AI助手内容 : {}"
,
JsonUtils
.
fromMap
(
map
));
okHttpUtil
.
addParams
(
map
);
okHttpUtil
.
post
(
true
);
String
responseStr
=
okHttpUtil
.
async
();
logger
.
info
(
"AI助手 : {}, 导入AI助手 response :{}"
,
aiAssistant
.
getCode
(),
responseStr
);
String
actionStatus
=
JsonUtils
.
getValueByPath
(
responseStr
,
"ActionStatus"
);
String
errorCode
=
JsonUtils
.
getValueByPath
(
responseStr
,
"ErrorCode"
);
String
errorInfo
=
JsonUtils
.
getValueByPath
(
responseStr
,
"ErrorInfo"
);
if
(!
"OK"
.
equals
(
actionStatus
))
{
logger
.
error
(
"AI助手 : {}, 导入AI助手失败, errorCode : {}, errmsg : {} "
,
aiAssistant
.
getCode
(),
errorCode
,
errorInfo
);
return
Result
.
failed
(
errorInfo
);
}
logger
.
info
(
"============= 导入AI助手成功 ==========="
);
return
Result
.
success
();
}
/**
* IM用户初始化
* 导入表中已有全部的用户
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/config/WebMvcConfiguration.java
View file @
4837173d
...
...
@@ -42,7 +42,8 @@ public class WebMvcConfiguration implements WebMvcConfigurer {
"/officialAccountCallback/**"
,
"/wx/officialAccount/**"
,
"/wx/item/**"
,
"/wx/aiAssistant/**"
"/wx/aiAssistant/**"
,
"/wx/im/**"
);
}
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/IMServiceImpl.java
View file @
4837173d
...
...
@@ -84,4 +84,9 @@ public class IMServiceImpl implements IMService {
}
return
Result
.
failed
();
}
@Override
public
Result
sendChatMsg
(
SendChatMsgRequestDto
dto
)
{
return
null
;
}
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/UserServiceImpl.java
View file @
4837173d
...
...
@@ -53,6 +53,10 @@ import java.util.Objects;
@Service
public
class
UserServiceImpl
implements
UserService
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
UserServiceImpl
.
class
);
//默认的ai机器人编码,用于ai助手的聊天,该机器人永远在会话列表中置顶
private
static
final
String
DEFAULT_AI_CODE
=
"ai10000"
;
@Autowired
private
UserDao
userDao
;
@Autowired
...
...
@@ -85,6 +89,8 @@ public class UserServiceImpl implements UserService {
private
FollowFansRecordService
followFansRecordService
;
@Override
public
Result
regCaptcha
(
UserRequestDto
dto
)
{
try
{
...
...
@@ -145,6 +151,8 @@ public class UserServiceImpl implements UserService {
if
(!
isOpen
)
{
result
.
put
(
"isInvited"
,
true
);
}
//添加默认AI机器人code
result
.
put
(
"defaultAiCode"
,
DEFAULT_AI_CODE
);
logger
.
info
(
"【请求结束】手机号登录,响应结果:{}"
,
JSONObject
.
toJSONString
(
result
));
// 清除验证码缓存
redisUtil
.
del
(
key
);
...
...
@@ -213,6 +221,8 @@ public class UserServiceImpl implements UserService {
if
(!
isOpen
)
{
result
.
put
(
"isInvited"
,
true
);
}
//添加默认AI机器人code
result
.
put
(
"defaultAiCode"
,
DEFAULT_AI_CODE
);
logger
.
info
(
"【请求结束】快捷登录成功,响应结果:{}"
,
JSONObject
.
toJSONString
(
result
));
return
Result
.
success
(
result
);
}
catch
(
Exception
e
)
{
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/service/IMService.java
View file @
4837173d
...
...
@@ -27,4 +27,12 @@ public interface IMService {
* @return
*/
Result
getUserSig
(
IMChatRequestDto
dto
);
/**
* 发送会话消息
* @param dto
* @return
*/
Result
sendChatMsg
(
SendChatMsgRequestDto
dto
);
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/web/IMController.java
View file @
4837173d
...
...
@@ -63,6 +63,17 @@ public class IMController {
}
return
imService
.
getUserSig
(
dto
);
}
@ApiOperation
(
value
=
"发送聊天消息"
)
@PostMapping
(
"/sendChatMsg"
)
public
Result
sendChatMsg
(
@RequestBody
SendChatMsgRequestDto
dto
)
{
logger
.
info
(
"【请求开始】发送聊天消息,请求参数:{}"
,
JSON
.
toJSONString
(
dto
));
if
(!
StringUtils
.
isAllNotEmpty
(
dto
.
getFrom_Account
(),
dto
.
getTo_Account
(),
dto
.
getMsgType
()))
{
return
Result
.
failed
(
ResultCode
.
PARAM_ERROR
);
}
return
imService
.
sendChatMsg
(
dto
);
}
}
ch-wx-api/src/test/java/com/wwdz/ch/wx/api/ChatApiTest.java
View file @
4837173d
...
...
@@ -6,14 +6,20 @@ import com.wwdz.ch.core.entity.im.SendChatMsgRequestDto;
import
com.wwdz.ch.core.im.api.ChatUserApi
;
import
com.wwdz.ch.core.im.api.ConversationApi
;
import
com.wwdz.ch.core.im.api.TLSSigApi
;
import
com.wwdz.ch.db.dao.AiAssistantDao
;
import
com.wwdz.ch.db.dao.UserDao
;
import
com.wwdz.ch.db.domain.AiAssistant
;
import
com.wwdz.ch.db.domain.User
;
import
com.wwdz.ch.db.dto.request.AiAssistantRequestDto
;
import
com.wwdz.ch.wx.service.AiAssistantService
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
java.util.List
;
@SpringBootTest
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
...
...
@@ -34,6 +40,9 @@ public class ChatApiTest {
@Autowired
TLSSigApi
tlsSigApi
;
@Autowired
AiAssistantDao
aiAssistantDao
;
@Test
public
void
chatWithModel
()
{
String
question
=
"刀币的由来"
;
...
...
@@ -55,6 +64,18 @@ public class ChatApiTest {
}
/**
* 导入Ai助手
*/
@Test
public
void
importAiUser
()
{
List
<
AiAssistant
>
aiAssistants
=
aiAssistantDao
.
findList
(
new
AiAssistantRequestDto
());
aiAssistants
.
forEach
(
aiAssistant
->
{
chatUserApi
.
importAiUser
(
aiAssistant
);
});
}
/**
* 导入系统所有用户
*/
...
...
@@ -70,9 +91,10 @@ public class ChatApiTest {
public
void
sendChatMsg
()
{
SendChatMsgRequestDto
sendChatMsgRequestDto
=
new
SendChatMsgRequestDto
();
sendChatMsgRequestDto
.
setTo_Account
(
"241"
);
sendChatMsgRequestDto
.
setFrom_Account
(
"
251
"
);
sendChatMsgRequestDto
.
setFrom_Account
(
"
ai10000
"
);
sendChatMsgRequestDto
.
setMsgType
(
IMEnum
.
MsgTypeEnum
.
TIMTextElem
.
getCode
());
String
msgContent
=
"测试消息4444444的数据, 是否可以接收到"
;
long
timestamp
=
System
.
currentTimeMillis
();
String
msgContent
=
timestamp
+
" >> ai测试消息的数据, 是否可以接收到"
;
sendChatMsgRequestDto
.
setMsgContent
(
msgContent
);
conversationApi
.
sendChatMsg
(
sendChatMsgRequestDto
);
}
...
...
@@ -83,7 +105,7 @@ public class ChatApiTest {
@Test
public
void
getChatList
()
{
IMChatRequestDto
imChatRequestDto
=
new
IMChatRequestDto
();
imChatRequestDto
.
setUserId
(
2
5
1L
);
imChatRequestDto
.
setUserId
(
2
4
1L
);
conversationApi
.
getChatList
(
imChatRequestDto
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment