Commit b4bcaaf9480ac07d621007b9622bce7452480433
1 parent
0d1fda38
Exists in
master
微信分享
Showing
1 changed file
with
1 additions
and
81 deletions
Show diff stats
src/main/java/com/sincere/student/controller/CommonController.java
| @@ -226,87 +226,6 @@ public class CommonController { | @@ -226,87 +226,6 @@ public class CommonController { | ||
| 226 | return result; | 226 | return result; |
| 227 | } | 227 | } |
| 228 | 228 | ||
| 229 | - public String Post(String httpUrl, String param) | ||
| 230 | - { | ||
| 231 | - HttpURLConnection connection = null; | ||
| 232 | - InputStream is = null; | ||
| 233 | - OutputStream os = null; | ||
| 234 | - BufferedReader br = null; | ||
| 235 | - String result = null; | ||
| 236 | - try { | ||
| 237 | - URL url = new URL(httpUrl); | ||
| 238 | - // 通过远程url连接对象打开连接 | ||
| 239 | - connection = (HttpURLConnection) url.openConnection(); | ||
| 240 | - // 设置连接请求方式 | ||
| 241 | - connection.setRequestMethod("POST"); | ||
| 242 | - // 设置连接主机服务器超时时间:15000毫秒 | ||
| 243 | - connection.setConnectTimeout(15000); | ||
| 244 | - // 设置读取主机服务器返回数据超时时间:60000毫秒 | ||
| 245 | - connection.setReadTimeout(60000); | ||
| 246 | - | ||
| 247 | - // 默认值为:false,当向远程服务器传送数据/写数据时,需要设置为true | ||
| 248 | - connection.setDoOutput(true); | ||
| 249 | - // 默认值为:true,当前向远程服务读取数据时,设置为true,该参数可有可无 | ||
| 250 | - connection.setDoInput(true); | ||
| 251 | - // 设置传入参数的格式:请求参数应该是 name1=value1&name2=value2 的形式。 | ||
| 252 | - connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); | ||
| 253 | - | ||
| 254 | - // 设置鉴权信息:Authorization: Bearer da3efcbf-0845-4fe3-8aba-ee040be542c0 | ||
| 255 | - connection.setRequestProperty("Authorization", "Bearer da3efcbf-0845-4fe3-8aba-ee040be542c0"); | ||
| 256 | - | ||
| 257 | - // 通过连接对象获取一个输出流 | ||
| 258 | - os = connection.getOutputStream(); | ||
| 259 | - // 通过输出流对象将参数写出去/传输出去,它是通过字节数组写出的 | ||
| 260 | - os.write(param.getBytes()); | ||
| 261 | - // 通过连接对象获取一个输入流,向远程读取 | ||
| 262 | - if (connection.getResponseCode() == 200) { | ||
| 263 | - | ||
| 264 | - is = connection.getInputStream(); | ||
| 265 | - // 对输入流对象进行包装:charset根据工作项目组的要求来设置 | ||
| 266 | - br = new BufferedReader(new InputStreamReader(is, "UTF-8")); | ||
| 267 | - | ||
| 268 | - StringBuffer sbf = new StringBuffer(); | ||
| 269 | - String temp = null; | ||
| 270 | - // 循环遍历一行一行读取数据 | ||
| 271 | - while ((temp = br.readLine()) != null) { | ||
| 272 | - sbf.append(temp); | ||
| 273 | - sbf.append("\r\n"); | ||
| 274 | - } | ||
| 275 | - result = sbf.toString(); | ||
| 276 | - } | ||
| 277 | - } catch (MalformedURLException e) { | ||
| 278 | - e.printStackTrace(); | ||
| 279 | - } catch (IOException e) { | ||
| 280 | - e.printStackTrace(); | ||
| 281 | - } finally { | ||
| 282 | - // 关闭资源 | ||
| 283 | - if (null != br) { | ||
| 284 | - try { | ||
| 285 | - br.close(); | ||
| 286 | - } catch (IOException e) { | ||
| 287 | - e.printStackTrace(); | ||
| 288 | - } | ||
| 289 | - } | ||
| 290 | - if (null != os) { | ||
| 291 | - try { | ||
| 292 | - os.close(); | ||
| 293 | - } catch (IOException e) { | ||
| 294 | - e.printStackTrace(); | ||
| 295 | - } | ||
| 296 | - } | ||
| 297 | - if (null != is) { | ||
| 298 | - try { | ||
| 299 | - is.close(); | ||
| 300 | - } catch (IOException e) { | ||
| 301 | - e.printStackTrace(); | ||
| 302 | - } | ||
| 303 | - } | ||
| 304 | - // 断开与远程地址url的连接 | ||
| 305 | - connection.disconnect(); | ||
| 306 | - } | ||
| 307 | - return result; | ||
| 308 | - } | ||
| 309 | - | ||
| 310 | public Token getAccessToken(String appID, String appScret) { | 229 | public Token getAccessToken(String appID, String appScret) { |
| 311 | Token token = new Token(); | 230 | Token token = new Token(); |
| 312 | String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appID + "&secret=" | 231 | String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appID + "&secret=" |
| @@ -330,6 +249,7 @@ public class CommonController { | @@ -330,6 +249,7 @@ public class CommonController { | ||
| 330 | String message = new String(b, "UTF-8"); | 249 | String message = new String(b, "UTF-8"); |
| 331 | JSONObject json = JSONObject.parseObject(message); | 250 | JSONObject json = JSONObject.parseObject(message); |
| 332 | token.setAccess_token(json.getString("access_token")); | 251 | token.setAccess_token(json.getString("access_token")); |
| 252 | + token.setExpires_in(new Integer(json.getString("expires_in"))); | ||
| 333 | System.out.println(message); | 253 | System.out.println(message); |
| 334 | } catch (MalformedURLException e) { | 254 | } catch (MalformedURLException e) { |
| 335 | e.printStackTrace(); | 255 | e.printStackTrace(); |