百度API 控制台地址: https://console.bce.baidu.com/?fromai=1#/aip/overview
创建应用后获得 API Key – Secret Key
maven 依赖
普通项目去maven中央仓库根据groupId 搜索下载 jar 包
com.baidu.aip
java-sdk
4.5.0
org.apache.httpcomponents
httpcore
org.apache.httpcomponents
httpclient
net.sf.json-lib
json-lib
2.4
jdk15
token 获取方法(需先创建应用)
package com.example.demo;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import java.util.Map;
import net.sf.json.JSONObject;
public class AuthService {
static String clientId = "YvWmx5eHYExqwI76606MsExd";
static String clientSecret = "Re93cqHB7ElIzSzTZnO4bOUsGmNvKm4Q";
public static long tokenTime = 0L;
public static String access_token;
public static String getToken() {
if (System.currentTimeMillis() > tokenTime) {
getAuth();
}