packagecom.xxl.job.service.handler; importcom.xxl.job.core.log.XxlJobLogger; importcom.xxl.job.core.biz.model.ReturnT; importcom.xxl.job.core.handler.IJobHandler; public class queryAllinpayWxH5ResultGlueJobHandler extendsIJobHandler { @Override public ReturnT<String> execute(String... arg0) throwsException { String result = null; InputStream input = null; String uri =""; try{ uri = arg0[0];//传进来的参数 URL url = newURL(uri); HttpURLConnection urlcon =(HttpURLConnection) url.openConnection(); urlcon.setRequestMethod("POST"); urlcon.connect();//获取连接 input =urlcon.getInputStream(); BufferedReader buffer = new BufferedReader(newInputStreamReader( input, "UTF-8")); StringBuffer bs = newStringBuffer(); String line = null; while ((line = buffer.readLine()) != null) { bs.append(line); } result =bs.toString(); XxlJobLogger.log("result:"+result); } catch(Exception e) { XxlJobLogger.log("[请求异常][地址:" + uri + "][错误信息:" +e.getMessage() + "]"); returnReturnT.FAIL; } finally{ try{ if (null !=input) input.close(); } catch(Exception e2) { XxlJobLogger.log("[关闭流异常][错误信息:" + e2.getMessage() + "]"); } } returnReturnT.SUCCESS; } }
配置任务信息:
执行参数:需要传递的参数
xxl-job官方文档地址:http://www.xuxueli.com/xxl-job/#/