219 lines
8.8 KiB
Plaintext
219 lines
8.8 KiB
Plaintext
package com.nationalelectric.greenH5.identityAuth.service;
|
|
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.io.UnsupportedEncodingException;
|
|
import java.nio.charset.Charset;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Date;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.UUID;
|
|
|
|
import org.apache.http.client.ClientProtocolException;
|
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
import org.apache.http.client.methods.HttpPost;
|
|
import org.apache.http.entity.mime.MultipartEntity;
|
|
import org.apache.http.entity.mime.content.FileBody;
|
|
import org.apache.http.entity.mime.content.StringBody;
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
import org.apache.http.impl.client.HttpClients;
|
|
import org.apache.http.util.EntityUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import com.jysoft.weChat.service.WechatService;
|
|
import com.jysoft.weChat.vo.ContentVo;
|
|
import com.nationalelectirc.Constant.Constant;
|
|
import com.nationalelectric.greenH5.bizc.BaseServiceImpl;
|
|
import com.nationalelectric.greenH5.bizc.GreenUserInfoBizc;
|
|
import com.nationalelectric.greenH5.bizc.IGreenApplyListBizc;
|
|
import com.nationalelectric.greenH5.bizc.IGreenUserInfoBizc;
|
|
import com.nationalelectric.greenH5.identityAuth.util.Const;
|
|
import com.nationalelectric.greenH5.identityAuth.util.PhotoUtil;
|
|
import com.nationalelectric.greenH5.identityAuth.util.SignGenerater;
|
|
import com.nationalelectric.greenH5.po.GreenApplyList;
|
|
import com.nationalelectric.greenH5.po.GreenUserInfo;
|
|
import com.nationalelectric.greenH5.po.GreenVisitorRetinueInfo;
|
|
import com.sgcc.uap.persistence.IHibernateDao;
|
|
|
|
import net.sf.json.JSONObject;
|
|
|
|
@Service
|
|
public class IdentityAuthService {
|
|
|
|
@Autowired
|
|
private IHibernateDao iHibernateDao;
|
|
|
|
@Autowired
|
|
private WechatService wService;
|
|
|
|
@Autowired
|
|
private IGreenApplyListBizc greenApplyListBizc;
|
|
|
|
@Autowired
|
|
private BaseServiceImpl baseService;
|
|
@Autowired
|
|
IHibernateDao hibernateDao;
|
|
@Autowired
|
|
private IGreenUserInfoBizc greenUserInfoBizc;
|
|
/**
|
|
*
|
|
* @param userInfo
|
|
* 申请人
|
|
* @param userId
|
|
* 被访人
|
|
* @param openId
|
|
* 被访人
|
|
* @param idNo
|
|
* 被访人
|
|
* @param picPath
|
|
* 压缩后文件地址
|
|
* @param startTime
|
|
* 访问开始时间
|
|
* @param aList
|
|
* 申请记录
|
|
*/
|
|
// @Async
|
|
public void auth(GreenUserInfo userInfo, String userId, String openId, String idNo, String picPath,
|
|
String startTime, GreenApplyList aList,GreenVisitorRetinueInfo greenVisitorRetinueInfo) {
|
|
|
|
// 人脸比对开关
|
|
List<Map<String, String>> list = baseService.getDictionaryInfo("identityAuth", "identityAuth");
|
|
String dataValue = list.get(0).get("data_Value");
|
|
String name = userInfo.getRealName();
|
|
//String
|
|
//if(name.equals(userInfoQ.)){}
|
|
|
|
|
|
if ("1".equals(dataValue) && name != null && !"".equals(name) && idNo != null && !"".equals(idNo)
|
|
) { //&& picPath != null && !"".equals(picPath)
|
|
System.out.println("进入人脸比对------");
|
|
String sign = SignGenerater.getSign(name, idNo);
|
|
// 创建默认的HttpClient
|
|
CloseableHttpClient httpclient = HttpClients.createDefault();
|
|
HttpPost request = new HttpPost(Const.ID_AUTH_URL);
|
|
MultipartEntity reqEntity = new MultipartEntity();
|
|
String resp = "";
|
|
try {
|
|
|
|
String picPaths[] = picPath.split("\\.");
|
|
String ysPicPath = picPaths[0]+"ys."+picPaths[1];
|
|
|
|
// picPath = "D:/examfile/1.jpg";
|
|
// String ysPicPath = "D:/examfile/123.jpg";
|
|
|
|
byte[] imgBytes = PhotoUtil.getByteByPic(picPath);
|
|
byte[] resultImg = PhotoUtil.compressUnderSize(imgBytes,10 * 1024);
|
|
PhotoUtil.byte2image(resultImg,ysPicPath);
|
|
|
|
reqEntity.addPart("appId", new StringBody(Const.ID_AUTH_APPID, Charset.forName("UTF-8")));
|
|
reqEntity.addPart("name", new StringBody(name, Charset.forName("UTF-8")));
|
|
reqEntity.addPart("idNo", new StringBody(idNo, Charset.forName("UTF-8")));
|
|
reqEntity.addPart("mode", new StringBody("8", Charset.forName("UTF-8")));
|
|
reqEntity.addPart("signatureType", new StringBody("MD5", Charset.forName("UTF-8")));
|
|
reqEntity.addPart("signature", new StringBody(sign, Charset.forName("UTF-8")));
|
|
reqEntity.addPart("photo", new FileBody(new File(ysPicPath)));
|
|
request.setEntity(reqEntity);
|
|
CloseableHttpResponse response = httpclient.execute(request);
|
|
resp = EntityUtils.toString(response.getEntity(), "UTF-8");
|
|
|
|
JSONObject jsonObject = JSONObject.fromObject(resp);
|
|
System.out.println(jsonObject);
|
|
Boolean success = jsonObject.getBoolean("success");
|
|
long code = jsonObject.getLong("code");
|
|
Boolean identical = false;
|
|
// // //判断被访人是否是本人 --- 变为待处理状态
|
|
// if (userId.equals(userInfo.getId())) {
|
|
// aList.setFirstStatus("3");
|
|
// aList.setCurrentStatus("13");
|
|
// } else {
|
|
// aList.setFirstStatus("0");
|
|
// aList.setCurrentStatus("10");
|
|
// }
|
|
if(success && code == 0 ){
|
|
JSONObject jsonObject2 = jsonObject.getJSONObject("data");
|
|
identical = jsonObject2.getBoolean("identical");
|
|
if (identical) {
|
|
System.out.println("身份验证成功");
|
|
aList.setIdentityAuth("1");
|
|
|
|
|
|
// 推送消息 给 审核人审核
|
|
// Map<String, ContentVo> data = new HashMap<String, ContentVo>();
|
|
// data.put("first", new ContentVo("您好,您有一条访客信息需处理", "#173177"));
|
|
// data.put("keyword1", new ContentVo(userInfo.getRealName(), "#black"));
|
|
// data.put("keyword2", new ContentVo(userInfo.getGender(), "#black"));
|
|
// data.put("keyword3", new ContentVo(userInfo.getMobile(), "#black"));
|
|
// data.put("keyword4", new ContentVo(userInfo.getOrgName(), "#black"));
|
|
// data.put("keyword5", new ContentVo(startTime, "#black"));
|
|
// data.put("remark", new ContentVo("请您至\"指尖上的后勤\"微信公众号审核确认", "#173177"));
|
|
// wService.publishMsg(data, openId, 1);
|
|
} else {
|
|
System.out.println("身份验证失败");
|
|
aList.setIdentityAuth("0"); // 身份验证失败
|
|
|
|
// 推送消息 给 申请人 身份验证失败
|
|
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
|
// Map<String, ContentVo> dataMap = new HashMap<String, ContentVo>();
|
|
// dataMap.put("first", new ContentVo("尊敬的用户,您的访客预约审核结果已出", "#173177"));
|
|
// dataMap.put("keyword1", new ContentVo("身份验证失败", "#black"));
|
|
// dataMap.put("keyword2", new ContentVo(sdf.format(new Date()), "#black"));
|
|
// dataMap.put("remark", new ContentVo("感谢您的参于与支持", "#173177"));
|
|
// wService.publishMsg(dataMap, userInfo.getWxOpenId(), 2);
|
|
}
|
|
}else {
|
|
System.out.println("身份验证失败");
|
|
aList.setIdentityAuth("0"); // 身份验证失败
|
|
|
|
// 推送消息 给 申请人 身份验证失败
|
|
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
|
// Map<String, ContentVo> dataMap = new HashMap<String, ContentVo>();
|
|
// dataMap.put("first", new ContentVo("尊敬的用户,您的访客预约审核结果已出", "#173177"));
|
|
// dataMap.put("keyword1", new ContentVo("身份验证失败", "#black"));
|
|
// dataMap.put("keyword2", new ContentVo(sdf.format(new Date()), "#black"));
|
|
// dataMap.put("remark", new ContentVo("感谢您的参于与支持", "#173177"));
|
|
// wService.publishMsg(dataMap, userInfo.getWxOpenId(), 2);
|
|
}
|
|
|
|
aList.setApplyInfo3(resp);
|
|
greenApplyListBizc.update(aList, aList.getId());
|
|
String realName = userInfo.getRealName();
|
|
String reqName = greenVisitorRetinueInfo.getVisitorName();
|
|
if(realName.equals(reqName)){
|
|
String identityAuthStr = identical?"1":"0";
|
|
userInfo.setIdentityAuth(identityAuthStr);
|
|
String facepic1 = greenVisitorRetinueInfo.getFacePic1() == null ? "" : greenVisitorRetinueInfo.getFacePic1();
|
|
if(!"".equals(facepic1)){
|
|
if(facepic1.indexOf("http")!=-1){
|
|
|
|
}else{
|
|
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMdd");
|
|
String date = sdf1.format(new Date()) + "/";
|
|
String uuid = date + UUID.randomUUID().toString().replaceAll("-","");
|
|
baseService.saveImgToIO(uuid+Constant.IMG_SUFFIX, facepic1);
|
|
String picture = uuid+Constant.IMG_SUFFIX;
|
|
String pictureData = uuid;
|
|
userInfo.setFacePic1(picture);
|
|
userInfo.setFacePic1Data(pictureData);
|
|
}
|
|
}
|
|
userInfo.setIdCard(greenVisitorRetinueInfo.getIdcard());
|
|
greenUserInfoBizc.update(userInfo, userInfo.getId());
|
|
}
|
|
|
|
} catch (UnsupportedEncodingException e1) {
|
|
e1.printStackTrace();
|
|
} catch (ClientProtocolException e2) {
|
|
e2.printStackTrace();
|
|
} catch (IOException e3) {
|
|
e3.printStackTrace();
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|