package utility; import beans.uploaderpdata.UploadDataToERP_HY; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import common.BaseClass; import common.Controller; import common.YosException; import common.data.Row; import common.data.Rows; import common.data.SQLFactory; import org.dom4j.Document; import utility.tools.WebRequest; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.CookieHandler; import java.net.CookieManager; import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.HashMap; public class ERPDocking extends BaseClass { public static boolean loginstatus = false; String url = ""; public ERPDocking(String siteid) throws YosException { Rows rows = dbConnect.runSqlQuery("SELECT erp_url from sys_site_parameter WHERE siteid='" + siteid + "'"); if (rows.isNotEmpty()) { url = rows.get(0).getString("erp_url"); } System.err.println(siteid + ":" + url); } public String getUrl() { return url; } /* crm登陆 */ // private void login() throws YosException { // if (!loginstatus) { // /* // 自动保存cookie // */ // CookieManager manager = new CookieManager(); // CookieHandler.setDefault(manager); // String s = new WebRequest().doPost("username=yosAdmin&password=yosAdmin123", "http://crm.meida.com/dmsService/ext/partner/login"); // JSONObject object = JSONObject.parseObject(s); // if (object.getIntValue("code") == 1) { // loginstatus = true; // } else { // loginstatus = false; // } // } // } /** * 获取erp物料档案 * * @param begindate * @param pagerows * @param pagenum * @return * @throws YosException */ public JSONArray getErpItemRows(String begindate, int pagerows, int pagenum) throws YosException { JSONObject object = new JSONObject(); JSONObject objectdetail = new JSONObject(); objectdetail.put("fstatus", "审核"); objectdetail.put("fmodel", ""); objectdetail.put("fitemname", ""); objectdetail.put("fitemclsnum", ""); objectdetail.put("fitemnos", new JSONArray()); objectdetail.put("pagerows", pagerows); objectdetail.put("pagenum", pagenum); objectdetail.put("changedateBeg", begindate); object.put("access_token", "basicDrp"); object.put("classname", "Titem"); object.put("method", "queryPage"); object.put("content", objectdetail); HashMap map = new HashMap<>(); map.put("content-Type", "application/json"); String result = new WebRequest().doPost(object.toString(), url, map); JSONObject resultobject = JSONObject.parseObject(result); // System.out.println(object.toString()); // System.out.println(resultobject.toJSONString()); if (resultobject != null) { if (resultobject.getString("errcode").equals("0")) { return resultobject.getJSONObject("results").getJSONArray("list"); } else { return new JSONArray(); } } else { return new JSONArray(); } } /** * 查询Erp库存 * * @param pagerows * @param pagenum * @param fitemnos * @return * @throws YosException */ public JSONArray getErpIcinvbalRows(int pagerows, int pagenum, JSONArray fitemnos) throws YosException { { JSONObject object = new JSONObject(); JSONObject objectdetail = new JSONObject(); objectdetail.put("fstockno", "01"); objectdetail.put("fmodel", ""); objectdetail.put("fitemname", ""); objectdetail.put("fitemclsnum", ""); objectdetail.put("fitemnos", fitemnos); objectdetail.put("pagerows", pagerows); objectdetail.put("pagenum", pagenum); object.put("access_token", "basicDrp"); object.put("classname", "Icinvbal"); object.put("method", "queryPage"); object.put("content", objectdetail); HashMap map = new HashMap<>(); map.put("content-Type", "application/json"); String result = new WebRequest().doPost(object.toString(), url, map); JSONObject resultobject = JSONObject.parseObject(result); if (resultobject != null) { if (resultobject.getString("errcode").equals("0")) { return resultobject.getJSONObject("results").getJSONArray("list"); } else { return new JSONArray(); } } else { return new JSONArray(); } } } /** * 查询Erp批次库存 * * @param pagerows * @param pagenum * @param fitemnos * @return * @throws YosException */ public JSONArray getErpIcinvbalBatchRows(int pagerows, int pagenum, JSONArray fitemnos) throws YosException { { JSONObject object = new JSONObject(); JSONObject objectdetail = new JSONObject(); objectdetail.put("fstockno", "01"); objectdetail.put("fstockname", ""); objectdetail.put("fmodel", ""); objectdetail.put("fitemname", ""); objectdetail.put("fbatchno", ""); objectdetail.put("fitemclsnum", ""); objectdetail.put("onlyFqtyPositive", "true"); objectdetail.put("fitemnos", fitemnos); objectdetail.put("pagerows", pagerows); objectdetail.put("pagenum", pagenum); object.put("access_token", "basicDrp"); object.put("classname", "Icinvbal"); object.put("method", "queryPageOfBatch"); object.put("content", objectdetail); HashMap map = new HashMap<>(); map.put("content-Type", "application/json"); String result = new WebRequest().doPost(object.toString(), url, map); JSONObject resultobject = JSONObject.parseObject(result); if (resultobject != null) { if (resultobject.getString("errcode").equals("0")) { return resultobject.getJSONObject("results").getJSONArray("list"); } else { return new JSONArray(); } } else { return new JSONArray(); } } } /** * 查询Erp批次库存 * * @param pagerows * @param pagenum * @param fitemnos * @return * @throws YosException */ public JSONArray getErpIcinvbalBatchRowsforbatchno(int pagerows, int pagenum, JSONArray fitemnos,String fbatchno) throws YosException { { JSONObject object = new JSONObject(); JSONObject objectdetail = new JSONObject(); objectdetail.put("fstockno", "01"); objectdetail.put("fstockname", ""); objectdetail.put("fmodel", ""); objectdetail.put("fitemname", ""); objectdetail.put("fbatchno", fbatchno); objectdetail.put("fitemclsnum", ""); objectdetail.put("onlyFqtyPositive", "true"); objectdetail.put("fitemnos", fitemnos); objectdetail.put("pagerows", pagerows); objectdetail.put("pagenum", pagenum); object.put("access_token", "basicDrp"); object.put("classname", "Icinvbal"); object.put("method", "queryPageOfBatch"); object.put("content", objectdetail); HashMap map = new HashMap<>(); map.put("content-Type", "application/json"); String result = new WebRequest().doPost(object.toString(), url, map); JSONObject resultobject = JSONObject.parseObject(result); if (resultobject != null) { if (resultobject.getString("errcode").equals("0")) { return resultobject.getJSONObject("results").getJSONArray("list"); } else { return new JSONArray(); } } else { return new JSONArray(); } } } /** * 创建Erp发货单 * * @param dispatchRow * @param dispatchItems * @return * @throws YosException */ public String createErpSainvoice(Row dispatchRow, Rows dispatchItems, Controller controller, long sa_dispatchid) throws YosException { { JSONObject object = new JSONObject(); JSONObject objectdetail = new JSONObject(); JSONArray jsonArray = new JSONArray(); object.put("access_token", "basicDrp"); object.put("classname", "Sainvoice"); object.put("method", "createSainvoice"); objectdetail.put("finvonum", dispatchRow.getString("billno")); objectdetail.put("fagentnum", dispatchRow.getString("agentnum")); objectdetail.put("fagentname", dispatchRow.getString("enterprisename")); objectdetail.put("fsonum", dispatchRow.getString("sonum")); objectdetail.put("fdate", dispatchRow.getString("billdate")); objectdetail.put("fnotes", dispatchRow.getString("remarks")); objectdetail.put("fcontact", dispatchRow.getString("name")); objectdetail.put("fmobilephone", dispatchRow.getString("phonenumber")); objectdetail.put("faddress", dispatchRow.getString("address")); objectdetail.put("createby", dispatchRow.getString("createby")); if (dispatchItems.isNotEmpty()) { for (Row row : dispatchItems) { JSONObject jsonObject = new JSONObject(); jsonObject.put("fsonum", row.getString("sonum")); jsonObject.put("fsorownum", row.getString("sorowno")); jsonObject.put("fprodnum", row.getString("itemno")); jsonObject.put("fbatchbnum", row.getString("batchno")); jsonObject.put("frownum", row.getString("rowno")); jsonObject.put("fqty", row.getString("qty")); jsonObject.put("fprice", row.getString("price")); jsonObject.put("fremarks", row.getString("remarks")); jsonArray.add(jsonObject); } } objectdetail.put("details", jsonArray); object.put("content", objectdetail); HashMap map = new HashMap<>(); map.put("content-Type", "application/json"); String result = new WebRequest().doPost(object.toString(), url, map); JSONObject resultobject = JSONObject.parseObject(result); saveLog(controller, "sa_dispatch", sa_dispatchid, "创建erp发货单", object.toString(), resultobject, dispatchRow.getString("billno")); if (resultobject != null) { if (resultobject.getString("errcode").equals("0")) { return "true"; } else { return resultobject.getString("errmsg"); } } else { return "false"; } } } /** * 查询Erp发货单(单个) * * @param billno * @return * @throws YosException */ public JSONArray queryErpSainvoice(String billno) throws YosException { { JSONObject object = new JSONObject(); JSONObject objectdetail = new JSONObject(); object.put("access_token", "basicDrp"); object.put("classname", "Sainvoice"); object.put("method", "queryOne"); objectdetail.put("finvonum", billno); object.put("content", objectdetail); HashMap map = new HashMap<>(); map.put("content-Type", "application/json"); String result = new WebRequest().doPost(object.toString(), url, map); JSONObject resultobject = JSONObject.parseObject(result); System.out.println(resultobject); if (resultobject == null || resultobject.getString("errcode").equals("error")) { return new JSONArray(); } else { return resultobject.getJSONObject("results").getJSONArray("details"); } } } /** * 查询Erp发货单(批量) * * @param pagerows * @param pagenum * @param finvonums * @param fagentnum * @param fsonum * @param fstatus * @param onlyNeedClosed * @return * @throws YosException */ public JSONArray queryErpSainvoices(int pagerows, int pagenum, JSONArray finvonums, String fagentnum, String fsonum, String fstatus, boolean onlyNeedClosed, boolean onlyNeedPartialOuts, boolean onlyWithCheckedOuts) throws YosException { { JSONObject object = new JSONObject(); JSONObject objectdetail = new JSONObject(); object.put("access_token", "basicDrp"); object.put("classname", "Sainvoice"); object.put("method", "queryPage"); objectdetail.put("pagenum", pagenum); objectdetail.put("pagerows", pagerows); objectdetail.put("finvonums", finvonums); objectdetail.put("fagentnum", fagentnum); objectdetail.put("fsonum", fsonum); objectdetail.put("fstatus", fstatus); objectdetail.put("onlyNeedClosed", onlyNeedClosed); objectdetail.put("onlyNeedPartialOuts", onlyNeedPartialOuts); objectdetail.put("onlyWithCheckedOuts", onlyWithCheckedOuts); object.put("content", objectdetail); HashMap map = new HashMap<>(); map.put("content-Type", "application/json"); System.out.println(object.toString()); String result = new WebRequest().doPost(object.toString(), url, map); JSONObject resultobject = JSONObject.parseObject(result); System.out.println(resultobject); if (resultobject == null || resultobject.getString("errcode").equals("error")) { return new JSONArray(); } else { return resultobject.getJSONObject("results").getJSONArray("list"); } } } /** * 关闭Erp发货单 * * @param billno * @param isManual * @return * @throws YosException */ public String closeErpSainvoice(String billno, boolean isManual, Controller controller, long sa_dispatchid) throws YosException { { JSONObject object = new JSONObject(); JSONObject objectdetail = new JSONObject(); object.put("access_token", "basicDrp"); object.put("classname", "Sainvoice"); object.put("method", "closeSainvoice"); objectdetail.put("finvonum", billno); objectdetail.put("isManual", isManual); object.put("content", objectdetail); HashMap map = new HashMap<>(); map.put("content-Type", "application/json"); String result = new WebRequest().doPost(object.toString(), url, map); JSONObject resultobject = JSONObject.parseObject(result); saveLog(controller, "sa_dispatch", sa_dispatchid, "关闭发货单", object.toString(), resultobject, billno); if (resultobject != null) { if (resultobject.getString("errcode").equals("0")) { return "true"; } else { return resultobject.getString("errmsg"); } } else { return "false"; } } } /** * Erp发货单行关闭 * * @param billno * @param controller * @param rowno * @param itemno * @param sa_dispatchid * @return * @throws YosException */ public String closeErpSainvoiceRow(String billno, Controller controller, long rowno, String itemno, long sa_dispatchid) throws YosException { { JSONObject object = new JSONObject(); JSONObject objectdetail = new JSONObject(); object.put("access_token", "basicDrp"); object.put("classname", "Sainvoice"); object.put("method", "closeRowOfSainvoice"); objectdetail.put("finvonum", billno); objectdetail.put("fprodnum", itemno); objectdetail.put("frownum", rowno); object.put("content", objectdetail); HashMap map = new HashMap<>(); map.put("content-Type", "application/json"); String result = new WebRequest().doPost(object.toString(), url, map); JSONObject resultobject = JSONObject.parseObject(result); saveLog(controller, "sa_dispatch", sa_dispatchid, "发货单行关闭", object.toString(), resultobject, billno); if (resultobject != null) { if (resultobject.getString("errcode").equals("0")) { return "true"; } else { return resultobject.getString("errmsg"); } } else { return resultobject.getString("false"); } } } /** * 创建Erp退/换货单 * * @param aftersalesmagRow * @param aftersalesmagItems * @return * @throws YosException */ public String createErpSareturn(Row aftersalesmagRow, Rows aftersalesmagItems, Controller controller, long sa_aftersalesmagid) throws YosException { { JSONObject object = new JSONObject(); JSONObject objectdetail = new JSONObject(); JSONArray jsonArray = new JSONArray(); object.put("access_token", "basicDrp"); object.put("classname", "Sareturn"); object.put("method", "createSareturn"); objectdetail.put("freturnnum", aftersalesmagRow.getString("billno")); objectdetail.put("fagentnum", aftersalesmagRow.getString("agentnum")); objectdetail.put("fagentname", aftersalesmagRow.getString("enterprisename")); objectdetail.put("faccclsnum", "01"); objectdetail.put("fdate", aftersalesmagRow.getString("billdate")); objectdetail.put("fnotes", aftersalesmagRow.getString("reason")); objectdetail.put("createby", aftersalesmagRow.getString("createby")); if (aftersalesmagRow.getString("type").equals("退货单")) { objectdetail.put("freturntype", "退货"); } else if (aftersalesmagRow.getString("type").equals("换货单")) { objectdetail.put("freturntype", "换货"); } if (aftersalesmagItems.isNotEmpty()) { for (Row row : aftersalesmagItems) { JSONObject jsonObject = new JSONObject(); jsonObject.put("fprodnum", row.getString("itemno")); jsonObject.put("fbatchbnum", row.getString("batchno")); jsonObject.put("fqty", row.getString("qty")); jsonObject.put("fprice", row.getString("price")); jsonObject.put("fremarks", row.getString("reason")); jsonArray.add(jsonObject); } } objectdetail.put("details", jsonArray); object.put("content", objectdetail); HashMap map = new HashMap<>(); map.put("content-Type", "application/json"); System.out.println(object.toString()); String result = new WebRequest().doPost(object.toString(), url, map); JSONObject resultobject = JSONObject.parseObject(result); saveLog(controller, "sa_aftersalesmag", sa_aftersalesmagid, "创建erp退/换货单", object.toString(), resultobject, aftersalesmagRow.getString("billno")); if (resultobject != null) { if (resultobject.getString("errcode").equals("0")) { return "true"; } else { return resultobject.getString("errmsg"); } } else { return "false"; } } } /** * 查询Erp退/换货单(单个) * * @param billno * @return * @throws YosException */ public JSONArray queryErpSareturn(String billno) throws YosException { { JSONObject object = new JSONObject(); JSONObject objectdetail = new JSONObject(); object.put("access_token", "basicDrp"); object.put("classname", "Sareturn"); object.put("method", "queryOne"); objectdetail.put("freturnnum", billno); object.put("content", objectdetail); HashMap map = new HashMap<>(); map.put("content-Type", "application/json"); String result = new WebRequest().doPost(object.toString(), url, map); JSONObject resultobject = JSONObject.parseObject(result); System.out.println(resultobject); if (resultobject == null || resultobject.getString("errcode").equals("error")) { return new JSONArray(); } else { return resultobject.getJSONObject("results").getJSONArray("details"); } } } /** * 查询Erpt退/换货单(批量) * * @param pagerows * @param pagenum * @param freturnnums * @param fagentnum * @param fsonum * @param fstatus * @param onlyNeedClosed * @return * @throws YosException */ public JSONArray queryErpSareturns(int pagerows, int pagenum, JSONArray freturnnums, String fagentnum, String fsonum, String freturntype, String fstatus, boolean onlyNeedClosed) throws YosException { { JSONObject object = new JSONObject(); JSONObject objectdetail = new JSONObject(); object.put("access_token", "basicDrp"); object.put("classname", "Sareturn"); object.put("method", "queryPage"); objectdetail.put("pagenum", pagenum); objectdetail.put("pagerows", pagerows); objectdetail.put("freturnnums", freturnnums); objectdetail.put("fagentnum", fagentnum); objectdetail.put("fsonum", fsonum); objectdetail.put("freturntype", freturntype); objectdetail.put("fstatus", fstatus); objectdetail.put("onlyNeedClosed", onlyNeedClosed); object.put("content", objectdetail); HashMap map = new HashMap<>(); map.put("content-Type", "application/json"); System.out.println(object.toString()); String result = new WebRequest().doPost(object.toString(), url, map); JSONObject resultobject = JSONObject.parseObject(result); System.out.println(resultobject); if (resultobject == null || resultobject.getString("errcode").equals("error")) { return new JSONArray(); } else { return resultobject.getJSONObject("results").getJSONArray("list"); } } } /** * 复核Erp退/换货单 * * @param billno * @param isManual * @return * @throws YosException */ public String recheckErpSareturn(String billno, boolean isManual, Controller controller, long sa_aftersalesmagid) throws YosException { { JSONObject object = new JSONObject(); JSONObject objectdetail = new JSONObject(); object.put("access_token", "basicDrp"); object.put("classname", "Sareturn"); object.put("method", "closeSareturn"); objectdetail.put("freturnnum", billno); objectdetail.put("isManual", isManual); object.put("content", objectdetail); HashMap map = new HashMap<>(); map.put("content-Type", "application/json"); String result = new WebRequest().doPost(object.toString(), url, map); JSONObject resultobject = JSONObject.parseObject(result); saveLog(controller, "sa_aftersalesmag", sa_aftersalesmagid, "复核erp退/换货单", object.toString(), resultobject, billno); if (resultobject != null) { if (resultobject.getString("errcode").equals("0")) { return "true"; } else { return resultobject.getString("errmsg"); } } else { return "false"; } } } /** * 上传日志更新 * * @param controller * @param ownertable * @param ownerid * @param type * @param request * @param response * @param billno * @return */ public static boolean saveLog(Controller controller, String ownertable, long ownerid, String type, String request, JSONObject response, String billno) { boolean issuccess = false; try { Rows rows = controller.dbConnect.runSqlQuery( "select * from sys_erpupdatelog where ownertable='" + ownertable + "' and ownerid=" + ownerid); SQLFactory sqlFactory; if (!rows.isEmpty()) { sqlFactory = new SQLFactory(new UploadDataToERP_HY(), "erp上传日志更新"); sqlFactory.addParameter("sys_erpupdatelogid", rows.get(0).getLong("sys_erpupdatelogid")); } else { sqlFactory = new SQLFactory(new UploadDataToERP_HY(), "erp上传日志新增"); sqlFactory.addParameter("sys_erpupdatelogid", controller.createTableID("sys_erpupdatelog")); } sqlFactory.addParameter("siteid", controller.siteid); sqlFactory.addParameter("userid", controller.userid); sqlFactory.addParameter("username", controller.username); sqlFactory.addParameter("ownerid", ownerid); sqlFactory.addParameter("ownertable", ownertable); sqlFactory.addParameter("type", type); sqlFactory.addParameter("request", request); sqlFactory.addParameter("response", response.toJSONString()); if ("0".equals(response.getString("errcode"))) { sqlFactory.addParameter("erpbillno", billno); sqlFactory.addParameter("errmsg", ""); issuccess = true; } else { sqlFactory.addParameter("erpbillno", ""); sqlFactory.addParameter("errmsg", response.getString("errmsg")); issuccess = false; } sqlFactory.addParameter("status", response.getString("errcode")); controller.dbConnect.runSqlUpdate(sqlFactory); } catch (Exception e) { e.printStackTrace(); } return issuccess; } /** * 查询销售出库单 * * @param pagerows * @param pagenum * @return * @throws YosException */ public JSONArray queryErpStockBill(int pagerows, int pagenum, String fbtname) throws YosException { { JSONArray fupdateFlags = new JSONArray(); fupdateFlags.add(0); fupdateFlags.add(99); fupdateFlags.add(2); JSONObject object = new JSONObject(); JSONObject objectdetail = new JSONObject(); object.put("access_token", "basicDrp"); object.put("classname", "TstockbillOuts"); object.put("method", "queryPageForSyncYos"); objectdetail.put("pagenum", pagenum); objectdetail.put("pagerows", pagerows); objectdetail.put("fbillnums", new JSONArray()); objectdetail.put("fagentnum", ""); objectdetail.put("fstatus", "审核"); objectdetail.put("frb", ""); objectdetail.put("fstockno", ""); objectdetail.put("fbtname", fbtname); objectdetail.put("fminperiod", ""); objectdetail.put("fupdateFlags", fupdateFlags); object.put("content", objectdetail); HashMap map = new HashMap<>(); map.put("content-Type", "application/json"); System.out.println(object.toString()); String result = new WebRequest().doPost(object.toString(), url, map); JSONObject resultobject = JSONObject.parseObject(result); System.out.println(resultobject); if (resultobject == null || resultobject.getString("errcode").equals("error")) { return new JSONArray(); } else { return resultobject.getJSONObject("results").getJSONArray("list"); } } } /** * 更新erp出库单标志 * * @return * @throws YosException */ public String updateErpupdateFlag(JSONArray flags) throws YosException { { JSONObject object = new JSONObject(); JSONObject objectdetail = new JSONObject(); object.put("access_token", "basicDrp"); object.put("classname", "TstockbillOuts"); object.put("method", "syncFupdateFlags"); objectdetail.put("flags", flags); object.put("content", objectdetail); HashMap map = new HashMap<>(); map.put("content-Type", "application/json"); String result = new WebRequest().doPost(object.toString(), url, map); JSONObject resultobject = JSONObject.parseObject(result); if (resultobject != null) { if (resultobject.getString("errcode").equals("0")) { return "true"; } else { return resultobject.getString("errmsg"); } } else { return "false"; } } } // /** // * crm账号同步反馈 // * // * @param id crm账号id // * @param succ 同步是否成功 // * @param errmsg 错误原因 // * @return // * @throws YosException // */ // public boolean feedback1(long id, boolean succ, String errmsg) throws YosException { // JSONArray array = new JSONArray(); // JSONObject object = new JSONObject(); // object.put("id", id); // object.put("fupdateFlag", succ ? 99 : 4); // object.put("fupdateWarnLog", errmsg); // array.add(object); // HashMap map = new HashMap<>(); // map.put("content-Type", "application/json"); // // System.out.println("feedback1:"+array.toString()); // String result = new WebRequest().doPost(array.toString(), "http://crm.meida.com/dmsService/ext/partner/userYos/syncFupdateFlags", map); // JSONObject resultobject = JSONObject.parseObject(result); // return resultobject.getIntValue("code") == 1; // } // /** // * 获取指定的账号信息 // * // * @param id crm账号id // * @return // * @throws YosException // */ // public JSONObject getSingleAccount(long id) throws YosException { // String result = doGet("http://crm.meida.com/dmsService/ext/partner/userYos/getSynUserYos?id=" + id); // JSONObject resultobject = JSONObject.parseObject(result); // if (resultobject.getIntValue("code") == 20001) { // loginstatus = false; // throw new YosException("crm不在登陆状态"); // } else { // return resultobject.getJSONObject("data"); // } // } // // /** // * 更新账号有效期 // * // * @param id crm账号id // * @param fexpireTime 账号到期时间 // * @return // * @throws YosException // */ // public boolean updateAccount(long id, String fexpireTime) throws YosException { // JSONObject object = new JSONObject(); // object.put("id", id); // object.put("fexpireTime", fexpireTime); // HashMap map = new HashMap<>(); // map.put("content-Type", "application/json"); // String result = new WebRequest().doPost(object.toString(), "http://crm.meida.com/dmsService/ext/partner/userYos/editSynUserYos", map); // JSONObject resultobject = JSONObject.parseObject(result); // if (resultobject.getIntValue("code") == 20001) { // loginstatus = false; // throw new YosException("crm不在登陆状态"); // } else { // return resultobject.getIntValue("code") == 1; // } // } private String doGet(String url) { PrintWriter out = null; BufferedReader in = null; StringBuilder result = new StringBuilder(); HttpURLConnection conn = null; try { URL realUrl = new URL(url); // 打开和URL之间的连接 conn = (HttpURLConnection) realUrl.openConnection(); conn.setRequestProperty("accept", "*/*"); conn.setRequestProperty("connection", "Keep-Alive"); conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); conn.setConnectTimeout(8000); in = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8)); String line; while ((line = in.readLine()) != null) { result.append(line); } } catch (Exception e) { e.printStackTrace(); System.err.println("[POST请求]向地址:" + url + " 发送数据:发生错误!"); } finally {// 使用finally块来关闭输出流、输入流 if (out != null) { out.close(); out = null; } if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } in = null; } if (conn != null) { conn.disconnect(); conn = null; } } return result.toString(); } }