Commit 32bf4407 authored by mengmeng's avatar mengmeng

Merge branch 'lings' into 'master'

浙里办等

See merge request !3
parents 1282ba88 ecbfe5ad
......@@ -17,6 +17,23 @@
<artifactId>hmit-common</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.60</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
</dependencies>
<build>
......
package io.hmit.config;
public class ZhelibanAPP {
// 获取请求app_secret的地址
public static final String APP_REQUEST_SECRET_URL = "http://10.68.138.194/gateway/app/refreshTokenByKey.htm";
public static final String APP_KEY = "6465b05327cc4a41897907bf81382c29";
public static final String APP_SECRET = "fe07f9be363c46449ffae97ae2ad2bda";
public static final String SIGN = "";
public static final String APP_ID = "4438763045";
public static final String APP_KEY_T = "249f09c69fe38bf51fe73976cbed2ead";
public static final String TOKEN_URL = "";
public static final String BASE_URL = "http://a.com/";
public static final String AUTH_LOGIN_URL = BASE_URL + "";
public static final String PUSH_MESSAGE_SIMPLE = BASE_URL + "";
public static final String GET_USER_INFO_BY_MOBILE = BASE_URL + "";
public static final String COMMIT_DATA = BASE_URL + "";
//手机
public static final String SERVICE_CODE = "blzwfwyyqhxt";
public static final String SERVICE_PASS = "blzwfwyyqhxtpwd";
// public static final String APP_BASE_URL = "https://puser.zjzwfw.gov.cn/sso/servlet/simpleauth?method=";
public static final String APP_BASE_URL = "https://appapi.zjzwfw.gov.cn/sso/servlet/simpleauth?method=";
public static final String VALIDATION_TICKET = "ticketValidation";
public static final String USER_INFO = "getUserInfo";
}
package io.hmit.config;
import io.hmit.common.utils.DateUtils;
import net.sf.json.JSONObject;
import com.google.gson.*;
import com.google.gson.reflect.TypeToken;
import io.hmit.common.utils.HttpRequestUtil;
import io.hmit.common.utils.MD5;
import org.apache.commons.lang3.StringEscapeUtils;
import org.slf4j.LoggerFactory;
import javax.net.ssl.*;
import java.io.*;
import java.lang.reflect.Type;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;
import java.text.MessageFormat;
import java.util.*;
public class ZhelibanUtils {
private static org.slf4j.Logger logger = LoggerFactory.getLogger(ZhelibanAPP.class);
private final static HostnameVerifier DO_NOT_VERIFY = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
};
private static Gson gson = new GsonBuilder()
.registerTypeAdapter(
new TypeToken<Map<String, Object>>() {
}.getType(),
new JsonDeserializer<Map<String, Object>>() {
@Override
public Map<String, Object> deserialize(
JsonElement json, Type typeOfT,
JsonDeserializationContext context) throws JsonParseException {
Map<String, Object> treeMap = new HashMap<String, Object>();
JsonObject jsonObject = json.getAsJsonObject();
Set<Map.Entry<String, JsonElement>> entrySet = jsonObject.entrySet();
for (Map.Entry<String, JsonElement> entry : entrySet) {
treeMap.put(entry.getKey(), entry.getValue());
}
return treeMap;
}
}).create();
public static JSONObject HttpRequest(String request , String RequestMethod , String output, String type, Map<String, Object> headParam ){
@SuppressWarnings("unused")
JSONObject jsonObject = null;
StringBuffer buffer = new StringBuffer();
try {
//建立连接
//trustAllHosts();//HTTPS请求需建立信任链接
URL url = new URL(request);
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
if(RequestMethod.equals("POST")) {
connection.setDoOutput(true);
}
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setRequestMethod(RequestMethod);
connection.setHostnameVerifier(DO_NOT_VERIFY);
//一定要设置 Content-Type 要不然服务端接收不到参数
setHeaderParam(connection,type,headParam);
connection.setRequestProperty("Content-Type", "application/Json; charset=UTF-8");
if(output != null){
OutputStream out = connection.getOutputStream();
out.write(output.getBytes("UTF-8"));
out.close();
}
//流处理
InputStream input = connection.getInputStream();
InputStreamReader inputReader = new InputStreamReader(input,"UTF-8");
BufferedReader reader = new BufferedReader(inputReader);
String line;
while((line=reader.readLine())!=null){
buffer.append(line);
}
//关闭连接、释放资源
reader.close();
inputReader.close();
input.close();
input = null;
connection.disconnect();
logger.info(buffer.toString());
jsonObject = JSONObject.fromObject(buffer.toString());
} catch (Exception e) {
e.printStackTrace();
}
return jsonObject;
}
public static Map<String, Object> getAccessToken() throws UnsupportedEncodingException, NoSuchAlgorithmException {
Long current_time = System.currentTimeMillis();
Map<String, Object> map = null ;
String para = "requestKey="+ZhelibanAPP.APP_KEY+"&requestTime="+current_time+"&sign="+ MD5.md5(ZhelibanAPP.APP_KEY+ZhelibanAPP.APP_SECRET+current_time);
System.out.println(para);
// Map<String, Object> map_result = HttpRequestUtil.sendPost(ZhelibanAPP.TOKEN_URL, para,false,false);
Map<String, Object> map_result = new HashMap<>();
String sp = new Gson().toJson(map_result);
if (null != sp && !"".equals(sp) ) {
try {
map = new Gson().fromJson(sp,new TypeToken<Map<String, Object>>() {
}.getType());
if (map.get("result").toString().equals("00")){ //获取成功
map.put("accessToken",map.get("resultmsg"));
} else {
logger.info("获取token失败:错误代码--"+map.get("result")+",错误原因--"+map.get("resultmsg"));
}
logger.info("获取token成功:"+map.get("resultmsg"));
} catch (Exception e) {
e.printStackTrace();
logger.error("获取token异常!!");
}
}
System.out.println(map);
return map;
}
public static Map<String, Object> getUserInfo(Map<String, Object> map) {
Map<String, Object> result_map = ZhelibanUtils.getAppToken(map);
String current_time = DateUtils.format(new Date(),"yyyyMMddHHmmss");
if (result_map !=null){
System.out.println(result_map);
if ("0".equals(result_map.get("result").toString())){
String params_vailidation = "&servicecode="+ZhelibanAPP.SERVICE_CODE+"&time="+current_time+"&sign="+MD5.md5(ZhelibanAPP.SERVICE_CODE+ZhelibanAPP.SERVICE_PASS+current_time)+"&token="+result_map.get("token").toString()+"&datatype=json";
String user_result = HttpRequestUtil.sendZlbGet(ZhelibanAPP.APP_BASE_URL+ZhelibanAPP.USER_INFO,params_vailidation);
return new Gson().fromJson(user_result,new TypeToken<Map<String, Object>>() {
}.getType());
}else {
return result_map;
}
}
return null;
}
public static Map<String, Object> getRootUserInfo(Map<String, Object> map) {
Long current_time = System.currentTimeMillis();
String params_vailidation = "token="+map.get("ssotoken").toString();
String user_result = "sssss";
// String user_result = HttpRequestUtil.sendHeaderPost(ZhelibanAPP.ROOT_USER_INFO,params_vailidation,false,false);
System.out.println("111 "+user_result);
return new Gson().fromJson(user_result,new TypeToken<Map<String, Object>>() {
}.getType());
}
/***
* 向指定URL发送POST方法的请求
*
* @param apiUrl
* @param data
* @param headers
* @return
*/
public static JSONObject sendPOST(String apiUrl, String data, LinkedHashMap<String, String> headers) {
StringBuffer strBuffer = null;
String result = null;
JSONObject jsonObj = null;
try {
// 建立连接
URL url = new URL(apiUrl);
/* 获取客户端向服务器端传送数据所依据的协议名称 */
String protocol = url.getProtocol();
if ("https".equalsIgnoreCase(protocol)) {
/* 获取HTTPS请求的SSL证书 */
try {
// SSLUtils.ignoreSsl();
} catch (Exception e) {
e.printStackTrace();
}
}
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
// 需要输出
httpURLConnection.setDoOutput(true);
// 需要输入
httpURLConnection.setDoInput(true);
// 不允许缓存
httpURLConnection.setUseCaches(false);
httpURLConnection.setRequestMethod("POST");
// 设置Headers
if (null != headers) {
for (String key : headers.keySet()) {
httpURLConnection.setRequestProperty(key, headers.get(key));
}
}
// 连接会话
httpURLConnection.connect();
// 建立输入流,向指向的URL传入参数
DataOutputStream dos = new DataOutputStream(httpURLConnection.getOutputStream());
// 设置请求参数
dos.write(data.getBytes("UTF-8"));
dos.flush();
dos.close();
// 获得响应状态
int http_StatusCode = httpURLConnection.getResponseCode();
String http_ResponseMessage = httpURLConnection.getResponseMessage();
if (HttpURLConnection.HTTP_OK == http_StatusCode) {
strBuffer = new StringBuffer();
String readLine = new String();
BufferedReader responseReader = new BufferedReader(
new InputStreamReader(httpURLConnection.getInputStream(), "UTF-8"));
while ((readLine = responseReader.readLine()) != null) {
strBuffer.append(readLine);
}
responseReader.close();
result = strBuffer.toString();
if (null == result || result.length() == 0) {
throw new Exception("获取企业(法人)信息失败");
} else {
jsonObj = JSONObject.fromObject(result);
}
} else {
throw new Exception(
MessageFormat.format("请求失败,失败原因: Http状态码 = {0} , {1}", http_StatusCode, http_ResponseMessage));
}
// 断开连接
httpURLConnection.disconnect();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return jsonObj;
}
public static Map<String, Object> getAppToken(Map<String, Object> map) {
// String current_time = DateUtils.getCurrentTimes();
String current_time = DateUtils.format(new Date(),"yyyyMMddHHmmss");
String params_vailidation = "&servicecode="+ZhelibanAPP.SERVICE_CODE+"&time="+current_time+"&sign="+MD5.md5(ZhelibanAPP.SERVICE_CODE+ZhelibanAPP.SERVICE_PASS+current_time)+"&st="+map.get("ticket").toString()+"&datatype=json";
String valid_result = HttpRequestUtil.sendZlbGet(ZhelibanAPP.APP_BASE_URL+ZhelibanAPP.VALIDATION_TICKET,params_vailidation);
return new Gson().fromJson(valid_result,new TypeToken<Map<String, Object>>() {
}.getType());
}
public static Map<String, Object> getAAccessToken() {
JSONObject jsonObject = HttpRequest(ZhelibanAPP.TOKEN_URL, "GET", null,"AccessToken",null);
String accessToken = null;
String expireTime = null;
Map<String, Object> map = null;
// 如果请求成功
if (null != jsonObject) {
try {
if (jsonObject.getString("status").equals("0")){ //获取成功
map = new HashMap<String, Object>();
JSONObject tokenObject = jsonObject.getJSONObject("data");
accessToken = tokenObject.getString("accessToken");
expireTime = tokenObject.getString("expireTime");
map.put("accessToken",accessToken);
map.put("expireTime",expireTime);
} else {
logger.info("获取token失败:错误代码--"+jsonObject.getString("status")+",错误原因--"+jsonObject.getString("message"));
}
logger.info("获取token成功:"+accessToken+",过期时间:"+expireTime);
} catch (Exception e) {
e.printStackTrace();
logger.error("获取token异常!!");
}
}
return map;
}
public static HttpURLConnection setHeaderParam(HttpURLConnection connection, String type, Map<String, Object> headParam) {
if (type.equals("AccessToken")) {
connection.setRequestProperty("appId", ZhelibanAPP.APP_ID);
connection.setRequestProperty("appSecret", ZhelibanAPP.APP_SECRET);
} else if (type.equals("authlogin")) {
connection.setRequestProperty("accessToken", headParam.get("accessToken").toString());
connection.setRequestProperty("token", headParam.get("token").toString());
} else if (type.equals("pushMessage")) {
connection.setRequestProperty("accessToken", headParam.get("accessToken").toString());
connection.setRequestProperty("orgSecret", headParam.get("orgSecret").toString());
//connection.setRequestProperty("uid", headParam.get("uid").toString());
} else if (type.equals("getUserInfoByMobile")) {
connection.setRequestProperty("accessToken", headParam.get("accessToken").toString());
connection.setRequestProperty("orgSecret", headParam.get("orgSecret").toString());
}
return connection;
}
private static void trustAllHosts() {
// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[]{};
}
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) {
}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) {
}
}};
// Install the all-trusting trust manager
try {
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (Exception e) {
e.printStackTrace();
}
}
public static Map<String, Object> authLogin(String accessToken, String token) {
Map<String, Object> headParam = new HashMap<String, Object>();
Map<String, Object> result = null;
headParam.put("accessToken",accessToken);
headParam.put("token",token);
logger.info("auth login");
try{
JSONObject jsonObject = HttpRequest(ZhelibanAPP.AUTH_LOGIN_URL, "GET", null,"authlogin",headParam);
if (jsonObject != null && jsonObject.getString("status").equals("0")) {
logger.info("免登授权请求成功");
result = new HashMap<String, Object>();
JSONObject userInfo = jsonObject.getJSONObject("data");
result.put("uid",userInfo.getString("uid"));
result.put("mobile",userInfo.getString("mobile"));
result.put("name",userInfo.getString("name"));
result.put("orgSecret",userInfo.getString("orgSecret"));
} else {
logger.info("无返回值");
return null;
}
} catch (Exception e) {
e.printStackTrace();
logger.error("免登授权请求失败!");
}
return result;
}
public static Map<String, Object> pushMessage(String accessToken, String orgSecret, String uid, String queryParam) {
Map<String, Object> headParam = new HashMap<String, Object>();
Map<String, Object> result = null;
headParam.put("accessToken",accessToken);
headParam.put("orgSecret",orgSecret);
headParam.put("uid",uid);
logger.info("pushMessage start!!");
try{
JSONObject jsonObject = HttpRequest(ZhelibanAPP.PUSH_MESSAGE_SIMPLE, "POST", queryParam,"pushMessage",headParam);
if (jsonObject != null && jsonObject.getString("status").equals("0")) {
logger.info("消息推送成功");
result = new HashMap<String, Object>();
result.put("status",jsonObject.getString("status"));
result.put("success",jsonObject.getString("success"));
} else {
logger.info("消息推送失败");
}
} catch (Exception e) {
e.printStackTrace();
logger.error("消息推送失败!");
}
return result;
}
public static Map<String, Object> getUserInfoByMobile(String accessToken, String orgSecret, String mobile) {
Map<String, Object> headParam = new HashMap<String, Object>();
Map<String, Object> result = null;
headParam.put("accessToken",accessToken);
headParam.put("orgSecret",orgSecret);
headParam.put("mobile",mobile);
logger.info("getUserInfoByMobile start!!");
try{
JSONObject jsonObject = HttpRequestGetUserInfoByMobile(ZhelibanAPP.GET_USER_INFO_BY_MOBILE,headParam,"getUserInfoByMobile");
if (jsonObject != null && jsonObject.getString("status").equals("0")) {
logger.info("获取用户信息成功");
result = new HashMap<String, Object>();
JSONObject userInfo = jsonObject.getJSONObject("data");
result.put("uid",userInfo.getString("uid"));
result.put("name",userInfo.getString("name"));
} else {
logger.info("获取用户信息失败!");
}
} catch (Exception e) {
e.printStackTrace();
logger.error("获取用户信息失败!");
}
return result;
}
public static JSONObject HttpRequestGetUserInfoByMobile(String request , Map<String, Object> headParam, String type ){
JSONObject jsonObject = null;
StringBuffer buffer = new StringBuffer();
try {
//建立连接
trustAllHosts();//HTTPS请求需建立信任链接
URL url = new URL(request+"?"+"mobile="+headParam.get("mobile").toString());
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setUseCaches(false);
setHeaderParam(connection,type,headParam);
connection.setHostnameVerifier(DO_NOT_VERIFY);
//流处理
InputStream input = connection.getInputStream();
InputStreamReader inputReader = new InputStreamReader(input,"UTF-8");
BufferedReader reader = new BufferedReader(inputReader);
String line;
while((line=reader.readLine())!=null){
buffer.append(line);
}
//关闭连接、释放资源
reader.close();
inputReader.close();
input.close();
input = null;
connection.disconnect();
logger.info(buffer.toString());
jsonObject = JSONObject.fromObject(buffer.toString());
} catch (Exception e) {
e.printStackTrace();
}
return jsonObject;
}
private static String getUtf8Url(String url) {
char[] chars = url.toCharArray();
StringBuilder utf8Url = new StringBuilder();
final int charCount = chars.length;
for (int i = 0; i < charCount; i++) {
byte[] bytes = ("" + chars[i]).getBytes();
if (bytes.length == 1) {
utf8Url.append(chars[i]);
}else{
try {
utf8Url.append(URLEncoder.encode(String.valueOf(chars[i]), "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}
return utf8Url.toString();
}
private static String toUTF(String inStr) throws UnsupportedEncodingException {
String outStr = "";
if (inStr != null) {
outStr = new String(inStr.getBytes("iso-8859-1"), "UTF-8");
}
return outStr;
}
/**
* 汉字 转换为对应的 UTF-8编码
* @param s 木
* @return E69CA8
*/
public static String convertStringToUTF8(String s) {
if (s == null || s.equals("")) {
return null;
}
StringBuffer sb = new StringBuffer();
try {
char c;
for (int i = 0; i < s.length(); i++) {
c = s.charAt(i);
if (c >= 0 && c <= 255) {
sb.append(c);
} else {
byte[] b;
b = Character.toString(c).getBytes("utf-8");
for (int j = 0; j < b.length; j++) {
int k = b[j];
//转换为unsigned integer 无符号integer
/*if (k < 0)
k += 256;*/
k = k < 0 ? k + 256 : k;
//返回整数参数的字符串表示形式 作为十六进制(base16)中的无符号整数
//该值以十六进制(base16)转换为ASCII数字的字符串
sb.append(Integer.toHexString(k).toUpperCase());
// url转置形式
// sb.append("%" +Integer.toHexString(k).toUpperCase());
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return sb.toString();
}
/**
* 可将中文转换成 "&#" 开头的html实体编码
*
*
* @param str
* @return*/
public static String encodeS(String str) {
char[] arrs = str.toCharArray();//Hex.encodeHex();
StringBuilder sb = new StringBuilder();
for (char c : arrs) {
// \\u 表示Unicode编码。
if (c >= '\u2E80' && c <= '\uFE4F') {// [ 只是中文一般 [ \u4e00-\u9fa5];中日韩统一表意文字(CJK Unified Ideographs) [\u2E80-\uFE4F]
sb.append("&#x").append((int)c).append(";");
} else {
sb.append(c);
}
}
return sb.toString();
}
public static String ZH(String str) {
String[] string = str.split("u");
System.out.println(new Gson().toJson(string));
return "111";
}
public static void main(String[] args) throws UnsupportedEncodingException, NoSuchAlgorithmException {
System.out.println(StringEscapeUtils.escapeJava("String"));
}
}
package io.hmit.controller;
import com.baomidou.mybatisplus.extension.api.R;
import io.hmit.annotation.Login;
import io.hmit.common.constant.Constant;
import io.hmit.common.utils.Result;
import io.hmit.common.validator.ValidatorUtils;
import io.hmit.config.ZhelibanUtils;
import io.hmit.dto.LoginDTO;
import io.hmit.entity.TokenEntity;
import io.hmit.entity.UserEntity;
import io.hmit.service.TokenService;
import io.hmit.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/**
* 登录接口
......@@ -53,4 +66,50 @@ public class ApiLoginController {
return new Result();
}
//个人登录 - 单点登陆
@RequestMapping(value="/check_user")
@ApiOperation("单点登录")
@ApiImplicitParams({
@ApiImplicitParam(name = "ticket", value = "票据", paramType = "query", required = true, dataType="String") ,
})
public Result checkUser(@ApiIgnore @RequestParam Map<String,Object> map , HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {
// 获取到票据信息ticket
System.out.println("开始进入这个checkuser了————————————————————");
System.out.println(map);
Long userId;
Map<String, Object> userMap = new HashMap<>();
if(map.get("ticket") != null){
System.out.println("Ticket 是"+map.get("ticket")+"——————————————————————");
Map<String,Object> user_map = ZhelibanUtils.getUserInfo(map);
System.out.println("UserMap是——————————————————————————————");
System.out.println(user_map);
if (user_map.get("idnum") !=null){
//判断是否已经存在了这条信息
UserEntity oldUser=userService.queryByIdnum(URLEncoder.encode(user_map.get("idnum").toString(), "UTF8"));
if(oldUser==null){
//将获得的信息保存到个人登陆表
UserEntity user=new UserEntity();
user.setUsername(user_map.get("username").toString());
user.setMobile(URLEncoder.encode(user_map.get("mobile").toString(), "UTF8"));
user.setPassword(URLEncoder.encode(user_map.get("idnum").toString(), "UTF8"));
user.setIdCardNo(URLEncoder.encode(user_map.get("idnum").toString(), "UTF8"));
userService.insert(user);
userId = user.getId();
}else{
userId = oldUser.getId();
}
TokenEntity tokenEntity = tokenService.createToken(userId);
userMap.put("token", tokenEntity.getToken());
userMap.put("expire", tokenEntity.getExpireDate().getTime() - System.currentTimeMillis());
}
return new Result().ok(userMap);
}else{
return new Result().error("票据信息为空");
}
}
}
package io.hmit.modules.appointment.controller;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonObject;
import io.hmit.annotation.LoginUser;
import io.hmit.common.constant.Constant;
import io.hmit.common.page.PageData;
import io.hmit.common.utils.ConvertUtils;
import io.hmit.common.utils.DateUtils;
import io.hmit.common.utils.HttpRequestUtil;
import io.hmit.common.utils.MD5;
import io.hmit.common.utils.Result;
import io.hmit.common.validator.AssertUtils;
import io.hmit.common.validator.ValidatorUtils;
import io.hmit.common.validator.group.AddGroup;
import io.hmit.common.validator.group.DefaultGroup;
import io.hmit.common.validator.group.UpdateGroup;
import io.hmit.entity.UserEntity;
import io.hmit.modules.appointment.dto.*;
import io.hmit.modules.appointment.entity.AppointmentOrderEntity;
import io.hmit.modules.appointment.service.AppointmentOrderService;
......@@ -19,7 +25,9 @@ import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import springfox.documentation.annotations.ApiIgnore;
import java.util.Arrays;
......@@ -50,10 +58,19 @@ public class AppointmentOrderController {
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码,从1开始", paramType = "query", required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") ,
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String")
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String"),
@ApiImplicitParam(name = "appointmentIdCard", value = "预约人身份证", paramType = "query", dataType="String"),
@ApiImplicitParam(name = "appointmentPhone", value = "预约人电话", paramType = "query", dataType="String")
})
public Result<PageData<AppointmentOrderDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
PageData<AppointmentOrderDTO> page = appointmentOrderService.page(params);
page.getList().forEach(l->{
//判断已取号或者消除过号
if(null!=l.getStatus() &&(2==l.getStatus() ||4==l.getStatus()) ){
YynumberDTO yynumberDTO = appointmentOrderService.findByYuNumber(l.getAppointmentNum());
l.setYynumberDTO(yynumberDTO);
}
});
return new Result<PageData<AppointmentOrderDTO>>().ok(page);
}
......@@ -62,7 +79,9 @@ public class AppointmentOrderController {
@ApiOperation("信息,预约详情接口")
public Result<AppointmentOrderDTO> get(@PathVariable("id") Long id){
AppointmentOrderDTO data = appointmentOrderService.get(id);
if(null!=data.getStatus() &&(2==data.getStatus() ||4==data.getStatus()) ) {
data.setYynumberDTO(appointmentOrderService.findByYuNumber(data.getAppointmentNum()));
}
return new Result<AppointmentOrderDTO>().ok(data);
}
......@@ -134,15 +153,51 @@ public class AppointmentOrderController {
return new Result();
}
/*
@GetMapping("/deleteOverNum/{id}")
@ApiOperation("消除过号")
public Result deleteOverNum(@PathVariable("id") Long id,@ApiIgnore @LoginUser UserEntity user){
AppointmentOrderDTO data = appointmentOrderService.get(id);
data.setStatus(4);
data.setStatusName("已消除过号");
data.setUpdateDate(new Date());
data.setUpdater(user.getId());
appointmentOrderService.update(data);
return new Result();
}
@GetMapping(value = "/signin/{appointmentOrderId}")
@ApiOperation("签到")
public Result signin(@PathVariable(value = "appointmentOrderId") Long appointmentOrderId){
//根据appointmentOrderId获取到订单实体
AppointmentOrderDTO appointmentOrderDTO = appointmentOrderService.get(appointmentOrderId);
String appointmentIdCard = appointmentOrderDTO.getAppointmentIdCard();
String appointmentPhone = appointmentOrderDTO.getAppointmentPhone();
String serviceId = appointmentOrderDTO.getServiceId().toString();
String appointmentPerson = appointmentOrderDTO.getAppointmentPerson();
String sign = "hjfhsdjfueytRwYSdsa%hdf^jdshfh*KGh$e"+serviceId+new Date().getTime();
//判断签到时间是否在预约时间前
if (appointmentOrderDTO.getAppointmentTime().getTime() > new Date().getTime()) {
//调用取号机取号接口,获取取号信息,并更新预约号。
// http://IP:8223/smartqueue/yynumber?sQueueInfoID=24&time=1613389800&sign=ee2c3fc1bdabf439f00aa90af6a0a68f&sTel=13988888888&sName=王小二&sCardID=333111123456
String url = "http://IP:8223/smartqueue/yynumber?" +
"sQueueInfoID=" +serviceId+
"&time="+ new Date().getTime()+
"&sign="+ MD5.md5(sign)+
"&sTel="+ appointmentPhone+
"&sName="+appointmentPerson+
"&sCardID="+appointmentIdCard;
String s = HttpRequestUtil.sendGetAndRetrieveContent(url);
YynumberDTO yynumberDTO = JSONObject.parseObject(s,YynumberDTO.class);
//根据接口返回的结果更新预约单号
if("0".equals(yynumberDTO.getNStatus())){
appointmentOrderDTO.setAppointmentNum(yynumberDTO.getSPaperNumber());
appointmentOrderDTO.setTicketDate(yynumberDTO.getSRegTime());
appointmentOrderDTO.setWaitNum(yynumberDTO.getNWait());
appointmentOrderDTO.setServiceWindow(yynumberDTO.getListWin().toString());
appointmentOrderDTO.setStatus(2);
appointmentOrderDTO.setStatusName("签到");
appointmentOrderDTO.setUpdateDate(new Date());
......@@ -150,22 +205,10 @@ public class AppointmentOrderController {
return new Result();
}else{
return new Result().error("预约时间已过,签到失败!");
return new Result().error(yynumberDTO.getSMsg());
}
}
@GetMapping(value = "/waitingNum/{appointmentOrderId}")
@ApiOperation("获取当前预约的排队人数")
public Result waitingNum (@PathVariable(value = "appointmentOrderId") Long appointmentOrderId){
//根据appointmentOrderId获取到订单实体
AppointmentOrderDTO appointmentOrderDTO = appointmentOrderService.get(appointmentOrderId);
//获取当前订单预约时间
Integer waitingNum = appointmentOrderService.waitingNum(DateUtils.format(appointmentOrderDTO.getAppointmentTime()));
return new Result().ok(waitingNum);
}*/
@GetMapping(value = "/serviceWaitingNum/{serviceId}")
@ApiOperation("获取当前事项的预约排队人数")
......@@ -202,4 +245,6 @@ public class AppointmentOrderController {
return new Result();
}
}
......@@ -93,6 +93,8 @@ public class AppointmentOrderDTO implements Serializable {
@ApiModelProperty(value = "等候人数")
private Integer waitNum;
private YynumberDTO yynumberDTO;
public AppointmentOrderDTO assembleAppointmentOrderDTO(ReservationDTO reservationDTO){
AppointmentOrderDTO dto = new AppointmentOrderDTO();
......
package io.hmit.modules.appointment.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
@Data
@ApiModel(value = "取号后的号码信息")
public class YynumberDTO {
/**
* nStatus : 0
* sMsg :
* sPaperNumber : Z1001
* nWait : 1
* nid : 4322
* sRegTime : 2018-12-21 13:49:21
* sQueueName : 预约-交通违法处理
* listWin : ["B03","B04","B05","B06"]
*/
@ApiModelProperty(value = "0:正确号码,号码未呼,有等候人数,人数在 nWait,1:正确号码,号码已呼,呼叫时间在sCallTime,2:无效号码,3:其它错误,4:输入查询参数错误")
private int nStatus;
@ApiModelProperty(value = "错误的消息提示语,字符串")
private String sMsg;
@ApiModelProperty(value = "预约信息唯一ID")
private String sPaperNumber;
@ApiModelProperty(value = " 整数,等候人数")
private int nWait;
@ApiModelProperty(value = "预约信息唯一ID")
private int nid;
@ApiModelProperty(value = "号码取号时间 格式2018-12-21 13:49:21")
private String sRegTime;
@ApiModelProperty(value = "号码被呼叫的时间 格式 2018-12-21 13:51:21")
private String sCallTime;
@ApiModelProperty(value = "业务名称")
private String sQueueName;
@ApiModelProperty(value = "字符串数组,对应办理窗口")
private List<String> listWin;
}
......@@ -3,6 +3,7 @@ package io.hmit.modules.appointment.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import io.hmit.common.entity.BaseEntity;
import io.hmit.modules.appointment.dto.YynumberDTO;
import lombok.Data;
import lombok.EqualsAndHashCode;
......@@ -110,4 +111,8 @@ public class AppointmentOrderEntity extends BaseEntity {
*/
private Integer waitNum;
@TableField(exist = false)
private YynumberDTO yynumberDTO;
}
......@@ -4,7 +4,10 @@ import io.hmit.common.page.PageData;
import io.hmit.common.service.CrudService;
import io.hmit.modules.appointment.dto.AppointmentOrderDTO;
import io.hmit.modules.appointment.dto.ReservationOrderInfoDTO;
import io.hmit.modules.appointment.dto.YynumberDTO;
import io.hmit.modules.appointment.entity.AppointmentOrderEntity;
import org.springframework.web.bind.annotation.RequestParam;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
import java.util.Map;
......@@ -21,8 +24,14 @@ public interface AppointmentOrderService extends CrudService<AppointmentOrderEnt
// PageData<AppointmentOrderDTO> getAppointmentInfoPage(Map<String, Object> params, String identity);
List<ReservationOrderInfoDTO> getAppointmentInfoPage(String identity);
// PageData<AppointmentOrderDTO> page(Map<String, Object> params);
Integer waitingNum (String appointmentTime);
Integer serviceWaitingNum (Long serviceId);
YynumberDTO findByYuNumber(String sPaperNumber );
}
package io.hmit.modules.appointment.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.hmit.common.constant.Constant;
......@@ -7,14 +8,20 @@ import io.hmit.common.page.PageData;
import io.hmit.common.service.impl.CrudServiceImpl;
import io.hmit.common.utils.ConvertUtils;
import io.hmit.common.utils.DateUtils;
import io.hmit.common.utils.HttpRequestUtil;
import io.hmit.common.utils.MD5;
import io.hmit.entity.UserEntity;
import io.hmit.modules.appointment.dao.AppointmentOrderDao;
import io.hmit.modules.appointment.dto.AppointmentOrderDTO;
import io.hmit.modules.appointment.dto.ReservationOrderInfoDTO;
import io.hmit.modules.appointment.dto.YynumberDTO;
import io.hmit.modules.appointment.entity.AppointmentOrderEntity;
import io.hmit.modules.appointment.service.AppointmentOrderService;
import io.hmit.modules.appointment.service.AppointmentServiceService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;
import springfox.documentation.annotations.ApiIgnore;
import javax.annotation.Resource;
import java.util.*;
......@@ -30,6 +37,8 @@ public class AppointmentOrderServiceImpl extends CrudServiceImpl<AppointmentOrde
@Resource
private AppointmentOrderDao appointmentOrderDao;
@Resource
private AppointmentOrderService appointmentOrderService;
@Resource
private AppointmentServiceService appointmentServiceService;
......@@ -109,6 +118,20 @@ public class AppointmentOrderServiceImpl extends CrudServiceImpl<AppointmentOrde
}
*/
// public PageData<AppointmentOrderDTO> page( Map<String, Object> params){
// //分页
// IPage<AppointmentOrderEntity> page = getPage(params, Constant.CREATE_DATE, false);
//
// //查询
//// List<AppointmentOrderEntity> list = appointmentOrderDao.;
//
//// for (AppointmentOrderEntity appointmentOrderEntity : list) {
//// YynumberDTO yynumberDTO = appointmentOrderService.findByYuNumber(appointmentOrderEntity.getAppointmentNum());
//// appointmentOrderEntity.setYynumberDTO(yynumberDTO);
//// }
// return getPageData(list, page.getTotal(), AppointmentOrderDTO.class);
// }
@Override
public Integer waitingNum(String appointmentTime) {
......@@ -120,4 +143,18 @@ public class AppointmentOrderServiceImpl extends CrudServiceImpl<AppointmentOrde
return appointmentOrderDao.serviceWaitingNum(serviceId) ;
}
@Override
public YynumberDTO findByYuNumber(String sPaperNumber) {
//调用取号机接口,。
// String url = "http://IP:8223/smartqueue/getpaperwait?sPaperNumber=" +sPaperNumber;
String url = "http://IP:8223/smartqueue/getpaperwait?sPaperNumber=" +sPaperNumber;
// String s = HttpRequestUtil.sendGetAndRetrieveContent(url);
String s = "{\"nStatus\":1,\"sMsg\":\"号码已被呼叫\",\"nWait\":0,\"sCallTime\":\"2021-03-08 16:27:09\",\"sRegTime\":\"2021-03-08 16:26:55\",\"sQueueName\":\"不动产档案查询\",\"listWin\":[\"38号窗口\",\"39号窗口\",\"40号窗口\",\"41号窗口\",\"42号窗口\",\"43号窗口\"]}";
YynumberDTO yynumberDTO = JSONObject.parseObject(s,YynumberDTO.class);
return yynumberDTO;
}
}
......@@ -17,6 +17,8 @@ public interface UserService extends BaseService<UserEntity> {
UserEntity getUserByUserId(Long userId);
UserEntity queryByIdnum(String idnum);
/**
* 用户登录
*
......
package io.hmit.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.hmit.common.exception.ErrorCode;
import io.hmit.common.exception.HmitException;
import io.hmit.common.service.impl.BaseServiceImpl;
......@@ -33,6 +34,11 @@ public class UserServiceImpl extends BaseServiceImpl<UserDao, UserEntity> implem
return baseDao.getUserByUserId(userId);
}
@Override
public UserEntity queryByIdnum(String idnum) {
return baseDao.selectOne(new QueryWrapper<UserEntity>().eq("id_card_no", idnum));
}
@Override
public Map<String, Object> login(LoginDTO dto) {
......
......@@ -14,5 +14,12 @@
<build>
<finalName>${project.artifactId}</finalName>
</build>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
</project>
......@@ -196,6 +196,46 @@ public class DateUtils {
return dateTime.plusYears(years).toDate();
}
public static String getCurrentTimes() {
Calendar c = Calendar.getInstance();//可以对每个时间域单独修改
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH) +1;
int date = c.get(Calendar.DATE);
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
int second = c.get(Calendar.SECOND);
String year1 = String.valueOf(year);
if (year<10){
year1 = "0"+year1;
}
String month1 = String.valueOf(month);
if (month<10){
month1 = "0"+month1;
}
String date1 = String.valueOf(date);
if (date<10){
date1 = "0"+date1;
}
String hour1 = String.valueOf(hour);
if (hour<10){
hour1 = "0"+hour1;
}
String minute1 = String.valueOf(minute);
if (minute<10){
minute1 = "0"+minute1;
}
String second1 = String.valueOf(second);
if (second<10){
second1 = "0"+second1;
}
return year1 + month1 + date1 +hour1 +minute1 + second1;
}
/**
* 将一段时间段拆分成子区间 按照时间间隔拆分
......
package io.hmit.common.utils;
import org.apache.commons.codec.binary.Base64;
import org.apache.log4j.Logger;
import javax.net.ssl.*;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import java.util.Map;
public class HttpRequestUtil {
private static Logger mailAndLyncFailLogger = Logger.getLogger("MailAndLyncFailLogger");
/***
* 向指定URL发送POST方法的请求
* @param url 发送请求的URL
* @return URL所代表远程资源的响应
*/
public static int sendGet(String url) {
int resultCode = 0;
try {
URL realUrl = new URL(url);
// 打开和URL之间的连接
HttpURLConnection conn = (HttpURLConnection) realUrl.openConnection();
conn.setRequestMethod("GET"); //设置post方式连接
// 设置通用的请求属性
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("Charset", "UTF-8");
conn.setUseCaches(false);
// 建立实际的连接
conn.connect();
// 获取响应状态
resultCode = conn.getResponseCode();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
return resultCode;
}
/**
* 向指定浙里办URL发送GET方法的请求
*
* @param url
* 发送请求的URL
* @param param
* 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
* @return URL 所代表远程资源的响应结果
*/
public static String sendZlbGet(String url, String param) {
String result = "";
BufferedReader in = null;
try {
String urlNameString = null;
if (url.indexOf("ticketValidation") != -1 || url.indexOf("getUserInfo") != -1 ){
urlNameString = url + param;
}else {
urlNameString = url + "?" + param;
}
System.out.println(urlNameString);
URL realUrl = new URL(urlNameString);
// 打开和URL之间的连接
URLConnection connection = realUrl.openConnection();
// 设置通用的请求属性
connection.setRequestProperty("accept", "*/*");
connection.setRequestProperty("connection", "Keep-Alive");
connection.setRequestProperty("user-agent",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
// 建立实际的连接
connection.connect();
// 获取所有响应头字段
Map<String, List<String>> map = connection.getHeaderFields();
// 遍历所有的响应头字段
for (String key : map.keySet()) {
System.out.println(key + "--->" + map.get(key));
}
// 定义 BufferedReader输入流来读取URL的响应
in = new BufferedReader(new InputStreamReader(
connection.getInputStream(),"UTF-8"));
String line;
while ((line = in.readLine()) != null) {
result += line;
}
} catch (Exception e) {
System.out.println("发送GET请求出现异常!" + e);
e.printStackTrace();
}
// 使用finally块来关闭输入流
finally {
try {
if (in != null) {
in.close();
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
return result;
}
/***
* 向指定URL发送GET方法的请求
* @param url 发送请求的URL
* @return URL所代表远程资源的响应
*/
public static String sendGetAndRetrieveContent(String url) {
String result = null;
StringBuffer resultBuffer = new StringBuffer();
try {
URL realUrl = new URL(url);
// 打开和URL之间的连接
HttpURLConnection conn = (HttpURLConnection) realUrl.openConnection();
conn.setRequestMethod("GET"); //设置post方式连接
// 设置通用的请求属性
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("Charset", "UTF-8");
conn.setUseCaches(false);
// 建立实际的连接
conn.connect();
// 获取响应状态
InputStream in = conn.getInputStream();
InputStreamReader reader = new InputStreamReader(in,"UTF-8");
BufferedReader breader = new BufferedReader(reader);
String str = null;
while((str=breader.readLine())!=null){
resultBuffer.append(str);
}
breader.close();
reader.close();
in.close();
conn.disconnect();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
return result=resultBuffer.toString();
}
/***
* 向指定URL发送POST方法的请求
* @param url 发送请求的URL
* @param param 请求参数,请求参数应该是name1=value1&name2=value2的形式
* @return URL所代表远程资源的响应
*/
public static int sendPost(String url, String param) {
PrintWriter out = null;
int resultCode = 0;
try {
URL realUrl = new URL(url);
mailAndLyncFailLogger.info("realUrl:"+realUrl);
mailAndLyncFailLogger.info("param:"+param);
// 打开和URL之间的连接
HttpURLConnection conn = (HttpURLConnection) realUrl.openConnection();
conn.setRequestMethod("POST"); //设置post方式连接
// 设置通用的请求属性
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("Charset", "UTF-8");
// 发送POST请求必须设置如下两行
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
// 获取URLConnection对象对应的输出流
out = new PrintWriter(conn.getOutputStream());
// 发送请求参数
out.print(param);
// flush输出流的缓冲
out.flush();
// 定义BufferedReader输入流来读取URL的响应
resultCode = conn.getResponseCode();
} catch (Exception e) {
e.printStackTrace();
mailAndLyncFailLogger.error(e.getMessage());
} finally {
try {
if (out != null) {
out.close();
}
} catch (Exception ex) {
ex.printStackTrace();
mailAndLyncFailLogger.error(ex.getMessage());
}
}
return resultCode;
}
/***
* 向指定URL发送POST方法的请求
* @param url 发送请求的URL
* @param param 请求参数,请求参数应该是name1=value1&name2=value2的形式
* @param userName 新品系统发送数据账号名
* @param passWord 新品系统发送数据账号密码
* @return URL所代表远程资源的响应
*/
public static int sendPostExtend(String url, String param, String userName, String passWord) {
PrintWriter out = null;
int resultCode = -1;
String base64Str = null;
String userInfo = null;
try {
URL realUrl = new URL(url);
mailAndLyncFailLogger.info("realUrl:"+realUrl);
mailAndLyncFailLogger.info("param:"+param+"; from userName="+userName);
// 打开和URL之间的连接
HttpsURLConnection conn = (HttpsURLConnection) realUrl.openConnection();
//SSLContext sslcontext = SSLContext.getInstance("SSL","SunJSSE");
SSLContext sslcontext = SSLContext.getInstance("SSL");
sslcontext.init(null, new TrustManager[]{new MyX509TrustManager()}, new java.security.SecureRandom());
HostnameVerifier ignoreHostnameVerifier = new HostnameVerifier() {
public boolean verify(String s, SSLSession sslsession) {
mailAndLyncFailLogger.info("WARNING: Hostname is not matched for cert.");
return true;
}
};
conn.setHostnameVerifier(ignoreHostnameVerifier);
conn.setSSLSocketFactory(sslcontext.getSocketFactory());
conn.setRequestMethod("POST"); //设置post方式连接
// 设置通用的请求属性
conn.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
conn.setRequestProperty("Accept-Language", "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2");
conn.setRequestProperty("Accept-Encoding", "gzip, deflate, br");
conn.setRequestProperty("Connection", "keep-alive");
conn.setRequestProperty("Upgrade-Insecure-Requests", "1");
//柳汽通 需要包含指定头部,用于临时授权
Base64 base64 = new Base64();
userInfo = userName+":"+passWord;
base64Str = base64.encodeToString(userInfo.getBytes("UTF-8"));
conn.setRequestProperty("Authorization", "Basic "+base64Str);
// 发送POST请求必须设置如下两行
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
//不校验
// conn.setHostnameVerifier(DO_NOT_VERIFY);
// 获取URLConnection对象对应的输出流
out = new PrintWriter(conn.getOutputStream());
// 发送请求参数
out.print(param);
// flush输出流的缓冲
out.flush();
// 定义BufferedReader输入流来读取URL的响应
conn.getResponseCode();
resultCode = conn.getResponseCode();
} catch (Exception e) {
e.printStackTrace();
mailAndLyncFailLogger.error(e.getMessage());
} finally {
try {
if (out != null) {
out.close();
}
} catch (Exception ex) {
ex.printStackTrace();
mailAndLyncFailLogger.error(ex.getMessage());
}
}
return resultCode;
}
}
package io.hmit.common.utils;
import sun.misc.BASE64Encoder;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* 说明:MD5处理
* 创建人:hmit
* 修改时间:
* @version
*/
public class MD5 {
public static String md5(String str) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(str.getBytes());
byte b[] = md.digest();
int i;
StringBuffer buf = new StringBuffer("");
for (int offset = 0; offset < b.length; offset++) {
i = b[offset];
if (i < 0)
i += 256;
if (i < 16)
buf.append("0");
buf.append(Integer.toHexString(i));
}
str = buf.toString();
} catch (Exception e) {
e.printStackTrace();
}
return str;
}
/**利用MD5进行加密
* @param str 待加密的字符串
* @return 加密后的字符串
* @throws NoSuchAlgorithmException 没有这种产生消息摘要的算法
* @throws UnsupportedEncodingException
*/
public static String EncoderByMd5(String str) throws NoSuchAlgorithmException, UnsupportedEncodingException {
//确定计算方法
MessageDigest md5= MessageDigest.getInstance("MD5");
BASE64Encoder base64en = new BASE64Encoder();
//加密后的字符串
String newstr=base64en.encode(md5.digest(str.getBytes("utf-8")));
return newstr;
}
public static void main(String[] args) throws UnsupportedEncodingException, NoSuchAlgorithmException {
System.out.println(md5("hjfhsdjfueytRwYSdsa%hdf^jdshfh*KGh$e241613389800"));
System.out.println(md5("kkk"));
System.out.println(EncoderByMd5("180@qq.com"+"123456"));
}
}
package io.hmit.common.utils;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.X509TrustManager;
public class MyX509TrustManager implements X509TrustManager {
@Override
public void checkClientTrusted(X509Certificate certificates[],String authType) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] ax509certificate,String s) throws CertificateException {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment