|
@@ -1,16 +1,47 @@
|
|
|
package com.xt.jygl.gkjygl.cghzyxxgl.dcsb.service.impl;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
+import java.net.SocketTimeoutException;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.security.cert.CertificateException;
|
|
|
+import java.security.cert.X509Certificate;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
+import javax.net.ssl.SSLContext;
|
|
|
+import javax.net.ssl.SSLException;
|
|
|
+import javax.net.ssl.SSLSession;
|
|
|
+import javax.net.ssl.SSLSocket;
|
|
|
+import javax.net.ssl.TrustManager;
|
|
|
+import javax.net.ssl.X509TrustManager;
|
|
|
+
|
|
|
+import org.apache.http.HttpEntity;
|
|
|
+import org.apache.http.HttpResponse;
|
|
|
+import org.apache.http.NameValuePair;
|
|
|
+import org.apache.http.client.HttpClient;
|
|
|
+import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
|
+import org.apache.http.client.methods.HttpPost;
|
|
|
+import org.apache.http.conn.ConnectTimeoutException;
|
|
|
+import org.apache.http.conn.scheme.Scheme;
|
|
|
+import org.apache.http.conn.ssl.SSLSocketFactory;
|
|
|
+import org.apache.http.conn.ssl.X509HostnameVerifier;
|
|
|
+import org.apache.http.entity.ContentType;
|
|
|
+import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
+import org.apache.http.message.BasicNameValuePair;
|
|
|
+import org.apache.http.params.CoreConnectionPNames;
|
|
|
+import org.apache.http.util.EntityUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.xt.jygl.common.Constants;
|
|
|
import com.xt.jygl.common.GlobalData;
|
|
|
+import com.xt.jygl.gkjcxx.gq.entity.GqEntity;
|
|
|
+import com.xt.jygl.gkjcxx.gq.service.GqService;
|
|
|
import com.xt.jygl.gkjygl.cghzyxxgl.dcsb.dao.DcsbDao;
|
|
|
import com.xt.jygl.gkjygl.cghzyxxgl.dcsb.entity.DcsbEntity;
|
|
|
import com.xt.jygl.gkjygl.cghzyxxgl.dcsb.service.DcsbService;
|
|
@@ -31,6 +62,8 @@ public class DcsbServiceImpl extends BaseWorkFlowServiceImpl<DcsbEntity, String>
|
|
|
private DcsbDao dao;
|
|
|
@Autowired
|
|
|
protected SecurityMgr securityMgr;
|
|
|
+ @Autowired
|
|
|
+ private GqService gqService;
|
|
|
|
|
|
@Override
|
|
|
protected SecRepository<DcsbEntity, String> getDao() {
|
|
@@ -55,6 +88,10 @@ public class DcsbServiceImpl extends BaseWorkFlowServiceImpl<DcsbEntity, String>
|
|
|
param.put(WorkFlowParam.IS_AUDIT, "false");
|
|
|
param.put(WorkFlowParam.DESCRIPTION, entity.getSsjyr().getGkjyr() + "的单船申报");
|
|
|
complete(param, variables);
|
|
|
+ UserEntity ue = securityMgr.userService().findByssjyr(entity.getSsjyr().getId());
|
|
|
+ if (ue != null && ue.getWeixinid() != null) {
|
|
|
+ tuisong(" 您收到一条提醒", entity.getSsjyr().getGkjyr() + "的单船申报", 7, ue.getWeixinid(), entity.getId(), false);
|
|
|
+ }
|
|
|
} else {
|
|
|
SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
Date today = new Date();
|
|
@@ -113,12 +150,21 @@ public class DcsbServiceImpl extends BaseWorkFlowServiceImpl<DcsbEntity, String>
|
|
|
param.put(WorkFlowParam.BUSINESS_KEY, entity.getId().toString());
|
|
|
// 提交流程
|
|
|
create(param, variables);
|
|
|
+ //
|
|
|
+ GqEntity gq = gqService.findOne(gqid);
|
|
|
+ List<UserEntity> ueList = securityMgr.userService().findByRole(Constants.ROLE_DCSBSC);
|
|
|
+ if (ueList != null && gq != null && gq.getSsgkglbm() != null) {
|
|
|
+ for (UserEntity ue : ueList) {
|
|
|
+ if (ue.getSsglbm() != null && ue.getSsglbm().getId() != null && ue.getSsglbm().getId().equals(gq.getSsgkglbm().getId())) {
|
|
|
+ tuisong(" 您收到一条提醒", entity.getSsjyr().getGkjyr() + "的单船申报", 7, ue.getWeixinid(), entity.getId(), true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
return entity;
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
public boolean changeAudit(String shyj, DcsbEntity entity, boolean flag) {
|
|
|
Map<String, Object> variables = new HashMap<String, Object>();
|
|
@@ -219,4 +265,150 @@ public class DcsbServiceImpl extends BaseWorkFlowServiceImpl<DcsbEntity, String>
|
|
|
return dao.dcsbtjbg2(sTime, eTime, hwzldedl, nwmid, szdid, szgkid, szgqid, jcgid);
|
|
|
}
|
|
|
|
|
|
+ // 参数顺序 标题,内容,微信应用id,微信id,业务key(PC端调用),查看or编辑页面
|
|
|
+ private boolean tuisong(String title, String content, int agentid, String weixinid, String busskey, boolean readOnly) {
|
|
|
+ boolean flag = true;
|
|
|
+ content = content.split(",")[0];
|
|
|
+ try {
|
|
|
+ StringBuffer sbf = new StringBuffer();
|
|
|
+ sbf.append("https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa70527e1ffa01384&redirect_uri=");
|
|
|
+ String path = "dcsbView";
|
|
|
+ if (!readOnly) {
|
|
|
+ path = "dcsbEdit";
|
|
|
+ }
|
|
|
+ sbf.append(URLEncoder.encode(("http://" + GlobalData.WEIXIN_IP + ":" + GlobalData.WEIXIN_PORT + "/weixinoa/mobile/dcsb/" + path + ".html?hname=db&isDone=1&id=" + busskey), "utf-8"));
|
|
|
+ sbf.append("&response_type=code&scope=snsapi_base&state=a#wechat_redirect");
|
|
|
+ String json = "{\"touser\": \"" + weixinid + "\",\"toparty\": \"" + "" + "\"" + ",\"totag\": \"\",\"msgtype\": \"text\",\"agentid\": \"" + agentid + "\",\"text\": {\"content\": \"" + content + ",<a href='" + sbf.toString() + "'>点击查看</a>" + "\"},\"safe\":\"0\"}";
|
|
|
+ sendWxmsg(json);
|
|
|
+ } catch (Exception e) {
|
|
|
+ flag = false;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 微信推送
|
|
|
+ */
|
|
|
+
|
|
|
+ return flag;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 推送微信消息
|
|
|
+ *
|
|
|
+ * @param param
|
|
|
+ * @throws UnsupportedEncodingException
|
|
|
+ */
|
|
|
+ private static void sendWxmsg(String param) {
|
|
|
+ try {
|
|
|
+ String urlString = "http://193.168.1.151:8091/weixinoa/weixincontroller/sendPost.do";
|
|
|
+ Map<String, String> params = new HashMap<String, String>();
|
|
|
+ params.put("param", param);
|
|
|
+ sendPostSSLRequest(urlString, params, "UTF-8");
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送HTTP_POST_SSL请求
|
|
|
+ *
|
|
|
+ * @see 1)该方法会自动关闭连接,释放资源
|
|
|
+ * @see 2)该方法亦可处理普通的HTTP_POST请求
|
|
|
+ * @see 3)当处理HTTP_POST_SSL请求时,默认请求的是对方443端口,除非reqURL参数中指明了SSL端口
|
|
|
+ * @see 4)方法内设置了连接和读取超时时间,单位为毫秒,超时或发生其它异常时方法会自动返回"通信失败"字符串
|
|
|
+ * @see 5)请求参数含中文等特殊字符时,可直接传入本方法,并指明其编码字符集encodeCharset参数,方法内部会自动对其转码
|
|
|
+ * @see 6)方法内部会自动注册443作为SSL端口,若实际使用中reqURL指定的SSL端口非443,可自行尝试更改方法内部注册的SSL端口
|
|
|
+ * @see 7)该方法在解码响应报文时所采用的编码,取自响应消息头中的[Content-Type:text/html;
|
|
|
+ * charset=GBK]的charset值
|
|
|
+ * @see 若响应消息头中未指定Content-Type属性,则会使用HttpClient内部默认的ISO-8859-1
|
|
|
+ * @param reqURL
|
|
|
+ * 请求地址
|
|
|
+ * @param params
|
|
|
+ * 请求参数
|
|
|
+ * @param encodeCharset
|
|
|
+ * 编码字符集,编码请求数据时用之,当其为null时,则取HttpClient内部默认的ISO-8859-1编码请求参数
|
|
|
+ * @return 远程主机响应正文
|
|
|
+ */
|
|
|
+ private static String sendPostSSLRequest(String reqURL, Map<String, String> params, String encodeCharset) {
|
|
|
+ String responseContent = "通信失败";
|
|
|
+ HttpClient httpClient = new DefaultHttpClient();
|
|
|
+ httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000);
|
|
|
+ httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 20000);
|
|
|
+ // 创建TrustManager()
|
|
|
+ // 用于解决javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
|
|
|
+ X509TrustManager trustManager = new X509TrustManager() {
|
|
|
+ @Override
|
|
|
+ public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public X509Certificate[] getAcceptedIssuers() {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ // 创建HostnameVerifier
|
|
|
+ // 用于解决javax.net.ssl.SSLException: hostname in certificate didn't match:
|
|
|
+ // <123.125.97.66> != <123.125.97.241>
|
|
|
+ X509HostnameVerifier hostnameVerifier = new X509HostnameVerifier() {
|
|
|
+ @Override
|
|
|
+ public void verify(String host, SSLSocket ssl) throws IOException {
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void verify(String host, X509Certificate cert) throws SSLException {
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void verify(String host, String[] cns, String[] subjectAlts) throws SSLException {
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean verify(String arg0, SSLSession arg1) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ try {
|
|
|
+ // TLS1.0与SSL3.0基本上没有太大的差别,可粗略理解为TLS是SSL的继承者,但它们使用的是相同的SSLContext
|
|
|
+ SSLContext sslContext = SSLContext.getInstance(SSLSocketFactory.TLS);
|
|
|
+ // 使用TrustManager来初始化该上下文,TrustManager只是被SSL的Socket所使用
|
|
|
+ sslContext.init(null, new TrustManager[] { trustManager }, null);
|
|
|
+ // 创建SSLSocketFactory
|
|
|
+ SSLSocketFactory socketFactory = new SSLSocketFactory(sslContext, hostnameVerifier);
|
|
|
+ // 通过SchemeRegistry将SSLSocketFactory注册到HttpClient上
|
|
|
+ httpClient.getConnectionManager().getSchemeRegistry().register(new Scheme("https", 443, socketFactory));
|
|
|
+ // 创建HttpPost
|
|
|
+ HttpPost httpPost = new HttpPost(reqURL);
|
|
|
+ // 由于下面使用的是new
|
|
|
+ // UrlEncodedFormEntity(....),所以这里不需要手工指定CONTENT_TYPE为application/x-www-form-urlencoded
|
|
|
+ // 因为在查看了HttpClient的源码后发现,UrlEncodedFormEntity所采用的默认CONTENT_TYPE就是application/x-www-form-urlencoded
|
|
|
+ // httpPost.setHeader(HTTP.CONTENT_TYPE,
|
|
|
+ // "application/x-www-form-urlencoded; charset=" + encodeCharset);
|
|
|
+ // 构建POST请求的表单参数
|
|
|
+ if (null != params) {
|
|
|
+ List<NameValuePair> formParams = new ArrayList<NameValuePair>();
|
|
|
+ for (Map.Entry<String, String> entry : params.entrySet()) {
|
|
|
+ formParams.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
|
|
|
+ }
|
|
|
+ httpPost.setEntity(new UrlEncodedFormEntity(formParams, encodeCharset));
|
|
|
+ }
|
|
|
+ HttpResponse response = httpClient.execute(httpPost);
|
|
|
+ HttpEntity entity = response.getEntity();
|
|
|
+ if (null != entity) {
|
|
|
+ responseContent = EntityUtils.toString(entity, ContentType.getOrDefault(entity).getCharset());
|
|
|
+ EntityUtils.consume(entity);
|
|
|
+ }
|
|
|
+ } catch (ConnectTimeoutException cte) {
|
|
|
+ System.out.println("请求通信[" + reqURL + "]时连接超时,堆栈轨迹如下" + cte);
|
|
|
+ } catch (SocketTimeoutException ste) {
|
|
|
+ System.out.println("请求通信[" + reqURL + "]时读取超时,堆栈轨迹如下" + ste);
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("请求通信[" + reqURL + "]时偶遇异常,堆栈轨迹如下" + e);
|
|
|
+ } finally {
|
|
|
+ httpClient.getConnectionManager().shutdown();
|
|
|
+ }
|
|
|
+ return responseContent;
|
|
|
+ }
|
|
|
}
|