Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 18c5887

Browse files
Copilotbinarywang
andcommitted
Revert intelligent conversation implementation - API endpoint does not exist in official WeChat documentation
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
1 parent 27de971 commit 18c5887

File tree

6 files changed

+1
-222
lines changed

6 files changed

+1
-222
lines changed

‎weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpAiOpenService.java‎

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import java.io.File;
44

55
import me.chanjar.weixin.common.error.WxErrorException;
6-
import me.chanjar.weixin.mp.bean.WxMpAiConversationRequest;
7-
import me.chanjar.weixin.mp.bean.WxMpAiConversationResponse;
86
import me.chanjar.weixin.mp.enums.AiLangType;
97

108
/**
@@ -78,49 +76,4 @@ public interface WxMpAiOpenService {
7876
* @throws WxErrorException the wx error exception
7977
*/
8078
String translate(AiLangType langFrom, AiLangType langTo, String content) throws WxErrorException;
81-
82-
/**
83-
* <pre>
84-
* 微信智能对话.
85-
* 基于WeChat AI Speech平台的智能对话功能
86-
*
87-
* 文档地址:https://developers.weixin.qq.com/doc/aispeech/platform/INTRODUCTION.html
88-
* </pre>
89-
*
90-
* @param query 用户输入的对话内容
91-
* @param sessionId 会话ID,用于保持对话上下文
92-
* @return 智能对话回复内容
93-
* @throws WxErrorException the wx error exception
94-
*/
95-
String intelligentConversation(String query, String sessionId) throws WxErrorException;
96-
97-
/**
98-
* <pre>
99-
* 微信智能对话(带语言参数).
100-
* 基于WeChat AI Speech平台的智能对话功能
101-
*
102-
* 文档地址:https://developers.weixin.qq.com/doc/aispeech/platform/INTRODUCTION.html
103-
* </pre>
104-
*
105-
* @param query 用户输入的对话内容
106-
* @param sessionId 会话ID,用于保持对话上下文
107-
* @param lang 语言类型,默认中文
108-
* @return 智能对话回复内容
109-
* @throws WxErrorException the wx error exception
110-
*/
111-
String intelligentConversation(String query, String sessionId, AiLangType lang) throws WxErrorException;
112-
113-
/**
114-
* <pre>
115-
* 微信智能对话(使用请求对象).
116-
* 基于WeChat AI Speech平台的智能对话功能,支持更复杂的请求参数
117-
*
118-
* 文档地址:https://developers.weixin.qq.com/doc/aispeech/platform/INTRODUCTION.html
119-
* </pre>
120-
*
121-
* @param request 智能对话请求对象
122-
* @return 智能对话响应对象
123-
* @throws WxErrorException the wx error exception
124-
*/
125-
WxMpAiConversationResponse intelligentConversation(WxMpAiConversationRequest request) throws WxErrorException;
12679
}
Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
package me.chanjar.weixin.mp.api.impl;
22

3-
import com.google.gson.JsonObject;
43
import lombok.RequiredArgsConstructor;
54
import me.chanjar.weixin.common.enums.WxType;
65
import me.chanjar.weixin.common.error.WxError;
76
import me.chanjar.weixin.common.error.WxErrorException;
87
import me.chanjar.weixin.common.util.json.GsonParser;
98
import me.chanjar.weixin.mp.api.WxMpAiOpenService;
109
import me.chanjar.weixin.mp.api.WxMpService;
11-
import me.chanjar.weixin.mp.bean.WxMpAiConversationRequest;
12-
import me.chanjar.weixin.mp.bean.WxMpAiConversationResponse;
1310
import me.chanjar.weixin.mp.enums.AiLangType;
1411
import me.chanjar.weixin.mp.util.requestexecuter.voice.VoiceUploadRequestExecutor;
1512

@@ -73,59 +70,4 @@ public String queryRecognitionResult(String voiceId, AiLangType lang) throws WxE
7370

7471
return GsonParser.parse(response).get("result").getAsString();
7572
}
76-
77-
@Override
78-
public String intelligentConversation(String query, String sessionId) throws WxErrorException {
79-
return this.intelligentConversation(query, sessionId, AiLangType.zh_CN);
80-
}
81-
82-
@Override
83-
public String intelligentConversation(String query, String sessionId, AiLangType lang) throws WxErrorException {
84-
if (lang == null) {
85-
lang = AiLangType.zh_CN;
86-
}
87-
88-
// 构建请求JSON
89-
JsonObject request = new JsonObject();
90-
request.addProperty("query", query);
91-
request.addProperty("session_id", sessionId);
92-
request.addProperty("lang", lang.getCode());
93-
94-
final String response = this.wxMpService.post(INTELLIGENT_CONVERSATION_URL.getUrl(this.wxMpService.getWxMpConfigStorage()),
95-
request.toString());
96-
97-
WxError error = WxError.fromJson(response, WxType.MP);
98-
if (error.getErrorCode() != 0) {
99-
throw new WxErrorException(error);
100-
}
101-
102-
return GsonParser.parse(response).get("reply").getAsString();
103-
}
104-
105-
@Override
106-
public WxMpAiConversationResponse intelligentConversation(WxMpAiConversationRequest request) throws WxErrorException {
107-
// 构建请求JSON
108-
JsonObject requestJson = new JsonObject();
109-
requestJson.addProperty("query", request.getQuery());
110-
requestJson.addProperty("session_id", request.getSessionId());
111-
requestJson.addProperty("lang", request.getLang() != null ? request.getLang().getCode() : AiLangType.zh_CN.getCode());
112-
113-
final String response = this.wxMpService.post(INTELLIGENT_CONVERSATION_URL.getUrl(this.wxMpService.getWxMpConfigStorage()),
114-
requestJson.toString());
115-
116-
WxError error = WxError.fromJson(response, WxType.MP);
117-
if (error.getErrorCode() != 0) {
118-
throw new WxErrorException(error);
119-
}
120-
121-
WxMpAiConversationResponse result = WxMpAiConversationResponse.fromJson(response);
122-
if (result.getReply() == null) {
123-
result.setReply(GsonParser.parse(response).get("reply").getAsString());
124-
}
125-
if (result.getSessionId() == null) {
126-
result.setSessionId(request.getSessionId());
127-
}
128-
129-
return result;
130-
}
13173
}

‎weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpAiConversationRequest.java‎

Lines changed: 0 additions & 40 deletions
This file was deleted.

‎weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpAiConversationResponse.java‎

Lines changed: 0 additions & 44 deletions
This file was deleted.

‎weixin-java-mp/src/main/java/me/chanjar/weixin/mp/enums/WxMpApiUrl.java‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -469,11 +469,7 @@ enum AiOpen implements WxMpApiUrl {
469469
/**
470470
* queryrecoresultfortext.
471471
*/
472-
VOICE_QUERY_RESULT_URL(API_DEFAULT_HOST_URL, "/cgi-bin/media/voice/queryrecoresultfortext"),
473-
/**
474-
* 智能对话.
475-
*/
476-
INTELLIGENT_CONVERSATION_URL(API_DEFAULT_HOST_URL, "/cgi-bin/aispeech/conversation");
472+
VOICE_QUERY_RESULT_URL(API_DEFAULT_HOST_URL, "/cgi-bin/media/voice/queryrecoresultfortext");
477473

478474
private final String prefix;
479475
private final String path;

‎weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpAiOpenServiceImplTest.java‎

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
import me.chanjar.weixin.common.error.WxErrorException;
99
import me.chanjar.weixin.mp.api.WxMpService;
1010
import me.chanjar.weixin.mp.api.test.ApiTestModule;
11-
import me.chanjar.weixin.mp.bean.WxMpAiConversationRequest;
12-
import me.chanjar.weixin.mp.bean.WxMpAiConversationResponse;
1311
import me.chanjar.weixin.mp.enums.AiLangType;
1412

1513
import static org.assertj.core.api.Assertions.assertThat;
@@ -47,30 +45,4 @@ public void testTranslate() throws WxErrorException {
4745
final String result = this.wxService.getAiOpenService().translate(AiLangType.zh_CN, AiLangType.en_US, "微信文档很坑爹");
4846
assertThat(result).isNotEmpty();
4947
}
50-
51-
@Test
52-
public void testIntelligentConversation() throws WxErrorException {
53-
String sessionId = "test_session_" + System.currentTimeMillis();
54-
final String result = this.wxService.getAiOpenService().intelligentConversation("你好", sessionId);
55-
assertThat(result).isNotEmpty();
56-
}
57-
58-
@Test
59-
public void testIntelligentConversationWithLang() throws WxErrorException {
60-
String sessionId = "test_session_" + System.currentTimeMillis();
61-
final String result = this.wxService.getAiOpenService().intelligentConversation("你好,请介绍一下微信", sessionId, AiLangType.zh_CN);
62-
assertThat(result).isNotEmpty();
63-
}
64-
65-
@Test
66-
public void testIntelligentConversationWithRequest() throws WxErrorException {
67-
WxMpAiConversationRequest request = new WxMpAiConversationRequest();
68-
request.setQuery("微信智能对话功能怎么使用?");
69-
request.setSessionId("test_session_bean_" + System.currentTimeMillis());
70-
request.setLang(AiLangType.zh_CN);
71-
72-
final WxMpAiConversationResponse result = this.wxService.getAiOpenService().intelligentConversation(request);
73-
assertThat(result).isNotNull();
74-
assertThat(result.getReply()).isNotEmpty();
75-
}
7648
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /