|
@@ -77,7 +77,6 @@ public class InformationReportingController {
|
|
|
@Value("${wx.template_id}")
|
|
@Value("${wx.template_id}")
|
|
|
private String template_id;
|
|
private String template_id;
|
|
|
|
|
|
|
|
- private WxController access_token_inf = new WxController();
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 信息上传
|
|
* 信息上传
|
|
@@ -187,11 +186,11 @@ public class InformationReportingController {
|
|
|
//向方法传入openid、ps、title
|
|
//向方法传入openid、ps、title
|
|
|
String ps = reporting.getPs();
|
|
String ps = reporting.getPs();
|
|
|
if (ps.equals("")) {
|
|
if (ps.equals("")) {
|
|
|
- String a = send(openid, "无备注", "项目有效");
|
|
|
|
|
- System.out.println("备注为:" + ps);
|
|
|
|
|
|
|
+ String a = wxController.send(openid, "无备注", "项目有效");
|
|
|
|
|
+ System.out.println("有效备注为(无备注):" + ps);
|
|
|
}else {
|
|
}else {
|
|
|
- String a = send(openid, ps, "项目有效");
|
|
|
|
|
- System.out.println("备注为:" + ps);
|
|
|
|
|
|
|
+ String a = wxController.send(openid, ps, "项目有效");
|
|
|
|
|
+ System.out.println("有效备注为(有备注):" + ps);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -245,11 +244,11 @@ public class InformationReportingController {
|
|
|
String ps = reporting.getPs();
|
|
String ps = reporting.getPs();
|
|
|
|
|
|
|
|
if (ps.equals("")) {
|
|
if (ps.equals("")) {
|
|
|
- String a = send(openid, "无备注", "项目无效");
|
|
|
|
|
- System.out.println("备注为:" + ps);
|
|
|
|
|
|
|
+ String a = wxController.send(openid, "无备注", "项目无效");
|
|
|
|
|
+ System.out.println("失效备注为(无备注):" + ps);
|
|
|
}else {
|
|
}else {
|
|
|
- String a = send(openid, ps, "项目无效");
|
|
|
|
|
- System.out.println("备注为:" + ps);
|
|
|
|
|
|
|
+ String a = wxController.send(openid, ps, "项目无效");
|
|
|
|
|
+ System.out.println("失效备注为(有备注):" + ps);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//System.out.println(ps);
|
|
//System.out.println(ps);
|
|
@@ -272,87 +271,49 @@ public class InformationReportingController {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 小程序订阅消息
|
|
|
|
|
- */
|
|
|
|
|
- public String send(String openid, String ps, String title) {
|
|
|
|
|
-
|
|
|
|
|
- // access_token是存在有效期的,过期就刷新
|
|
|
|
|
- if (access_token_inf.access_token.equals("")) {
|
|
|
|
|
- wxController.getAccessToken();
|
|
|
|
|
-// getAccessToken();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- System.out.println("订阅消息接口里的access_token_inf: " + wxController.access_token);
|
|
|
|
|
-
|
|
|
|
|
- JSONObject message = new JSONObject();
|
|
|
|
|
- message.put("touser", openid);
|
|
|
|
|
- message.put("template_id", template_id);
|
|
|
|
|
- //message.put("page", "");
|
|
|
|
|
- message.put("miniprogram_state", "formal");
|
|
|
|
|
- message.put("lang", "zh_CN");
|
|
|
|
|
-
|
|
|
|
|
- JSONObject data = new JSONObject();
|
|
|
|
|
-
|
|
|
|
|
- // 审核结果
|
|
|
|
|
- JSONObject thing1 = new JSONObject();
|
|
|
|
|
- thing1.put("value", title);//变为title
|
|
|
|
|
-
|
|
|
|
|
- // 备注
|
|
|
|
|
- JSONObject thing5 = new JSONObject();
|
|
|
|
|
- thing5.put("value", ps);
|
|
|
|
|
|
|
|
|
|
- // 审核结果
|
|
|
|
|
- data.put("thing1", thing1);
|
|
|
|
|
- // 备注
|
|
|
|
|
- data.put("thing5", thing5);
|
|
|
|
|
|
|
|
|
|
- message.put("data", data);
|
|
|
|
|
- System.out.println(message);
|
|
|
|
|
- return HttpsClient.sendJson("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + access_token_inf.access_token, message);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public String getOpenId(String code) throws IOException {
|
|
|
|
|
-
|
|
|
|
|
- // access_token是存在有效期的,过期就刷新
|
|
|
|
|
- if (access_token_inf.access_token.equals("")) {
|
|
|
|
|
- wxController.getAccessToken();
|
|
|
|
|
- }
|
|
|
|
|
- System.out.println("access_token_inf: " + wxController.access_token);
|
|
|
|
|
- // 构造请求URL
|
|
|
|
|
- //String requestUrl = OPENID_URL + "?appid=" + appID + "&secret=" + secret + "&code=" + code + "&grant_type=authorization_code";
|
|
|
|
|
- String requestUrl = "https://api.weixin.qq.com/sns/jscode2session?appid=" + appID + "&secret=" + secret + "&code=" + code + "&grant_type=authorization_code";
|
|
|
|
|
-
|
|
|
|
|
- // 发送请求并获取响应
|
|
|
|
|
- URL url = new URL(requestUrl);
|
|
|
|
|
- HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
|
|
|
- connection.setRequestMethod("GET");
|
|
|
|
|
- connection.setDoOutput(true);
|
|
|
|
|
- connection.setDoInput(true);
|
|
|
|
|
- connection.connect();
|
|
|
|
|
- InputStream inputStream = connection.getInputStream();
|
|
|
|
|
- BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
|
|
|
|
- StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
|
- String line;
|
|
|
|
|
- while ((line = reader.readLine()) != null) {
|
|
|
|
|
- stringBuilder.append(line);
|
|
|
|
|
- }
|
|
|
|
|
- reader.close();
|
|
|
|
|
- connection.disconnect();
|
|
|
|
|
-
|
|
|
|
|
- // 解析响应结果,提取openid
|
|
|
|
|
- String response = stringBuilder.toString();
|
|
|
|
|
- String openid = null;
|
|
|
|
|
- if (response.contains("openid")) {
|
|
|
|
|
- int beginIndex = response.indexOf("openid") + 9;
|
|
|
|
|
- int endIndex = response.indexOf("\"", beginIndex);
|
|
|
|
|
- openid = response.substring(beginIndex, endIndex);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- //String openid="1234512345123451234512345123";
|
|
|
|
|
-
|
|
|
|
|
- return openid;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+// public String getOpenId(String code) throws IOException {
|
|
|
|
|
+//
|
|
|
|
|
+// // access_token是存在有效期的,过期就刷新
|
|
|
|
|
+// if (access_token_inf.access_token.equals("")) {
|
|
|
|
|
+// wxController.getAccessToken();
|
|
|
|
|
+// }
|
|
|
|
|
+// System.out.println("access_token_inf: " + wxController.access_token);
|
|
|
|
|
+// // 构造请求URL
|
|
|
|
|
+// //String requestUrl = OPENID_URL + "?appid=" + appID + "&secret=" + secret + "&code=" + code + "&grant_type=authorization_code";
|
|
|
|
|
+// String requestUrl = "https://api.weixin.qq.com/sns/jscode2session?appid=" + appID + "&secret=" + secret + "&code=" + code + "&grant_type=authorization_code";
|
|
|
|
|
+//
|
|
|
|
|
+// // 发送请求并获取响应
|
|
|
|
|
+// URL url = new URL(requestUrl);
|
|
|
|
|
+// HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
|
|
|
+// connection.setRequestMethod("GET");
|
|
|
|
|
+// connection.setDoOutput(true);
|
|
|
|
|
+// connection.setDoInput(true);
|
|
|
|
|
+// connection.connect();
|
|
|
|
|
+// InputStream inputStream = connection.getInputStream();
|
|
|
|
|
+// BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
|
|
|
|
+// StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
|
+// String line;
|
|
|
|
|
+// while ((line = reader.readLine()) != null) {
|
|
|
|
|
+// stringBuilder.append(line);
|
|
|
|
|
+// }
|
|
|
|
|
+// reader.close();
|
|
|
|
|
+// connection.disconnect();
|
|
|
|
|
+//
|
|
|
|
|
+// // 解析响应结果,提取openid
|
|
|
|
|
+// String response = stringBuilder.toString();
|
|
|
|
|
+// String openid = null;
|
|
|
|
|
+// if (response.contains("openid")) {
|
|
|
|
|
+// int beginIndex = response.indexOf("openid") + 9;
|
|
|
|
|
+// int endIndex = response.indexOf("\"", beginIndex);
|
|
|
|
|
+// openid = response.substring(beginIndex, endIndex);
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+// //String openid="1234512345123451234512345123";
|
|
|
|
|
+//
|
|
|
|
|
+// return openid;
|
|
|
|
|
+// }
|
|
|
|
|
|
|
|
public String getOpenidByCode(String code) {
|
|
public String getOpenidByCode(String code) {
|
|
|
//页面获取openId接口
|
|
//页面获取openId接口
|