Skip to content

Commit 6171924

Browse files
🔧 tuling api key config
1 parent 0ba0c39 commit 6171924

7 files changed

Lines changed: 14 additions & 8 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
## Config
2222

23+
请先前往图灵官网注册并获取apiKey, *[http://www.turingapi.com](http://www.turingapi.com)*
24+
2325
`config.yaml`:
2426

2527
```yml
@@ -34,6 +36,7 @@ loverPrattle: # 每天发送土味情话配置
3436

3537
autoReply: # 自动回复配置
3638
enable: true # 是否启用
39+
tulingApiKey: asdasdasdasdasd # 图灵apiKey
3740
nickNames: # 自动回复名单, 可配置多个, 群回复需要@
3841
- Bot567
3942
prefix: 【~(≧▽≦)~】 # 自动回复小尾巴

src/main/java/io/github/biezhi/wechat/MyBot.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void groupMessage(WeChatMessage message) {
5050

5151
private void autoReplyByAI(WeChatMessage message) {
5252
this.api().sendText(message.getFromUserName(),
53-
getMessagePrefix() + Tuling.send(message, this.client().nativeOkHttpClient()));
53+
getMessagePrefix() + Tuling.send(message, this.client().nativeOkHttpClient(), this.customConfig().getAutoReply().getTulingApiKey()));
5454
}
5555

5656
private String getMessagePrefix() {

src/main/java/io/github/biezhi/wechat/ai/tuling/Tuling.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
*/
2121
public class Tuling {
2222

23-
public static String send(WeChatMessage message, OkHttpClient client) {
23+
public static String send(WeChatMessage message, OkHttpClient client, String apiKey) {
2424
try {
2525
Request.Builder builder = new Request.Builder();
2626
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json;charset=UTF-8"),
27-
WeChatUtils.toJson(TulingReq.of(message.getText(), message.getGroupMsgOwner().substring(1, 10))));
27+
WeChatUtils.toJson(TulingReq.of(message.getText(), message.getGroupMsgOwner().substring(1, 10), apiKey)));
2828
Request request = builder.url("http://openapi.tuling123.com/openapi/api/v2")
2929
.post(requestBody)
3030
.build();

src/main/java/io/github/biezhi/wechat/ai/tuling/req/TulingReq.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class TulingReq {
1515
private Perception perception;
1616
private UserInfo userInfo;
1717

18-
public static TulingReq of(String text, String userId) {
19-
return new TulingReq().setPerception(Perception.of(text)).setUserInfo(UserInfo.of(userId));
18+
public static TulingReq of(String text, String userId, String apiKey) {
19+
return new TulingReq().setPerception(Perception.of(text)).setUserInfo(UserInfo.of(userId, apiKey));
2020
}
2121
}

src/main/java/io/github/biezhi/wechat/ai/tuling/req/UserInfo.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
@Accessors(chain = true)
1313
public class UserInfo {
1414

15-
private String apiKey = "b24b376ec0444b418035720785a8cde4";
15+
private String apiKey;
1616
private String userId;
1717

18-
public static UserInfo of(String userId) {
19-
return new UserInfo().setUserId(userId);
18+
public static UserInfo of(String userId, String apiKey) {
19+
return new UserInfo().setUserId(userId).setApiKey(apiKey);
2020
}
2121
}

src/main/java/io/github/biezhi/wechat/api/constant/custom/AutoReply.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public class AutoReply {
1515

1616
private Boolean enable = false;
1717

18+
private String tulingApiKey;
19+
1820
private Set<String> nickNames;
1921

2022
private String prefix;

src/main/resources/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ loverPrattle:
99

1010
autoReply:
1111
enable: true
12+
tulingApiKey: b24b376ec0444b418035720785a8cde4
1213
nickNames:
1314
- Bot567
1415
prefix: 【~(≧▽≦)~】

0 commit comments

Comments
 (0)