青年时种下什么,老年时就收获什么——易卜生

API地址:https://developer.yahoo.co.jp/webapi/jlp/kousei/v2/kousei.html

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package com.ruben;

import cn.hutool.core.map.MapUtil;
import cn.hutool.core.text.CharPool;
import cn.hutool.core.text.StrPool;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.hutool.log.StaticLog;
import cn.hutool.setting.Setting;

import java.util.LinkedHashMap;

/**
* YaHoo
*
* @author VampireAchao
* @since 2022/9/6
*/
public class YaHoo {

/**
* 地址与鉴权信息,配置文件中
*/
public static final String HOST_URL;
public static final String APP_ID;

static {
// 加载配置文件
Setting setting = new Setting("app.setting");
HOST_URL = setting.get("HOST_URL");
APP_ID = setting.get("APP_ID");
setting.clear();
}

public static void main(String[] args) {
inspect("セキュリティー,食べれる");
}

public static JSONObject inspect(String words) {
String json = getRequestJson(words);
String backResult = HttpUtil.post(HOST_URL + "?appid=" + APP_ID, json);
StaticLog.debug("文本纠错返回结果:" + backResult);
return JSONUtil.parseObj(backResult);
}

private static String getRequestJson(String words) {
return JSONUtil.toJsonStr(MapUtil.builder(new LinkedHashMap<>())
.put("id", "1234-1")
.put("jsonrpc", "2.0")
.put("method", "jlp.kouseiservice.kousei")
.put("params", MapUtil.builder(new LinkedHashMap<>())
.put("q", words)
.build())
.build());
}
}

这里配置文件app.settingresources目录下

1
2
3
4
5
6
7
# -------------------------------------------------------------
# ----- Setting File with UTF8-----
# ----- 服务接口认证信息配置文件 -----
# -------------------------------------------------------------

HOST_URL = https://jlp.yahooapis.jp/KouseiService/V2/kousei
APP_ID = <YOUR_APP_ID>

效果

image-20220907153505803