Index: ssts-datasync-default-impl/src/main/java/com/forgon/disinfectsystem/datasynchronization/dao/szslgqdsrmyy/VerificationCodeDaoImpl.java =================================================================== diff -u --- ssts-datasync-default-impl/src/main/java/com/forgon/disinfectsystem/datasynchronization/dao/szslgqdsrmyy/VerificationCodeDaoImpl.java (revision 0) +++ ssts-datasync-default-impl/src/main/java/com/forgon/disinfectsystem/datasynchronization/dao/szslgqdsrmyy/VerificationCodeDaoImpl.java (revision 41273) @@ -0,0 +1,178 @@ +package com.forgon.disinfectsystem.datasynchronization.dao.szslgqdsrmyy; + +import java.nio.charset.Charset; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.http.HttpEntity; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.util.EntityUtils; +import org.apache.log4j.Logger; + +import com.forgon.disinfectsystem.verification.dao.VerificationCodeDao; +import com.forgon.disinfectsystem.verification.model.VerificationCode; + +/** + * 短信验证码校验的dao + * SZLGSY-14 + */ +public class VerificationCodeDaoImpl implements VerificationCodeDao { + + Logger logger = Logger.getLogger(this.getClass()); + + /** + * 登录接口地址 + */ + private final static String LOGIN_ADDRESS = "http://172.17.14.108:9091/lgdsrmyy/api/login"; + /** + * 短信发送接口地址 + */ + private final static String MESSAGE_SEBD_ADDRESS = "http://172.17.14.108:9091/lgdsrmyy/api/message/send/message"; + /** + * 用户名 + */ + private final static String USER_NAME = "XKSJ-ZSXT"; + /** + * 密码 + */ + private final static String PASSWORD = "XKSJ@XXK.com"; + /** + * 短信发送成功的code=0 + */ + private final static int CODE_SUCCESS = 0; + + @Override + public void generateverificationCode(String messageId, String extCode, + String ssmNumber, String messageContent, Integer reqDeliveryReport, + Integer msgFormat, Integer sendMethod, Date requestDateTime, + String applicationId) { + if(StringUtils.isBlank(ssmNumber)){ + throw new RuntimeException("手机号码不能为空!"); + } + if(StringUtils.isBlank(messageContent)){ + throw new RuntimeException("短信内容不能为空!"); + } + + //获取token + String token = getToken(); + if(StringUtils.isBlank(token)){ + throw new RuntimeException("登录接口返回的token为空!"); + } + + //发送短信验证码 + JSONArray mobiles = new JSONArray(); + mobiles.add(ssmNumber); + JSONObject paramJson = new JSONObject(); + paramJson.put("context", messageContent); + paramJson.put("mobiles", mobiles); + + Map header = new HashMap(); + header.put("token", token); + + String result = this.doHttpPost(MESSAGE_SEBD_ADDRESS, paramJson, header); + //String result = "{'code':0,'msg':'success'}"; + logger.debug(String.format("短信发送接口返回的信息为:%s", result)); + if(StringUtils.isBlank(result)){ + throw new RuntimeException("短信发送接口返回的信息为空!"); + } + JSONObject resultJson = JSONObject.fromObject(result); + int code = resultJson.optInt("code"); + if(code != CODE_SUCCESS){ + throw new RuntimeException("短信发送失败:" + resultJson.optString("msg")); + } + } + + /** + * 获取token + * @return + */ + private String getToken() { + JSONObject paramJson = new JSONObject(); + paramJson.put("userName", USER_NAME); + paramJson.put("password", PASSWORD); + Map header = new HashMap(); + String result = this.doHttpPost(LOGIN_ADDRESS, paramJson, header); + //String result = "{'code':0,'msg':'success','data':{'token':'11111111','expire':'43200000'}}"; + logger.debug(String.format("登录接口返回的信息为:%s", result)); + if(StringUtils.isBlank(result)){ + throw new RuntimeException("登录接口返回的信息为空!"); + } + JSONObject resultJson = JSONObject.fromObject(result); + int code = resultJson.optInt("code"); + if(code != CODE_SUCCESS){ + throw new RuntimeException("登录接口调用失败:" + resultJson.optString("msg")); + } + return resultJson.optJSONObject("data").optString("token"); + } + + /** + * 发送post请求 + * @param postUrl 接口地址 + * @param paramJson json格式的入参 + * @param header 请求头 + * @return 接口返回 + */ + private String doHttpPost(String postUrl, JSONObject paramJson, Map header) { + + String retStr = ""; + try { + logger.debug(String.format("请求参数param=%s,header=%s", paramJson.toString(), header == null ? "" : JSONObject.fromObject(header).toString())); + // 创建HttpClientBuilder + HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); + // HttpClient + CloseableHttpClient closeableHttpClient = httpClientBuilder.build(); + HttpPost httpPost = new HttpPost(postUrl); + // 设置请求和传输超时时间 + RequestConfig requestConfig = RequestConfig.custom() + .setSocketTimeout(300000) + .setConnectTimeout(300000).build(); + httpPost.setConfig(requestConfig); + // 设置Header属性 + httpPost.setHeader("Content-Type", "application/json;charset=UTF-8"); + if(MapUtils.isNotEmpty(header)){ + for (Entry entry : header.entrySet()) { + httpPost.setHeader(entry.getKey(), entry.getValue()); + } + } + StringEntity data = new StringEntity(paramJson.toString(),Charset.forName("UTF-8")); + httpPost.setEntity(data); + CloseableHttpResponse response = closeableHttpClient.execute(httpPost); + HttpEntity httpEntity = response.getEntity(); + if (httpEntity != null) { + // 打印响应内容 + retStr = EntityUtils.toString(httpEntity, "UTF-8"); + } + // 释放资源 + closeableHttpClient.close(); + } catch (Exception e) { + e.printStackTrace(); + logger.debug(String.format("接口地址:%s 调用失败:%s", postUrl, e.getMessage())); + throw new RuntimeException("接口调用异常:" + e.getMessage()); + } + + return retStr; + } + + @Override + public VerificationCode getVerificationCodeByMessageId(String messageId) { + return null; + } + + @Override + public void sendVerificationCodeSms(String smsMumber, String messageContent) { + throw new RuntimeException("不支持发送登录安全验证的短信验证码!"); + } + +} Index: ssts-datasync-default-impl/src/main/java/com/forgon/disinfectsystem/verification/VerificationCodeManagerImpl.java =================================================================== diff -u -r40909 -r41273 --- ssts-datasync-default-impl/src/main/java/com/forgon/disinfectsystem/verification/VerificationCodeManagerImpl.java (.../VerificationCodeManagerImpl.java) (revision 40909) +++ ssts-datasync-default-impl/src/main/java/com/forgon/disinfectsystem/verification/VerificationCodeManagerImpl.java (.../VerificationCodeManagerImpl.java) (revision 41273) @@ -20,6 +20,7 @@ import com.forgon.security.model.User; import com.forgon.security.service.UserManager; import com.forgon.tools.json.JSONUtil; +import com.forgon.tools.util.ConfigUtils; public class VerificationCodeManagerImpl implements VerificationCodeManager { @@ -94,7 +95,12 @@ * @return */ private String generateMessageContent(String variables) { - String messageContent = "【丁香软件】验证码:" + variables + ",用于追溯系统重置登录密码。验证码请勿泄露给他人,谨防账号被盗。"; + String messageContent = ""; + if(ConfigUtils.isProject("szslgqdsrmyy")){ + messageContent = "验证码:" + variables + ",用于追溯系统重置登录密码。验证码请勿泄露给他人,谨防账号被盗。"; + }else{ + messageContent = "【丁香软件】验证码:" + variables + ",用于追溯系统重置登录密码。验证码请勿泄露给他人,谨防账号被盗。"; + } return messageContent; } Index: ssts-web/src/main/webapp/disinfectsystem/config/szslgqdsrmyy/spring/HIS.xml =================================================================== diff -u -r40507 -r41273 --- ssts-web/src/main/webapp/disinfectsystem/config/szslgqdsrmyy/spring/HIS.xml (.../HIS.xml) (revision 40507) +++ ssts-web/src/main/webapp/disinfectsystem/config/szslgqdsrmyy/spring/HIS.xml (.../HIS.xml) (revision 41273) @@ -54,5 +54,13 @@ + + + + + + + \ No newline at end of file