package com.cl.utils;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONObject;
import com.baidu.aip.ocr.AipOcr;
import com.baidu.aip.imageclassify.AipImageClassify;
/**
* 类说明 :
*/
public class BaiduUtil {
/**
* 根据经纬度获得省市区信息
* @param lon 纬度
* @param lat 经度
* @param coordtype 经纬度坐标系
* @return
*/
public static Map<String, String> getCityByLonLat(String key, String lng, String lat) {
String location = lat + "," + lng;
try {
//拼装url
String url = "http://api.map.baidu.com/reverse_geocoding/v3/?ak="+key+"&output=json&coordtype=wgs84ll&location="+location;
String result = HttpClientUtils.doGet(url);
JSONObject o = new JSONObject(result);
Map<String, String> area = new HashMap<>();
area.put("province", o.getJSONObject("result").getJSONObject("addressComponent").getString("province"));
area.put("city", o.getJSONObject("result").getJSONObject("addressComponent").getString("city"));
area.put("district", o.getJSONObject("result").getJSONObject("addressComponent").getString("district"));
area.put("street", o.getJSONObject("result").getJSONObject("addressComponent").getString("street"));
return area;
}catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* 获取API访问token
* 该token有一定的有效期,需要自行管理,当失效时需重新获取.
* @param ak - 百度云官网获取的 API Key
* @param sk - 百度云官网获取的 Securet Key
* @return assess_token
*/
public static String getAuth(String ak, String sk) {
// 获取token地址
String authHost = "https://aip.baidubce.com/oauth/2.0/token?";
String getAccessTokenUrl = authHost
// 1. grant_type为固定参数
+ "grant_type=client_credentials"
// 2. 官网获取的 API Key
+ "&client_id=" + ak
// 3. 官网获取的 Secret Key
+ "&client_secret=" + sk;
try {
URL realUrl = new URL(getAccessTokenUrl);
// 打开和URL之间的连接
HttpURLConnection connection = (HttpURLConnection) realUrl.openConnection();
connection.setRequestMethod("GET");
connection.connect();
// 获取所有响应头字段
Map<String, List<String>> map = connection.getHeaderFields();
// 遍历所有的响应头字段
for (String key : map.keySet()) {
System.err.println(key + "--->" + map.get(key));
}
// 定义 BufferedReader输入流来读取URL的响应
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String result = "";
String line;
while ((line = in.readLine()) != null) {
result += line;
}
/**
* 返回结果示例
*/
System.err.println("result:" + result);
org.json.JSONObject jsonObject = new org.json.JSONObject(result);
String access_token = jsonObject.getString("access_token");
return access_token;
} catch (Exception e) {
System.err.printf("获取token失败!");
e.printStackTrace(System.err);
}
return null;
}
//设置APPID/AK/SK
public static final String APP_ID = "40927715";
public static final String API_KEY = "DPinK7BkM3yI4Qptnr0eFZNH";
public static final String SECRET_KEY = "wmZbglKccAGMBwzZCyn9IVQfK2ObRAtc";
private static AipOcr ocrClient = null;
/**
* 识别图片上的文本内容,转成文字字符串返回
* @param imagePath 图片文件的路径
*/
public static String generalString(String imagePath, boolean isNewline){
try{
HashMap<String, String> options = new HashMap<String, String>();
options.put("language_type", "CHN_ENG"); //CHN_ENG:中英文混合, ENG:英文
options.put("detect_direction", "true"); //是否检测图像朝向,默认不检测,即:false
options.put("detect_language", "true"); //是否检测语言,默认不检测。
options.put("probability", "false"); //是否返回识别结果中每一行的置信度
//通用文字识别
if(ocrClient==null) {
ocrClient = new AipOcr(APP_ID, API_KEY, SECRET_KEY);
ocrClient.setConnectionTimeoutInMillis(5000);
ocrClient.setSocketTimeoutInMillis(60000);
}
JSONObject jsonObject = ocrClient.basicAccurateGeneral(imagePath, options);
String result = mergeString(jsonObject, isNewline);
return result;
}catch(Exception ex){
ex.printStackTrace();
}
return null;
}
private static String mergeString(JSONObject jsonObject, boolean isNewline){
if(jsonObject == null){
return "";
}
if(jsonObject.has("words_result") && jsonObject.has("words_result_num")){
int wordsResultNum = jsonObject.getInt("words_result_num");
if(wordsResultNum > 0){
StringBuilder sb = new StringBuilder();
JSONArray jsonArray = jsonObject.getJSONArray("words_result");
int len = jsonArray.length();
for(int i=0;i<len;i++) {
JSONObject obj = (JSONObject)jsonArray.get(i);
if(isNewline){
sb.append(obj.get("words") + "\n");
}else{
sb.append(obj.get("words"));
}
}
return sb.toString();
}
}else{
return jsonObject.toString();
}
return null;
}
public static JSONObject animalDetect(String imgPath) {
//初始化
AipImageClassify aic = new AipImageClassify(APP_ID, API_KEY, SECRET_KEY);
//返回JSON格式的数据
HashMap<String, String> params = new HashMap<String, String>();
params.put("baike_num", "1");
JSONObject res = aic.animalDetect(imgPath, params);
System.out.println(res.toString(2));
return res;
}
public static JSONObject dishDetect(String imgPath) {
//初始化
AipImageClassify aic = new AipImageClassify(APP_ID, API_KEY, SECRET_KEY);
//返回JSON格式的数据
HashMap<String, String> params = new HashMap<String, String>();
params.put("baike_num", "1");
JSONObject res = aic.dishDetect(imgPath, params);
System.out.println(res.toString(2));
return res;
}
public static JSONObject plantDetect(String imgPath) {
//初始化
AipImageClassify aic = new AipImageClassify(APP_ID, API_KEY, SECRET_KEY);
//返回JSON格式的数据
HashMap<String, String> params = new HashMap<String, String>();
params.put("baike_num", "1");
JSONObject res = aic.plantDetect(imgPath, params);
System.out.println(res.toString(2));
return res;
}
public static JSONObject advancedGeneral(String imgPath) {
//初始化
AipImageClassify aic = new AipImageClassify(APP_ID, API_KEY, SECRET_KEY);
//返回JSON格式的数据
HashMap<String, String> params = new HashMap<String, String>();
没有合适的资源?快使用搜索试试~ 我知道了~
基于springboot数字资源共享平台源码数据库文档.zip
共371个文件
java:100个
vue:82个
png:47个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 2 浏览量
2024-11-18
10:46:18
上传
评论
收藏 17.28MB ZIP 举报
温馨提示
基于springboot数字资源共享平台源码数据库文档.zip
资源推荐
资源详情
资源评论
收起资源包目录
基于springboot数字资源共享平台源码数据库文档.zip (371个子文件)
chunk-vendors.83167ee3.css 339KB
chunk-vendors.9650af1e.css 319KB
app.2e26043f.css 207KB
app.df35604c.css 142KB
565.5d54edbe.css 10KB
806.3e0d8505.css 3KB
536.1108b1aa.css 3KB
279.799fb85e.css 1KB
iconfont.css 622B
canvas-bg-1.css 391B
canvas-bg-1.css 391B
canvas-bg-2.css 83B
canvas-bg-2.css 83B
canvas-bg-4.css 61B
canvas-bg-5.css 61B
canvas-bg-3.css 61B
canvas-bg-4.css 61B
canvas-bg-3.css 61B
canvas-bg-5.css 61B
.env.development 195B
.env.development 195B
数据库表结构文档.doc 918KB
.gitignore 231B
index.html 777B
index.html 774B
index.html 692B
index.html 689B
favicon.ico 4KB
favicon.ico 4KB
favicon.ico 4KB
favicon.ico 4KB
BaiduUtil.java 8KB
EncryptUtil.java 8KB
ZhuanjiaController.java 8KB
YonghuController.java 8KB
CommonController.java 7KB
ChatController.java 6KB
ForumController.java 6KB
MenuController.java 6KB
YaocairenzhengxinxiController.java 6KB
YaocaigongxiaoController.java 6KB
YaocaishuxingController.java 6KB
YaocaifenleiController.java 6KB
YaocaiziyuanController.java 6KB
YaocaiziyuanEntity.java 5KB
UsersController.java 5KB
MPUtil.java 5KB
YaocairenzhengxinxiEntity.java 4KB
FileController.java 4KB
CommonUtil.java 4KB
ForumEntity.java 4KB
ZhuanjiaEntity.java 3KB
YonghuEntity.java 3KB
AuthorizationInterceptor.java 3KB
ConfigController.java 3KB
ChatEntity.java 3KB
HttpClientUtils.java 3KB
YaocaishuxingEntity.java 3KB
YaocaigongxiaoEntity.java 3KB
Query.java 3KB
TokenServiceImpl.java 2KB
TokenEntity.java 2KB
YaocaifenleiEntity.java 2KB
MenuEntity.java 2KB
PageUtils.java 2KB
YaocairenzhengxinxiServiceImpl.java 2KB
YaocaigongxiaoServiceImpl.java 2KB
YaocaishuxingServiceImpl.java 2KB
YaocaifenleiServiceImpl.java 2KB
YaocaiziyuanServiceImpl.java 2KB
ZhuanjiaServiceImpl.java 2KB
YonghuServiceImpl.java 2KB
ForumServiceImpl.java 2KB
MenuServiceImpl.java 2KB
ChatServiceImpl.java 2KB
InterceptorConfig.java 1KB
CommonServiceImpl.java 1KB
UsersServiceImpl.java 1KB
UsersEntity.java 1KB
SpringContextUtils.java 1KB
ValidatorUtils.java 1KB
YaocairenzhengxinxiView.java 1KB
SQLFilter.java 1KB
YaocaigongxiaoView.java 1KB
YaocaishuxingView.java 1KB
YaocaiziyuanView.java 1020B
YaocaifenleiView.java 1020B
ZhuanjiaView.java 978B
YonghuView.java 960B
ForumView.java 957B
ChatView.java 948B
MenuView.java 942B
ConfigServiceImpl.java 934B
YaocairenzhengxinxiService.java 916B
YaocairenzhengxinxiDao.java 906B
R.java 887B
YaocaigongxiaoService.java 865B
YaocaishuxingService.java 856B
ConfigEntity.java 854B
YaocaigongxiaoDao.java 850B
共 371 条
- 1
- 2
- 3
- 4
资源评论
老了敲不动了
- 粉丝: 86
- 资源: 4618
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功