@SuppressWarnings({"unchecked", "rawtypes"}) private String uploadImage(Map<String, Object> params, File[] files, String[] fileNames) throws Exception { try { logger.info("开始上传文件"); File[] newFiles = new File[files.length]; String webSite = PayConstants.getConfigValue("UPP_INTERFACE_URL"); String methodUrlValue = PayConstants.getConfigValue("UPP_UPLOAD_PIC"); Map map = new HashMap<String, String>(); map.putAll(params); for (int i = 0; i < files.length; i++) { int suxInx = fileNames[i].lastIndexOf("."); String suxName = "jpg"; if (suxInx != -1) { suxName = fileNames[i].substring(suxInx); } int filePathInx = files[i].getPath().lastIndexOf(File.separatorChar); String filePath = files[i].getPath().substring(0, filePathInx); String newFileStr = filePath + File.separatorChar + UUID.randomUUID().toString() + suxName; newFiles[i] = FileUploadImage.FileCopy(files[i].getPath(), newFileStr); } String picUrl = FileUploadImage.upload(webSite + methodUrlValue, map, newFiles); logger.info(String.format("上传文件结束,返回结果:%s", picUrl)); return picUrl; } catch (Exception e) { logger.info(String.format("上传文件异常"), e); throw new Exception("上传文件异常", e); } }
private UppResult callUPP(Object param, String methodUrlKey) throws Exception { UppResult uppResult = null; try { String methodUrlValue = PayConstants.getConfigValue(methodUrlKey); String requestJson = JSONObject.fromObject(param).toString(); // 发送POST消息(明文的数据在下面的方法中做了加密,实际POST发送给支付平台是加密后的数据) String returnJson = HttpUtils.sendRequest( requestJson, PayConstants.getConfigValue("UPP_INTERFACE_URL") + methodUrlValue, PayConstants.getPrivateKey(PayConstants.getConfigValue("MOBILE_API_MERCHANT_CODE")), PayConstants.getPublicKey(PayConstants.getConfigValue("INTERFACE_MERCHANT_CODE")), PayConstants.getConfigValue("MOBILE_API_MERCHANT_CODE")); uppResult = (UppResult) JSONObject.toBean(JSONObject.fromObject(returnJson), UppResult.class); } catch (Exception e) { logger.error("调用支付中接口出错:", e); throw e; } return uppResult; }