|
@@ -10,6 +10,7 @@ import java.io.UnsupportedEncodingException;
|
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.SocketTimeoutException;
|
|
|
import java.net.URL;
|
|
|
+import java.net.URLConnection;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.security.MessageDigest;
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
@@ -112,13 +113,13 @@ public class BaseWebCtl extends BaseCtl {
|
|
|
public SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
|
|
|
|
|
|
public SimpleDateFormat sdf2 = new SimpleDateFormat("YYYY-MM-dd");
|
|
|
-
|
|
|
+
|
|
|
private static String TOKEN = "";
|
|
|
-
|
|
|
- private static boolean TOKEN_FLAG = true;//标志token是否有效
|
|
|
-
|
|
|
- private static int n = 0;//防止死递归
|
|
|
-
|
|
|
+
|
|
|
+ private static boolean TOKEN_FLAG = true;// 标志token是否有效
|
|
|
+
|
|
|
+ private static int n = 0;// 防止死递归
|
|
|
+
|
|
|
public static final String ALGORITHM = "SHA-256";
|
|
|
|
|
|
@InitBinder
|
|
@@ -250,7 +251,7 @@ public class BaseWebCtl extends BaseCtl {
|
|
|
}
|
|
|
// 用户节点
|
|
|
for (User u : users) {
|
|
|
- if(!u.getValid()){
|
|
|
+ if (!u.getValid()) {
|
|
|
continue;
|
|
|
}
|
|
|
NodeVo vo = new NodeVo();
|
|
@@ -283,7 +284,7 @@ public class BaseWebCtl extends BaseCtl {
|
|
|
dataPerm.setOper(Constants.STATE_DO + "");// 设置为已办
|
|
|
securityMgr.dataPermService().save(dataPerm);
|
|
|
}
|
|
|
- if("recall".equals(status)&&dataPerm.getOper().equals(Constants.STATE_DO + "") && dataPerm.getText2().equals(Constants.STATUS_READY)){
|
|
|
+ if ("recall".equals(status) && dataPerm.getOper().equals(Constants.STATE_DO + "") && dataPerm.getText2().equals(Constants.STATUS_READY)) {
|
|
|
dataPerm.setOper(Constants.STATE_TODO + "");// 设置为已办
|
|
|
securityMgr.dataPermService().save(dataPerm);
|
|
|
}
|
|
@@ -338,15 +339,15 @@ public class BaseWebCtl extends BaseCtl {
|
|
|
}
|
|
|
if (menuId != null) {
|
|
|
Menu m = securityMgr.menuService().findMenu(menuId);
|
|
|
- if(m!=null){
|
|
|
+ if (m != null) {
|
|
|
Menu pm = securityMgr.menuService().findMenu(m.getPid());
|
|
|
- if(pm!=null){
|
|
|
+ if (pm != null) {
|
|
|
Menu ppm = securityMgr.menuService().findMenu(pm.getPid());
|
|
|
String path = " 当前位置:" + (ppm == null ? "" : ppm.getName()) + ">>" + (pm == null ? "" : pm.getName()) + ">>" + (m == null ? "" : m.getName());
|
|
|
model.addAttribute("menuPath", path);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
} else {
|
|
|
model.addAttribute("menuPath", "");
|
|
|
}
|
|
@@ -368,112 +369,109 @@ public class BaseWebCtl extends BaseCtl {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
- * 向指定 URL 发送POST方法的请求
|
|
|
- *
|
|
|
- * @param url
|
|
|
- * 发送请求的 URL
|
|
|
- * @param param
|
|
|
- * 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
|
|
- * @return 所代表远程资源的响应结果
|
|
|
- * @throws UnsupportedEncodingException
|
|
|
- */
|
|
|
- public static String sendPost(String param) throws UnsupportedEncodingException{
|
|
|
- n++;
|
|
|
- if(n > 2){
|
|
|
- n = 0;
|
|
|
- return null;
|
|
|
- }
|
|
|
- //获取token
|
|
|
- if(!TOKEN_FLAG){
|
|
|
- TOKEN = getToken(Constants.CORPID, Constants.SECRET);
|
|
|
- }
|
|
|
-
|
|
|
- String urlString = Constants.SEND_MSG_URL+"message/send?access_token="+TOKEN;
|
|
|
- String txt = new String(param.getBytes("UTF-8"),"UTF-8");
|
|
|
- PrintWriter out = null;
|
|
|
- BufferedReader in = null;
|
|
|
- String result = "";
|
|
|
- try {
|
|
|
- URL realUrl = new URL(urlString);
|
|
|
- // 打开和URL之间的连接
|
|
|
- HttpURLConnection conn = (HttpURLConnection)realUrl.openConnection();
|
|
|
- // 设置通用的请求属性
|
|
|
- conn.setRequestProperty("Content-Type","application/json;charset=UTF-8");
|
|
|
- conn.setRequestProperty("Charset", "UTF-8");
|
|
|
- conn.setRequestProperty("accept", "*/*");
|
|
|
- conn.setRequestProperty("connection", "Keep-Alive");
|
|
|
- conn.setRequestProperty("user-agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
|
|
|
- // 发送POST请求必须设置如下两行
|
|
|
- conn.setDoOutput(true);
|
|
|
- conn.setDoInput(true);
|
|
|
- conn.setRequestProperty("charsert", "UTF-8");
|
|
|
-
|
|
|
-
|
|
|
- // 获取URLConnection对象对应的输出流
|
|
|
- out = new PrintWriter(new OutputStreamWriter(conn.getOutputStream(),"UTF-8"));
|
|
|
- // 发送请求参数
|
|
|
- System.out.println(txt);
|
|
|
-
|
|
|
- out.print(txt);
|
|
|
- // flush输出流的缓冲
|
|
|
- out.flush();
|
|
|
- // 定义BufferedReader输入流来读取URL的响应
|
|
|
- in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
|
|
- String line;
|
|
|
- while ((line = in.readLine()) != null) {
|
|
|
- result += line;
|
|
|
- }
|
|
|
-
|
|
|
- if(!StringUtils.isEmpty(result)){
|
|
|
- JSONObject resultJSON = new JSONObject(result);
|
|
|
- if(!StringUtils.isEmpty(resultJSON)){
|
|
|
- if("ok".equals(resultJSON.get("errmsg").toString().toLowerCase())){
|
|
|
- TOKEN_FLAG = true;
|
|
|
- n = 0;
|
|
|
- }else{
|
|
|
- System.out.println("TOKEN已过期。。。。。。。。。。。");
|
|
|
- TOKEN_FLAG = false;
|
|
|
- result = sendPost(param);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }catch (Exception e) {
|
|
|
- System.out.println("发送 POST 请求出现异常!"+e);
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- //使用finally块来关闭输出流、输入流
|
|
|
- finally{
|
|
|
- try{
|
|
|
- if(out!=null){
|
|
|
- out.close();
|
|
|
- }
|
|
|
- if(in!=null){
|
|
|
- in.close();
|
|
|
- }
|
|
|
- }catch(IOException ex){
|
|
|
- ex.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
+ * 向指定 URL 发送POST方法的请求
|
|
|
+ *
|
|
|
+ * @param url
|
|
|
+ * 发送请求的 URL
|
|
|
+ * @param param
|
|
|
+ * 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
|
|
+ * @return 所代表远程资源的响应结果
|
|
|
+ * @throws UnsupportedEncodingException
|
|
|
+ */
|
|
|
+ public static String sendPost(String param) throws UnsupportedEncodingException {
|
|
|
+ n++;
|
|
|
+ if (n > 2) {
|
|
|
+ n = 0;
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ // 获取token
|
|
|
+ if (!TOKEN_FLAG) {
|
|
|
+ TOKEN = getToken(Constants.CORPID, Constants.SECRET);
|
|
|
+ }
|
|
|
+
|
|
|
+ String urlString = Constants.SEND_MSG_URL + "message/send?access_token=" + TOKEN;
|
|
|
+ String txt = new String(param.getBytes("UTF-8"), "UTF-8");
|
|
|
+ PrintWriter out = null;
|
|
|
+ BufferedReader in = null;
|
|
|
+ String result = "";
|
|
|
+ try {
|
|
|
+ URL realUrl = new URL(urlString);
|
|
|
+ // 打开和URL之间的连接
|
|
|
+ HttpURLConnection conn = (HttpURLConnection) realUrl.openConnection();
|
|
|
+ // 设置通用的请求属性
|
|
|
+ conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
|
|
|
+ conn.setRequestProperty("Charset", "UTF-8");
|
|
|
+ conn.setRequestProperty("accept", "*/*");
|
|
|
+ conn.setRequestProperty("connection", "Keep-Alive");
|
|
|
+ conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
|
|
|
+ // 发送POST请求必须设置如下两行
|
|
|
+ conn.setDoOutput(true);
|
|
|
+ conn.setDoInput(true);
|
|
|
+ conn.setRequestProperty("charsert", "UTF-8");
|
|
|
+
|
|
|
+ // 获取URLConnection对象对应的输出流
|
|
|
+ out = new PrintWriter(new OutputStreamWriter(conn.getOutputStream(), "UTF-8"));
|
|
|
+ // 发送请求参数
|
|
|
+ System.out.println(txt);
|
|
|
+
|
|
|
+ out.print(txt);
|
|
|
+ // flush输出流的缓冲
|
|
|
+ out.flush();
|
|
|
+ // 定义BufferedReader输入流来读取URL的响应
|
|
|
+ in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
|
|
+ String line;
|
|
|
+ while ((line = in.readLine()) != null) {
|
|
|
+ result += line;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!StringUtils.isEmpty(result)) {
|
|
|
+ JSONObject resultJSON = new JSONObject(result);
|
|
|
+ if (!StringUtils.isEmpty(resultJSON)) {
|
|
|
+ if ("ok".equals(resultJSON.get("errmsg").toString().toLowerCase())) {
|
|
|
+ TOKEN_FLAG = true;
|
|
|
+ n = 0;
|
|
|
+ } else {
|
|
|
+ System.out.println("TOKEN已过期。。。。。。。。。。。");
|
|
|
+ TOKEN_FLAG = false;
|
|
|
+ result = sendPost(param);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("发送 POST 请求出现异常!" + e);
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ // 使用finally块来关闭输出流、输入流
|
|
|
+ finally {
|
|
|
+ try {
|
|
|
+ if (out != null) {
|
|
|
+ out.close();
|
|
|
+ }
|
|
|
+ if (in != null) {
|
|
|
+ in.close();
|
|
|
+ }
|
|
|
+ } catch (IOException ex) {
|
|
|
+ ex.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 获取token
|
|
|
+ *
|
|
|
* @param corpid
|
|
|
* @param corpsecret
|
|
|
- * @return
|
|
|
+ * @return
|
|
|
*/
|
|
|
public static String getToken(String corpid, String corpsecret) {
|
|
|
String token = "";
|
|
|
- //获取token接口URL
|
|
|
- String urlString = Constants.SEND_MSG_URL +"gettoken?corpid=" + corpid + "&corpsecret=" + corpsecret;
|
|
|
+ // 获取token接口URL
|
|
|
+ String urlString = Constants.SEND_MSG_URL + "gettoken?corpid=" + corpid + "&corpsecret=" + corpsecret;
|
|
|
HttpURLConnection httpurlconnection = null;
|
|
|
try {
|
|
|
- URL url = new URL(urlString);
|
|
|
+ URL url = new URL(urlString);
|
|
|
// 以post方式请求
|
|
|
httpurlconnection = (HttpURLConnection) url.openConnection();
|
|
|
httpurlconnection.setDoOutput(true);
|
|
@@ -493,12 +491,12 @@ public class BaseWebCtl extends BaseCtl {
|
|
|
String str = breader.readLine();
|
|
|
while (str != null) {
|
|
|
JSONObject jsonObject = new JSONObject(str);
|
|
|
- if(!StringUtils.isEmpty(jsonObject)){
|
|
|
+ if (!StringUtils.isEmpty(jsonObject)) {
|
|
|
token = jsonObject.get("access_token").toString();
|
|
|
}
|
|
|
str = breader.readLine();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
} finally {
|
|
@@ -507,31 +505,32 @@ public class BaseWebCtl extends BaseCtl {
|
|
|
}
|
|
|
return token;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/***
|
|
|
* 获取部门id
|
|
|
+ *
|
|
|
* @param weixinid
|
|
|
* @return
|
|
|
* @throws JSONException
|
|
|
*/
|
|
|
public static String getWxInfo(String weixinid) throws JSONException {
|
|
|
n++;
|
|
|
- if(n > 2){
|
|
|
+ if (n > 2) {
|
|
|
n = 0;
|
|
|
return null;
|
|
|
}
|
|
|
- JSONArray toparty = new JSONArray();
|
|
|
-
|
|
|
- //获取token
|
|
|
- if(!TOKEN_FLAG){
|
|
|
- TOKEN = getToken(Constants.CORPID, Constants.SECRET);
|
|
|
- }
|
|
|
-
|
|
|
- String urlString = Constants.GET_USER_URL+"?access_token="+TOKEN+"&userid="+weixinid;
|
|
|
- String topartyString = "";
|
|
|
+ JSONArray toparty = new JSONArray();
|
|
|
+
|
|
|
+ // 获取token
|
|
|
+ if (!TOKEN_FLAG) {
|
|
|
+ TOKEN = getToken(Constants.CORPID, Constants.SECRET);
|
|
|
+ }
|
|
|
+
|
|
|
+ String urlString = Constants.GET_USER_URL + "?access_token=" + TOKEN + "&userid=" + weixinid;
|
|
|
+ String topartyString = "";
|
|
|
HttpURLConnection httpurlconnection = null;
|
|
|
try {
|
|
|
- URL url = new URL(urlString);
|
|
|
+ URL url = new URL(urlString);
|
|
|
// 以post方式请求
|
|
|
httpurlconnection = (HttpURLConnection) url.openConnection();
|
|
|
httpurlconnection.setDoOutput(true);
|
|
@@ -545,34 +544,34 @@ public class BaseWebCtl extends BaseCtl {
|
|
|
// 获取页面内容
|
|
|
InputStream in = httpurlconnection.getInputStream();
|
|
|
BufferedReader breader = new BufferedReader(new InputStreamReader(in, "utf-8"));
|
|
|
-
|
|
|
+
|
|
|
String line;
|
|
|
String result = "";
|
|
|
- while ((line = breader.readLine()) != null) {
|
|
|
- result += line;
|
|
|
- }
|
|
|
- if(!StringUtils.isEmpty(result)){
|
|
|
- JSONObject resultJSON = new JSONObject(result);
|
|
|
- if(!StringUtils.isEmpty(resultJSON)){
|
|
|
- if("ok".equals(resultJSON.get("errmsg").toString().toLowerCase())){
|
|
|
- toparty = (JSONArray)resultJSON.get("department");
|
|
|
- System.out.println("toparty:"+toparty);
|
|
|
- TOKEN_FLAG = true;
|
|
|
- n = 0;
|
|
|
- for(int i=0;i<toparty.length();i++){
|
|
|
- if(i>0){
|
|
|
- topartyString = topartyString+"|"+toparty.get(i).toString();
|
|
|
- }else {
|
|
|
- topartyString = toparty.get(i).toString();
|
|
|
- }
|
|
|
- }
|
|
|
- }else{
|
|
|
- System.out.println("已过期。。。。。。。。。。。");
|
|
|
- TOKEN_FLAG = false;
|
|
|
- topartyString = "";
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ while ((line = breader.readLine()) != null) {
|
|
|
+ result += line;
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(result)) {
|
|
|
+ JSONObject resultJSON = new JSONObject(result);
|
|
|
+ if (!StringUtils.isEmpty(resultJSON)) {
|
|
|
+ if ("ok".equals(resultJSON.get("errmsg").toString().toLowerCase())) {
|
|
|
+ toparty = (JSONArray) resultJSON.get("department");
|
|
|
+ System.out.println("toparty:" + toparty);
|
|
|
+ TOKEN_FLAG = true;
|
|
|
+ n = 0;
|
|
|
+ for (int i = 0; i < toparty.length(); i++) {
|
|
|
+ if (i > 0) {
|
|
|
+ topartyString = topartyString + "|" + toparty.get(i).toString();
|
|
|
+ } else {
|
|
|
+ topartyString = toparty.get(i).toString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ System.out.println("已过期。。。。。。。。。。。");
|
|
|
+ TOKEN_FLAG = false;
|
|
|
+ topartyString = "";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
} finally {
|
|
@@ -581,339 +580,407 @@ public class BaseWebCtl extends BaseCtl {
|
|
|
}
|
|
|
return topartyString;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
- * 更改当前处理人的限时提醒状态
|
|
|
- * 退回或者完成的最后一步时,把该数据下所有所有提醒设置为已办
|
|
|
+ * 更改当前处理人的限时提醒状态 退回或者完成的最后一步时,把该数据下所有所有提醒设置为已办
|
|
|
*
|
|
|
*/
|
|
|
- public void updateStatus(String buskey,boolean isBack,String uid){
|
|
|
+ public void updateStatus(String buskey, boolean isBack, String uid) {
|
|
|
List<BltxEntity> bltxList = null;
|
|
|
- if(isBack){
|
|
|
+ if (isBack) {
|
|
|
bltxList = bltxService.queryByBuskey(buskey);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
bltxList = bltxService.queryByBuskeyAndShr(uid, buskey);
|
|
|
}
|
|
|
-
|
|
|
- if(bltxList!=null&&bltxList.size()>0){
|
|
|
+
|
|
|
+ if (bltxList != null && bltxList.size() > 0) {
|
|
|
for (BltxEntity bltxEntity : bltxList) {
|
|
|
bltxEntity.setStatus(Constants.BLTX_STATUS_DONE);
|
|
|
- bltxService.save(bltxEntity,uid);
|
|
|
+ bltxService.save(bltxEntity, uid);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- //供webservice调用
|
|
|
- public void sendTxWX(String weixinid,String receivers, String title, String msg, String agentid,String uid,String busskey,String mk) {
|
|
|
+
|
|
|
+ // 供webservice调用
|
|
|
+ public void sendTxWX(String weixinid, String receivers, String title, String msg, String agentid, String uid, String busskey, String mk) {
|
|
|
try {
|
|
|
- if(!tuisong(receivers, title, msg, mk, agentid==null?0:Integer.parseInt(agentid), weixinid, busskey,uid)){
|
|
|
- wxmsgService.saveEntityWX(weixinid, receivers, agentid==null?0:Integer.parseInt(agentid), msg, title,uid,mk,busskey);
|
|
|
+ if (!tuisong(receivers, title, msg, mk, agentid == null ? 0 : Integer.parseInt(agentid), weixinid, busskey, uid)) {
|
|
|
+ wxmsgService.saveEntityWX(weixinid, receivers, agentid == null ? 0 : Integer.parseInt(agentid), msg, title, uid, mk, busskey);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
- //供webservice调用
|
|
|
- //参数顺序 限时天数,系统用户id,步骤,rtx提醒内荣,办理提醒内同,业务key,模块,当前用户id
|
|
|
- public void inserttx(String days,String userid,String step,String rtxmsg,String bltxmsg,String buskey,String lx,String uid){
|
|
|
+
|
|
|
+ // 供webservice调用
|
|
|
+ // 参数顺序 限时天数,系统用户id,步骤,rtx提醒内荣,办理提醒内同,业务key,模块,当前用户id
|
|
|
+ public void inserttx(String days, String userid, String step, String rtxmsg, String bltxmsg, String buskey, String lx, String uid) {
|
|
|
try {
|
|
|
- if(!StringUtils.isEmpty(days)){
|
|
|
+ if (!StringUtils.isEmpty(days)) {
|
|
|
int daynum = Integer.parseInt(days.trim());
|
|
|
- bltxService.saveEntity(userid, step, bltxmsg, daynum, buskey,lx);
|
|
|
+ bltxService.saveEntity(userid, step, bltxmsg, daynum, buskey, lx);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- //发送rtx提醒
|
|
|
+ // 发送rtx提醒
|
|
|
try {
|
|
|
UserEntity u = (UserEntity) securityMgr.userService().findById(userid);
|
|
|
- if(u!=null){
|
|
|
- sendTxWX(u.getWeixinid(), u.getUname(), " 您收到一条提醒", rtxmsg, InitServlet.agentidMap.get(lx),userid, buskey,lx);
|
|
|
+ if (u != null) {
|
|
|
+ sendTxWX(u.getWeixinid(), u.getUname(), " 您收到一条提醒", rtxmsg, InitServlet.agentidMap.get(lx), userid, buskey, lx);
|
|
|
}
|
|
|
- }catch (Throwable e) {
|
|
|
+ } catch (Throwable e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- //参数顺序 微信id,用户名,标题, 内容,微信应用id,模块,业务key(PC端调用)
|
|
|
- public void sendTxPC(String weixinid,String receivers, String title, String msg, String agentid,String mk,String busskey,String oauserid) {
|
|
|
+
|
|
|
+ // 参数顺序 微信id,用户名,标题, 内容,微信应用id,模块,业务key(PC端调用)
|
|
|
+ public void sendTxPC(String weixinid, String receivers, String title, String msg, String agentid, String mk, String busskey, String oauserid) {
|
|
|
try {
|
|
|
- //实时发送,失败放进消息中心
|
|
|
- //参数顺序 微信id,用户名,标题, 内容,微信应用id,模块,业务key
|
|
|
- if(!tuisong(receivers, title, msg, mk, agentid==null?0:Integer.parseInt(agentid), weixinid, busskey,oauserid)){
|
|
|
- wxmsgService.saveEntityPC(weixinid, receivers, agentid==null?0:Integer.parseInt(agentid), msg, title,mk,busskey,oauserid);
|
|
|
+ // 实时发送,失败放进消息中心
|
|
|
+ // 参数顺序 微信id,用户名,标题, 内容,微信应用id,模块,业务key
|
|
|
+ if (!tuisong(receivers, title, msg, mk, agentid == null ? 0 : Integer.parseInt(agentid), weixinid, busskey, oauserid)) {
|
|
|
+ wxmsgService.saveEntityPC(weixinid, receivers, agentid == null ? 0 : Integer.parseInt(agentid), msg, title, mk, busskey, oauserid);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 更改当前处理人的限时提醒状态
|
|
|
*/
|
|
|
- //参数顺序 限时天数,系统用户id,步骤,rtx提醒内荣,办理提醒内同,业务key,模块(PC)
|
|
|
- public void inserttx(String days,String userid,String step,String rtxmsg,String bltxmsg,String buskey,String lx){
|
|
|
+ // 参数顺序 限时天数,系统用户id,步骤,rtx提醒内荣,办理提醒内同,业务key,模块(PC)
|
|
|
+ public void inserttx(String days, String userid, String step, String rtxmsg, String bltxmsg, String buskey, String lx) {
|
|
|
try {
|
|
|
- if(!StringUtils.isEmpty(days)){
|
|
|
+ if (!StringUtils.isEmpty(days)) {
|
|
|
int daynum = Integer.parseInt(days.trim());
|
|
|
- //参数顺序 系统用户id,步骤,办理提醒内同, 限时天数,业务key,模块
|
|
|
- bltxService.saveEntity(userid, step, bltxmsg, daynum, buskey,lx);
|
|
|
+ // 参数顺序 系统用户id,步骤,办理提醒内同, 限时天数,业务key,模块
|
|
|
+ bltxService.saveEntity(userid, step, bltxmsg, daynum, buskey, lx);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
- //发送rtx提醒
|
|
|
+ // 发送rtx提醒
|
|
|
try {
|
|
|
UserEntity u = (UserEntity) securityMgr.userService().findById(userid);
|
|
|
- if(u!=null){
|
|
|
- //参数顺序 微信id,用户名,标题, 内容,微信应用id,模块,业务key
|
|
|
- sendTxPC(u.getWeixinid(), u.getUname(), " 您收到一条提醒", rtxmsg, InitServlet.agentidMap.get(lx),lx,buskey,userid);
|
|
|
+ if (u != null) {
|
|
|
+ // 参数顺序 微信id,用户名,标题, 内容,微信应用id,模块,业务key
|
|
|
+ sendTxPC(u.getWeixinid(), u.getUname(), " 您收到一条提醒", rtxmsg, InitServlet.agentidMap.get(lx), lx, buskey, userid);
|
|
|
}
|
|
|
- }catch (Throwable e) {
|
|
|
+ } catch (Throwable e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- /**供webservice调用
|
|
|
- * 保存已读标记
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 供webservice调用 保存已读标记
|
|
|
+ *
|
|
|
* @param stepname
|
|
|
* @param wfid
|
|
|
* @param uid
|
|
|
*/
|
|
|
- public void saveViewflag(String wfid,String stepname,String uid){
|
|
|
+ public void saveViewflag(String wfid, String stepname, String uid) {
|
|
|
List<ViewflagEntity> list = viewflagService.queryViewflag(wfid, stepname, uid);
|
|
|
- if(list!=null && list.size()>0){
|
|
|
-
|
|
|
- }else{
|
|
|
+ if (list != null && list.size() > 0) {
|
|
|
+
|
|
|
+ } else {
|
|
|
ViewflagEntity viewflagEntity = new ViewflagEntity();
|
|
|
viewflagEntity.setStepname(stepname);
|
|
|
viewflagEntity.setWfid(wfid);
|
|
|
viewflagEntity.setUserid(uid);
|
|
|
viewflagService.save(viewflagEntity, uid);
|
|
|
}
|
|
|
- return ;
|
|
|
+ return;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* SHA-256加密
|
|
|
+ *
|
|
|
* @param orignal
|
|
|
* @return
|
|
|
*/
|
|
|
- public static String SHA256Encrypt(String orignal) {
|
|
|
- MessageDigest md = null;
|
|
|
- try {
|
|
|
- md = MessageDigest.getInstance(ALGORITHM);
|
|
|
- } catch (NoSuchAlgorithmException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- if (null != md) {
|
|
|
- byte[] origBytes = orignal.getBytes();
|
|
|
- md.update(origBytes);
|
|
|
- byte[] digestRes = md.digest();
|
|
|
- String digestStr = getDigestStr(digestRes);
|
|
|
- return digestStr;
|
|
|
- }
|
|
|
-
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- private static String getDigestStr(byte[] origBytes) {
|
|
|
- String tempStr = null;
|
|
|
- StringBuilder stb = new StringBuilder();
|
|
|
- for (int i = 0; i < origBytes.length; i++) {
|
|
|
- // System.out.println("and by bit: " + (origBytes[i] & 0xff));
|
|
|
- // System.out.println("no and: " + origBytes[i]);
|
|
|
- // System.out.println("---------------------------------------------");
|
|
|
- // 这里按位与是为了把字节转整时候取其正确的整数,java中一个int是4个字节
|
|
|
- // 如果origBytes[i]最高位为1,则转为int时,int的前三个字节都被1填充了
|
|
|
- tempStr = Integer.toHexString(origBytes[i] & 0xff);
|
|
|
- if (tempStr.length() == 1) {
|
|
|
- stb.append("0");
|
|
|
- }
|
|
|
- stb.append(tempStr);
|
|
|
-
|
|
|
- }
|
|
|
- return stb.toString();
|
|
|
- }
|
|
|
-
|
|
|
- //参数顺序 用户名,标题,内容,模块,微信应用id,微信id,业务key(PC端调用)
|
|
|
- public boolean tuisong(String uname,String title,String content,String mk,int agentid,String weixinid,String busskey,String oauserid){
|
|
|
- boolean flag = true;
|
|
|
- /**
|
|
|
+ public static String SHA256Encrypt(String orignal) {
|
|
|
+ MessageDigest md = null;
|
|
|
+ try {
|
|
|
+ md = MessageDigest.getInstance(ALGORITHM);
|
|
|
+ } catch (NoSuchAlgorithmException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ if (null != md) {
|
|
|
+ byte[] origBytes = orignal.getBytes();
|
|
|
+ md.update(origBytes);
|
|
|
+ byte[] digestRes = md.digest();
|
|
|
+ String digestStr = getDigestStr(digestRes);
|
|
|
+ return digestStr;
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String getDigestStr(byte[] origBytes) {
|
|
|
+ String tempStr = null;
|
|
|
+ StringBuilder stb = new StringBuilder();
|
|
|
+ for (int i = 0; i < origBytes.length; i++) {
|
|
|
+ // System.out.println("and by bit: " + (origBytes[i] & 0xff));
|
|
|
+ // System.out.println("no and: " + origBytes[i]);
|
|
|
+ // System.out.println("---------------------------------------------");
|
|
|
+ // 这里按位与是为了把字节转整时候取其正确的整数,java中一个int是4个字节
|
|
|
+ // 如果origBytes[i]最高位为1,则转为int时,int的前三个字节都被1填充了
|
|
|
+ tempStr = Integer.toHexString(origBytes[i] & 0xff);
|
|
|
+ if (tempStr.length() == 1) {
|
|
|
+ stb.append("0");
|
|
|
+ }
|
|
|
+ stb.append(tempStr);
|
|
|
+
|
|
|
+ }
|
|
|
+ return stb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 参数顺序 用户名,标题,内容,模块,微信应用id,微信id,业务key(PC端调用)
|
|
|
+ public boolean tuisong(String uname, String title, String content, String mk, int agentid, String weixinid, String busskey, String oauserid) {
|
|
|
+ boolean flag = true;
|
|
|
+ /**
|
|
|
* rtx推送
|
|
|
*/
|
|
|
- try {
|
|
|
+ String url="http://10.1.30.119:8012/sendnotify.cgi?msg="+content+"&receiver="+uname+"&title="+title;
|
|
|
+ getURLContent(url);
|
|
|
+ /*try {
|
|
|
String type = "0";
|
|
|
String delayTime = "0";
|
|
|
int iRet = -1;
|
|
|
+ String SvrIP = "10.1.30.119"; // rtx服务器所在ip地址,请修改
|
|
|
+ int iPort = 6000; // 端口
|
|
|
RTXSvrApi RtxsvrapiObj = new RTXSvrApi();
|
|
|
if (RtxsvrapiObj.Init()) {
|
|
|
-
|
|
|
- iRet = RtxsvrapiObj.sendNotify(uname, title, content, type, delayTime);
|
|
|
- if (iRet == 0) {
|
|
|
- System.out.println("发送成功");
|
|
|
- } else {
|
|
|
- flag=false;
|
|
|
- System.out.println( "发送失败");
|
|
|
- }
|
|
|
+ System.out.println("操作成功" + "\n" + "服务器地址:" + SvrIP + "\n" + "服务器端口:" + iPort);
|
|
|
+ iRet = RtxsvrapiObj.sendNotify(uname, title, content, type, delayTime);
|
|
|
+ if (iRet == 0) {
|
|
|
+ System.out.println("发送成功");
|
|
|
+ } else {
|
|
|
+ flag = false;
|
|
|
+ System.out.println("发送失败");
|
|
|
+ }
|
|
|
}
|
|
|
RtxsvrapiObj.UnInit();
|
|
|
- } catch (Throwable e) {
|
|
|
-// flag=false;
|
|
|
+ } catch (Throwable e) {
|
|
|
+ // flag=false;
|
|
|
e.printStackTrace();
|
|
|
+ }*/
|
|
|
+ // if(!flag){
|
|
|
+ // flag=false;
|
|
|
+ // }
|
|
|
+ // User u = securityMgr.userService().findById(oauserid);
|
|
|
+ content = content.split(",")[0];
|
|
|
+ if (mk.equals(Constants.GRRC)) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ String json = "{\"touser\": \"" + weixinid + "\",\"toparty\": \"" + "" + "\"" + ",\"totag\": \"\",\"msgtype\": \"text\",\"agentid\": \"" + agentid + "\",\"text\": {\"content\": \"" + content + "" + "\"},\"safe\":\"0\"}";
|
|
|
+ sendWxmsg(json);
|
|
|
+ } catch (Exception e) {
|
|
|
+ flag = false;
|
|
|
+ }
|
|
|
+ } else if (mk.equals(Constants.YOUJIAN)) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ StringBuffer sbf = new StringBuffer();
|
|
|
+ sbf.append("https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa70527e1ffa01384&redirect_uri=");
|
|
|
+ sbf.append(URLEncoder.encode(("http://" + Constants.WEIXIN_IP + ":" + Constants.WEIXIN_PORT + "/weixinoa/mobile/" + mk + "/xiangqingemailSJ.html?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;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ try {
|
|
|
+ StringBuffer sbf = new StringBuffer();
|
|
|
+ sbf.append("https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa70527e1ffa01384&redirect_uri=");
|
|
|
+ sbf.append(URLEncoder.encode(("http://" + Constants.WEIXIN_IP + ":" + Constants.WEIXIN_PORT + "/weixinoa/mobile/" + mk + "/info.html?hname=db&isDone=1&id=" + busskey + "&tempdata=" + oauserid + "&wxuserid=" + weixinid), "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;
|
|
|
+ }
|
|
|
}
|
|
|
-// if(!flag){
|
|
|
-// flag=false;
|
|
|
-// }
|
|
|
- User u = securityMgr.userService().findById(oauserid);
|
|
|
- content = content.split(",")[0];
|
|
|
- if(mk.equals(Constants.GRRC)){
|
|
|
-
|
|
|
- try {
|
|
|
- String json ="{\"touser\": \""+weixinid+"\",\"toparty\": \""+""+"\""
|
|
|
- +",\"totag\": \"\",\"msgtype\": \"text\",\"agentid\": \""+agentid+"\",\"text\": {\"content\": \""+content
|
|
|
- +""
|
|
|
- +"\"},\"safe\":\"0\"}";
|
|
|
- sendWxmsg(json);
|
|
|
- } catch (Exception e) {
|
|
|
- flag=false;
|
|
|
- }
|
|
|
- }else if(mk.equals(Constants.YOUJIAN)){
|
|
|
-
|
|
|
- try {
|
|
|
- StringBuffer sbf = new StringBuffer();
|
|
|
- sbf.append("https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa70527e1ffa01384&redirect_uri=");
|
|
|
- sbf.append(URLEncoder.encode(("http://"+Constants.WEIXIN_IP+":"+Constants.WEIXIN_PORT+"/weixinoa/mobile/"+mk+"/xiangqingemailSJ.html?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;
|
|
|
- }
|
|
|
- }else{
|
|
|
-
|
|
|
- try {
|
|
|
- StringBuffer sbf = new StringBuffer();
|
|
|
- sbf.append("https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa70527e1ffa01384&redirect_uri=");
|
|
|
- sbf.append(URLEncoder.encode(("http://"+Constants.WEIXIN_IP+":"+Constants.WEIXIN_PORT+"/weixinoa/mobile/"+mk+"/info.html?hname=db&isDone=1&id="+busskey+"&tempdata="+oauserid+"&wxuserid="+u.getWeixinid()),"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
|
|
|
- */
|
|
|
- public 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");
|
|
|
+
|
|
|
+ return flag;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String getURLContent(String urlStr) {
|
|
|
+ System.out.println(urlStr);
|
|
|
+ URL url = null;
|
|
|
+ BufferedReader in = null;
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ try {
|
|
|
+ url = new URL(urlStr);
|
|
|
+ URLConnection connection = url.openConnection();
|
|
|
+ connection.connect();
|
|
|
+ in = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"));
|
|
|
+ String str = null;
|
|
|
+ while ((str = in.readLine()) != null) {
|
|
|
+ sb.append(str);
|
|
|
+ }
|
|
|
+ } catch (Exception ex) {
|
|
|
+
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ if (in != null) {
|
|
|
+ in.close();
|
|
|
+ }
|
|
|
+ } catch (IOException ex) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 推送微信消息
|
|
|
+ *
|
|
|
+ * @param param
|
|
|
+ * @throws UnsupportedEncodingException
|
|
|
+ */
|
|
|
+ public 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 远程主机响应正文
|
|
|
- */
|
|
|
- public 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;
|
|
|
- }
|
|
|
-
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送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 远程主机响应正文
|
|
|
+ */
|
|
|
+ public 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ //getURLContent("http://192.168.30.142:81/");
|
|
|
+ /* try {
|
|
|
+ String type = "0";
|
|
|
+ String delayTime = "0";
|
|
|
+ int iRet = -1;
|
|
|
+ RTXSvrApi RtxsvrapiObj = new RTXSvrApi();
|
|
|
+ if (RtxsvrapiObj.Init()) {
|
|
|
+
|
|
|
+ iRet = RtxsvrapiObj.sendNotify("zhaoj", "标题", "内容", "0", "0");
|
|
|
+ if (iRet == 0) {
|
|
|
+ System.out.println("发送成功");
|
|
|
+ } else {
|
|
|
+ System.out.println("发送失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ RtxsvrapiObj.UnInit();
|
|
|
+ } catch (Throwable e) {
|
|
|
+ // flag=false;
|
|
|
+ e.printStackTrace();
|
|
|
+ }*/
|
|
|
+ }
|
|
|
}
|