Ver Fonte

Merge branch 'master' of http://git.zthymaoyi.com/zyw/tourism

高敬炎 há 2 anos atrás
pai
commit
1f49771bc6

+ 8 - 1
unimall-admin-api/src/main/java/com/iotechn/unimall/admin/api/tourism/IProductManagementService.java

@@ -8,6 +8,7 @@ import com.iotechn.unimall.core.annotation.HttpParam;
 import com.iotechn.unimall.core.annotation.HttpParamType;
 import com.iotechn.unimall.core.annotation.param.NotNull;
 import com.iotechn.unimall.core.exception.ServiceException;
+import com.iotechn.unimall.data.dto.DistinguishView;
 import com.iotechn.unimall.data.model.Page;
 import java.util.Date;
 
@@ -57,7 +58,13 @@ public interface IProductManagementService{
 
 	@HttpMethod(description = "查询", permissionName = "生活服务信息管理")
 	public ProductManagement get(@NotNull @HttpParam(name = "id", type = HttpParamType.COMMON, description = "")Long id)throws ServiceException;
-	
+
+	@HttpMethod(description = "识别身份证",  permissionName = "生活服务信息管理")
+	public DistinguishView personShibie(@HttpParam(name = "personImageFront", type = HttpParamType.COMMON, description = "身份证正面") String personImageFront)throws ServiceException;
+
+	@HttpMethod(description = "语音识别",  permissionName = "证件管理管理")
+	public DistinguishView speechRecognition(@HttpParam(name = "voiceMessage", type = HttpParamType.COMMON, description = "语音") String voiceMessage)throws ServiceException;
+
 	@HttpMethod(description = "导出excl表",  permissionName = "生活服务信息管理")
 	public String export(
 								@HttpParam(name = "commonId", type = HttpParamType.COMMON, description = "个人id") Long commonId,

+ 97 - 3
unimall-admin-api/src/main/java/com/iotechn/unimall/admin/api/tourism/impl/ProductManagementServiceImpl.java

@@ -1,7 +1,20 @@
 package com.iotechn.unimall.admin.api.tourism.impl;
 
-import java.util.List;
+import java.util.*;
 
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.iotechn.unimall.data.dto.DistinguishView;
+import com.iotechn.unimall.data.util.HttpUtils;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.util.EntityUtils;
 import org.apache.ibatis.session.RowBounds;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -15,7 +28,6 @@ import com.iotechn.unimall.data.mapper.ProductManagementMapper;
 import com.iotechn.unimall.data.domain.ProductManagement;
 import com.iotechn.unimall.admin.api.tourism.IProductManagementService;
 import com.iotechn.unimall.data.model.Page;
-import java.util.Date;
 import org.springframework.transaction.annotation.Transactional;
 
 /**
@@ -134,7 +146,89 @@ public class ProductManagementServiceImpl implements IProductManagementService{
 	public ProductManagement get(Long id) throws ServiceException {
 		return productManagementMapper.selectById(id);
 	}
-	
+
+	@Override
+	public DistinguishView personShibie(String personImageFront) throws ServiceException {
+		String appcode = "2d59bfa794994f5f94d1d98b7b5bd102";
+		//API产品路径
+		String requestUrl = "https://personcard.market.alicloudapi.com/ai_market/ai_ocr_universal/shen_fen_zheng/ch/v1";
+		//阿里云APPCODE
+		DistinguishView distinguishView = new DistinguishView();
+		CloseableHttpClient httpClient = null;
+		try {
+			httpClient = HttpClients.createDefault();
+			List<NameValuePair> params = new ArrayList<NameValuePair>();
+			//启用URL方式进行识别
+			//内容数据类型是图像文件URL链接
+			params.add(new BasicNameValuePair("IMAGE", personImageFront));
+			params.add(new BasicNameValuePair("IMAGE_TYPE", "1"));
+
+			// 创建一个HttpPost实例
+			HttpPost httpPost = new HttpPost(requestUrl);
+			httpPost.addHeader("Authorization", "APPCODE " + appcode);
+			httpPost.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
+
+			// 设置请求参数
+			httpPost.setEntity(new UrlEncodedFormEntity(params, "utf-8"));
+
+			// 发送POST请求
+			HttpResponse execute = httpClient.execute(httpPost);
+
+			// 获取状态码
+			int statusCode = execute.getStatusLine().getStatusCode();
+			System.out.println(statusCode);
+
+			// 获取结果
+			HttpEntity entity = execute.getEntity();
+			String body = EntityUtils.toString(entity);
+			System.out.println(body);
+			JSONObject jsonObject = JSONObject.parseObject(body);
+			distinguishView.setRecPersonNo(jsonObject.getJSONObject("身份证识别实体信息").getJSONObject("身份证人像面实体信息").getString("身份证号"));
+			return distinguishView;
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return null;
+	}
+
+	@Override
+	public DistinguishView speechRecognition(String voiceMessage) throws ServiceException {
+		String host = "https://audio.market.alicloudapi.com";
+		String path = "/audioshort";
+		String method = "POST";
+		String appcode = "2d59bfa794994f5f94d1d98b7b5bd102";
+		Map<String, String> headers = new HashMap<String, String>();
+		//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
+		headers.put("Authorization", "APPCODE " + appcode);
+		//根据API的要求,定义相对应的Content-Type
+		headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
+		Map<String, String> querys = new HashMap<String, String>();
+		Map<String, String> bodys = new HashMap<String, String>();
+		bodys.put("format", "m4a");
+		bodys.put("src", voiceMessage);
+		bodys.put("type", "zh-fast");
+		try {
+			HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
+			String body = EntityUtils.toString(response.getEntity());
+			System.out.println(body);
+			JSONObject jsonObject = JSONObject.parseObject(body);
+			JSONArray jsonArray = jsonObject.getJSONArray("msg");
+			DistinguishView distinguishView = new DistinguishView();
+			if(jsonArray!= null && jsonArray.size() >0){
+				String text = jsonArray.getString(0).replace("。","");
+				distinguishView.setText(text);
+				System.out.println(text);
+			}
+			else{
+				distinguishView.setText("未识别成功!");
+			}
+			return distinguishView;
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return null;
+	}
+
 	@Override
 	public String export(Long commonId,String mainBody,String shopNames,String coverImage,String province,String city,String area,String location,String detailedAddress,String serviceDescription,String nickname,String phone,String realname,String personNo,String personImageFront,String personImageBack,String businessLicense,String status,Date gmtCreate,Date gmtUpdate,Long deleteFlag, Integer page, Integer limit)throws ServiceException {
 		Wrapper<ProductManagement> wrapper = new EntityWrapper<ProductManagement>();

+ 3 - 1
unimall-data/src/main/java/com/iotechn/unimall/data/domain/ProductManagement.java

@@ -131,7 +131,9 @@ public class ProductManagement extends SuperDO{
     @Excel(name = "删除标识")
     @TableField("delete_flag")
     private Long deleteFlag;
-
+    /** 语音 */
+    @TableField(exist = false)
+    private String voiceMessage;
 
     @Override
     public String toString() {