Java tutorial
package gpps.service.impl; import gpps.dao.IBorrowerDao; import gpps.dao.ICardBindingDao; import gpps.dao.ICashStreamDao; import gpps.dao.ILenderDao; import gpps.dao.IPayBackDao; import gpps.inner.service.IInnerThirdPaySupportService; import gpps.model.Borrower; import gpps.model.CashStream; import gpps.model.GovermentOrder; import gpps.model.Lender; import gpps.model.PayBack; import gpps.model.Product; import gpps.model.ProductSeries; import gpps.model.Submit; import gpps.service.IAccountService; import gpps.service.IBorrowerService; import gpps.service.IGovermentOrderService; import gpps.service.ILenderService; import gpps.service.ILoginService; import gpps.service.IProductService; import gpps.service.ISubmitService; import gpps.service.exception.IllegalConvertException; import gpps.service.exception.IllegalOperationException; import gpps.service.exception.InsufficientBalanceException; import gpps.service.exception.LoginException; import gpps.service.exception.SMSException; import gpps.service.message.ILetterSendService; import gpps.service.message.IMessageService; import gpps.service.thirdpay.Authorize; import gpps.service.thirdpay.CardBinding; import gpps.service.thirdpay.Cash; import gpps.service.thirdpay.IHttpClientService; import gpps.service.thirdpay.IThirdPaySupportService; import gpps.service.thirdpay.Recharge; import gpps.service.thirdpay.RegistAccount; import gpps.service.thirdpay.ResultCodeException; import gpps.service.thirdpay.ThirdPartyState; import gpps.service.thirdpay.Transfer; import gpps.service.thirdpay.Transfer.LoanJson; import gpps.tools.Common; import gpps.tools.ObjectUtil; import gpps.tools.RsaHelper; import gpps.tools.StringUtil; import java.io.UnsupportedEncodingException; import java.math.BigDecimal; import java.net.URLDecoder; import java.net.URLEncoder; import java.security.SignatureException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; import com.google.gson.Gson; @Service public class ThirdPaySupportServiceImpl implements IThirdPaySupportService { @Autowired IAccountService accountService; @Autowired ILenderService lenderService; @Autowired ILenderDao lenderDao; @Autowired ISubmitService submitService; @Autowired IProductService productService; @Autowired IGovermentOrderService orderService; @Autowired IBorrowerService borrowerService; @Autowired IBorrowerDao borrowerDao; @Autowired IHttpClientService httpClientService; @Autowired ICardBindingDao cardBindingDao; @Autowired ICashStreamDao cashStreamDao; @Autowired IPayBackDao payBackDao; @Autowired IMessageService messageService; @Autowired ILetterSendService letterSendService; @Autowired IInnerThirdPaySupportService innerThirdPaySupportService; private Logger log = Logger.getLogger(ThirdPaySupportServiceImpl.class); @Override public String getUrl() { return innerThirdPaySupportService.getUrl(); } @Override public RegistAccount getRegistAccount() throws LoginException { RegistAccount registAccount = new RegistAccount(); registAccount.setBaseUrl( innerThirdPaySupportService.getBaseUrl(IInnerThirdPaySupportService.ACTION_REGISTACCOUNT)); HttpServletRequest req = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()) .getRequest(); HttpSession session = req.getSession(); Object currentUser = session.getAttribute(ILoginService.SESSION_ATTRIBUTENAME_USER); if (currentUser == null) throw new LoginException("??"); if (currentUser instanceof Lender) { registAccount.setAccountType(null); Lender lender = (Lender) currentUser; // registAccount.setEmail(lender.getEmail()); registAccount.setIdentificationNo(lender.getIdentityCard()); registAccount.setLoanPlatformAccount("L" + lender.getId()); registAccount.setMobile(lender.getTel()); registAccount.setRealName(lender.getName()); } else if (currentUser instanceof Borrower) { registAccount.setAccountType(1); Borrower borrower = (Borrower) currentUser; // registAccount.setEmail(borrower.getEmail()); registAccount.setIdentificationNo(borrower.getLicense()); registAccount.setLoanPlatformAccount("B" + borrower.getId()); registAccount.setMobile(borrower.getTel()); registAccount.setRealName(borrower.getCompanyName());//????????? } else { throw new RuntimeException("??"); } registAccount .setReturnURL(innerThirdPaySupportService.getReturnUrl() + "/account/thirdPartyRegist/response"); if ("1".equals(innerThirdPaySupportService.getAppendFlag())) registAccount.setNotifyURL( innerThirdPaySupportService.getNotifyUrl() + "/account/thirdPartyRegist/response" + "/bg"); else registAccount.setNotifyURL(innerThirdPaySupportService.getNotifyUrl()); registAccount.setPlatformMoneymoremore(innerThirdPaySupportService.getPlatformMoneymoremore()); registAccount.setSignInfo(registAccount.getSign(innerThirdPaySupportService.getPrivateKey())); return registAccount; } @Override public Recharge getCompanyRecharge(String amount) throws LoginException { float am = Float.parseFloat(amount); if (am < 1000.0) { throw new LoginException("?1000"); } Recharge recharge = new Recharge(); recharge.setBaseUrl(innerThirdPaySupportService.getBaseUrl(IInnerThirdPaySupportService.ACTION_RECHARGE)); HttpServletRequest req = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()) .getRequest(); HttpSession session = req.getSession(); Object currentUser = session.getAttribute(ILoginService.SESSION_ATTRIBUTENAME_USER); if (currentUser == null) throw new LoginException("??"); recharge.setAmount(amount); recharge.setReturnURL(innerThirdPaySupportService.getReturnUrl() + "/account/recharge/response"); if ("1".equals(innerThirdPaySupportService.getAppendFlag())) recharge.setNotifyURL( innerThirdPaySupportService.getNotifyUrl() + "/account/recharge/response" + "/bg"); else recharge.setNotifyURL(innerThirdPaySupportService.getNotifyUrl()); recharge.setPlatformMoneymoremore(innerThirdPaySupportService.getPlatformMoneymoremore()); recharge.setRechargeType("4"); //RechargeType==4?? recharge.setFeeType("2"); //??FeeType==2??20 Integer cashStreamId = null; if (currentUser instanceof Lender) { throw new RuntimeException("??"); } else if (currentUser instanceof Borrower) { Borrower borrower = (Borrower) currentUser; recharge.setRechargeMoneymoremore(borrower.getThirdPartyAccount()); cashStreamId = accountService.rechargeBorrowerAccount(borrower.getAccountId(), BigDecimal.valueOf(Double.valueOf(amount)), ""); } else { throw new RuntimeException("??"); } recharge.setOrderNo(String.valueOf(cashStreamId)); recharge.setSignInfo(recharge.getSign(innerThirdPaySupportService.getPrivateKey())); return recharge; } @Override public Recharge getQuickRecharge(String amount) throws LoginException { float am = Float.parseFloat(amount); if (am < 100.0) { throw new LoginException("?100"); } Recharge recharge = new Recharge(); recharge.setBaseUrl(innerThirdPaySupportService.getBaseUrl(IInnerThirdPaySupportService.ACTION_RECHARGE)); HttpServletRequest req = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()) .getRequest(); HttpSession session = req.getSession(); Object currentUser = session.getAttribute(ILoginService.SESSION_ATTRIBUTENAME_USER); if (currentUser == null) throw new LoginException("??"); recharge.setAmount(amount); recharge.setReturnURL(innerThirdPaySupportService.getReturnUrl() + "/account/recharge/response"); if ("1".equals(innerThirdPaySupportService.getAppendFlag())) recharge.setNotifyURL( innerThirdPaySupportService.getNotifyUrl() + "/account/recharge/response" + "/bg"); else recharge.setNotifyURL(innerThirdPaySupportService.getNotifyUrl()); recharge.setPlatformMoneymoremore(innerThirdPaySupportService.getPlatformMoneymoremore()); recharge.setRechargeType("2"); //RechargeType==2?? recharge.setFeeType("2"); //??FeeType==2??3.5 Integer cashStreamId = null; if (currentUser instanceof Lender) { Lender lender = (Lender) currentUser; recharge.setRechargeMoneymoremore(lender.getThirdPartyAccount()); cashStreamId = accountService.rechargeLenderAccount(lender.getAccountId(), BigDecimal.valueOf(Double.valueOf(amount)), ""); } else if (currentUser instanceof Borrower) { Borrower borrower = (Borrower) currentUser; recharge.setRechargeMoneymoremore(borrower.getThirdPartyAccount()); cashStreamId = accountService.rechargeBorrowerAccount(borrower.getAccountId(), BigDecimal.valueOf(Double.valueOf(amount)), ""); } else { throw new RuntimeException("??"); } recharge.setOrderNo(String.valueOf(cashStreamId)); recharge.setSignInfo(recharge.getSign(innerThirdPaySupportService.getPrivateKey())); return recharge; } @Override public Recharge getRecharge(String amount) throws LoginException { Recharge recharge = new Recharge(); recharge.setBaseUrl(innerThirdPaySupportService.getBaseUrl(IInnerThirdPaySupportService.ACTION_RECHARGE)); HttpServletRequest req = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()) .getRequest(); HttpSession session = req.getSession(); Object currentUser = session.getAttribute(ILoginService.SESSION_ATTRIBUTENAME_USER); if (currentUser == null) throw new LoginException("??"); recharge.setAmount(amount); recharge.setReturnURL(innerThirdPaySupportService.getReturnUrl() + "/account/recharge/response"); if ("1".equals(innerThirdPaySupportService.getAppendFlag())) recharge.setNotifyURL( innerThirdPaySupportService.getNotifyUrl() + "/account/recharge/response" + "/bg"); else recharge.setNotifyURL(innerThirdPaySupportService.getNotifyUrl()); recharge.setPlatformMoneymoremore(innerThirdPaySupportService.getPlatformMoneymoremore()); // recharge.setRechargeType("4"); // recharge.setFeeType("1"); // recharge.setSignInfo(recharge.getSign(innerThirdPaySupportService.getPrivateKey())); Integer cashStreamId = null; if (currentUser instanceof Lender) { Lender lender = (Lender) currentUser; recharge.setRechargeMoneymoremore(lender.getThirdPartyAccount()); cashStreamId = accountService.rechargeLenderAccount(lender.getAccountId(), BigDecimal.valueOf(Double.valueOf(amount)), ""); } else if (currentUser instanceof Borrower) { Borrower borrower = (Borrower) currentUser; recharge.setRechargeMoneymoremore(borrower.getThirdPartyAccount()); cashStreamId = accountService.rechargeBorrowerAccount(borrower.getAccountId(), BigDecimal.valueOf(Double.valueOf(amount)), ""); } else { throw new RuntimeException("??"); } recharge.setOrderNo(String.valueOf(cashStreamId)); recharge.setSignInfo(recharge.getSign(innerThirdPaySupportService.getPrivateKey())); return recharge; } @Override public Transfer getTransferToPurchase(Integer cashstreamId) throws InsufficientBalanceException, LoginException, IllegalOperationException { Transfer transfer = new Transfer(); transfer.setBaseUrl(innerThirdPaySupportService.getBaseUrl(innerThirdPaySupportService.ACTION_TRANSFER)); Lender lender = lenderService.getCurrentUser(); if (lender == null) throw new LoginException("??"); CashStream cs = cashStreamDao.find(cashstreamId); if (cs == null) { throw new IllegalOperationException("??"); } if (cs.getAction() != CashStream.ACTION_PURCHASE) { throw new IllegalOperationException("?????"); } if (cs.getLenderAccountId() != lender.getAccountId()) { throw new IllegalOperationException("??????"); } if (cs.getState() != CashStream.STATE_INIT) { throw new IllegalOperationException("???"); } Borrower borrower = borrowerDao.findByAccountID(cs.getBorrowerAccountId()); Submit submit = submitService.find(cs.getSubmitId()); Product product = productService.find(submit.getProductId()); HttpServletRequest req = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()) .getRequest(); transfer.setAction(ThirdPartyState.THIRD_ACTION_MANUAL); //? transfer.setNeedAudit("1");//?? transfer.setReturnURL(innerThirdPaySupportService.getReturnUrl() + "/account/purchase/response"); if ("1".equals(innerThirdPaySupportService.getAppendFlag())) transfer.setNotifyURL( innerThirdPaySupportService.getNotifyUrl() + "/account/purchase/response" + "/bg"); else transfer.setNotifyURL(innerThirdPaySupportService.getNotifyUrl()); transfer.setPlatformMoneymoremore(innerThirdPaySupportService.getPlatformMoneymoremore()); transfer.setTransferAction(ThirdPartyState.THIRD_TRANSFERACTION_BUY);// transfer.setTransferType(ThirdPartyState.THIRD_TRANSFERTYPE_DIRECT);// List<LoanJson> loanJsons = new ArrayList<LoanJson>(); LoanJson loanJson = new LoanJson(); loanJson.setLoanOutMoneymoremore(lender.getThirdPartyAccount()); loanJson.setLoanInMoneymoremore(borrower.getThirdPartyAccount()); loanJson.setOrderNo(cashstreamId.toString()); loanJson.setBatchNo(String.valueOf(product.getId())); // loanJson.setExchangeBatchNo(null); // loanJson.setAdvanceBatchNo(null); loanJson.setAmount(cs.getChiefamount().negate().add(cs.getInterest().negate()).toString()); loanJson.setFullAmount(""); loanJson.setTransferName(""); loanJson.setRemark(""); loanJson.setSecondaryJsonList(""); loanJsons.add(loanJson); transfer.setLoanJsonList(Common.JSONEncode(loanJsons)); transfer.setSignInfo(transfer.getSign(innerThirdPaySupportService.getPrivateKey())); try { transfer.setLoanJsonList(URLEncoder.encode(transfer.getLoanJsonList(), "UTF-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return transfer; } @Override public Transfer getTransferToBuy(Integer submitId, String pid) throws InsufficientBalanceException, LoginException { Transfer transfer = new Transfer(); transfer.setBaseUrl(innerThirdPaySupportService.getBaseUrl(innerThirdPaySupportService.ACTION_TRANSFER)); Lender lender = lenderService.getCurrentUser(); if (lender == null) throw new LoginException("??"); Submit submit = ObjectUtil.checkNullObject(Submit.class, submitService.find(submitId)); if (submit.getState() == Submit.STATE_COMPLETEPAY) { throw new InsufficientBalanceException("???"); } GovermentOrder order = orderService.findGovermentOrderByProduct(submit.getProductId()); Borrower borrower = borrowerService.find(order.getBorrowerId()); HttpServletRequest req = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()) .getRequest(); transfer.setAction("1"); transfer.setNeedAudit(null);//.? transfer.setReturnURL(innerThirdPaySupportService.getReturnUrl() + "/account/buy/response"); if ("1".equals(innerThirdPaySupportService.getAppendFlag())) transfer.setNotifyURL(innerThirdPaySupportService.getNotifyUrl() + "/account/buy/response" + "/bg"); else transfer.setNotifyURL(innerThirdPaySupportService.getNotifyUrl()); transfer.setPlatformMoneymoremore(innerThirdPaySupportService.getPlatformMoneymoremore()); transfer.setRemark1(pid); transfer.setTransferAction("1");// transfer.setTransferType("2");// List<LoanJson> loanJsons = new ArrayList<LoanJson>(); Integer cashStreamId = null; //?? CashStream cashStream = cashStreamDao.findBySubmitAndAction(submitId, CashStream.ACTION_FREEZE); if (cashStream == null) cashStreamId = accountService.freezeLenderAccount(lender.getAccountId(), submit.getAmount(), submitId, ""); else cashStreamId = cashStream.getId(); LoanJson loanJson = new LoanJson(); loanJson.setLoanOutMoneymoremore(lender.getThirdPartyAccount()); loanJson.setLoanInMoneymoremore(borrower.getThirdPartyAccount()); loanJson.setOrderNo(cashStreamId.toString()); loanJson.setBatchNo(String.valueOf(submit.getProductId()));//???? // loanJson.setExchangeBatchNo(null); // loanJson.setAdvanceBatchNo(null); loanJson.setAmount(submit.getAmount().toString()); loanJson.setFullAmount(""); loanJson.setTransferName(""); loanJson.setRemark(""); loanJson.setSecondaryJsonList(""); loanJsons.add(loanJson); transfer.setLoanJsonList(Common.JSONEncode(loanJsons)); transfer.setSignInfo(transfer.getSign(innerThirdPaySupportService.getPrivateKey())); try { transfer.setLoanJsonList(URLEncoder.encode(transfer.getLoanJsonList(), "UTF-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return transfer; } @Override public void repay(List<String> loanNos, int auditType) { if (loanNos == null || loanNos.size() == 0) return; String baseUrl = innerThirdPaySupportService.getBaseUrl(IInnerThirdPaySupportService.ACTION_CHECK); StringBuilder loanNoSBuilder = new StringBuilder(); Map<String, String> params = new HashMap<String, String>(); params.put("PlatformMoneymoremore", innerThirdPaySupportService.getPlatformMoneymoremore()); params.put("AuditType", String.valueOf(auditType)); params.put("ReturnURL", innerThirdPaySupportService.getReturnUrl() + "/account/repay/response/bg"); if ("1".equals(innerThirdPaySupportService.getAppendFlag())) params.put("NotifyURL", innerThirdPaySupportService.getNotifyUrl() + "/account/repay/response/bg"); else params.put("NotifyURL", innerThirdPaySupportService.getNotifyUrl()); for (int i = 0; i < loanNos.size(); i++) { if (loanNoSBuilder.length() != 0) loanNoSBuilder.append(","); loanNoSBuilder.append(loanNos.get(i)); if ((i + 1) % 200 == 0) { params.put("LoanNoList", loanNoSBuilder.toString()); sendExecuteRepay(params, baseUrl); loanNoSBuilder = new StringBuilder(); } } if (loanNoSBuilder.length() > 0) { params.put("LoanNoList", loanNoSBuilder.toString()); sendExecuteRepay(params, baseUrl); } } private void sendExecuteRepay(Map<String, String> params, String baseUrl) { //LoanNoList + PlatformMoneymoremore + AuditType + RandomTimeStamp + Remark1 + Remark2 + Remark3 + ReturnURL + NotifyURL StringBuilder sBuilder = new StringBuilder(); sBuilder.append(StringUtil.strFormat(params.get("LoanNoList"))); sBuilder.append(StringUtil.strFormat(params.get("PlatformMoneymoremore"))); sBuilder.append(StringUtil.strFormat(params.get("AuditType"))); sBuilder.append(StringUtil.strFormat(params.get("RandomTimeStamp"))); sBuilder.append(StringUtil.strFormat(params.get("Remark1"))); sBuilder.append(StringUtil.strFormat(params.get("Remark2"))); sBuilder.append(StringUtil.strFormat(params.get("Remark3"))); sBuilder.append(StringUtil.strFormat(params.get("ReturnURL"))); sBuilder.append(StringUtil.strFormat(params.get("NotifyURL"))); RsaHelper rsa = RsaHelper.getInstance(); String signInfo = rsa.signData(sBuilder.toString(), innerThirdPaySupportService.getPrivateKey()); params.put("SignInfo", signInfo); String body = httpClientService.post(baseUrl, params); Gson gson = new Gson(); Map<String, String> returnParams = gson.fromJson(body, Map.class); try { checkExecutePaybackProcessor(returnParams); } catch (SignatureException e) { e.printStackTrace(); } catch (ResultCodeException e) { e.printStackTrace(); } } public void checkExecutePaybackProcessor(Map<String, String> params) throws SignatureException, ResultCodeException { String[] signStrs = { "LoanNoList", "LoanNoListFail", "PlatformMoneymoremore", "AuditType", "RandomTimeStamp", "Remark1", "Remark2", "Remark3", "ResultCode" }; checkRollBack(params, signStrs); String auditType = params.get("AuditType"); if (!StringUtil.isEmpty(params.get("LoanNoList"))) { String[] loanNoList = params.get("LoanNoList").split(","); for (String loanNo : loanNoList) { List<CashStream> cashStreams = cashStreamDao.findSuccessByActionAndLoanNo(-1, loanNo); if (cashStreams.size() == 2) continue; //?? CashStream cashStream = cashStreams.get(0); try { Integer cashStreamId = null; if (auditType.equals("1")) // { Submit submit = null; GovermentOrder order = null; Product product = null; Lender lender = null; if (cashStream.getSubmitId() != null) { submit = submitService.find(cashStream.getSubmitId()); order = orderService.findGovermentOrderByProduct(submit.getProductId()); product = productService.find(submit.getProductId()); lender = lenderDao.find(submit.getLenderId()); } else { submit = new Submit(); order = new GovermentOrder(); product = new Product(); product.setProductSeries(new ProductSeries()); } Borrower borrower = borrowerDao.findByAccountID(cashStream.getBorrowerAccountId()); //? if (lender != null) { cashStreamId = accountService.repay(lender.getAccountId(), cashStream.getBorrowerAccountId(), cashStream.getChiefamount().negate(), cashStream.getInterest().negate(), cashStream.getSubmitId(), cashStream.getPaybackId(), ""); } else { cashStreamId = accountService.storeChange(cashStream.getBorrowerAccountId(), cashStream.getPaybackId(), cashStream.getChiefamount().negate(), cashStream.getInterest().negate(), ""); } Map<String, String> param = new HashMap<String, String>(); param.put(IMessageService.PARAM_ORDER_NAME, order.getTitle()); param.put(IMessageService.PARAM_PRODUCT_SERIES_NAME, product.getProductSeries().getTitle()); //???? param.put(IMessageService.PARAM_AMOUNT, cashStream.getChiefamount().add(cashStream.getInterest()).negate().toString()); param.put(ILetterSendService.PARAM_TITLE, ""); if (lender != null) { try { letterSendService.sendMessage(ILetterSendService.MESSAGE_TYPE_PAYBACKSUCCESS, ILetterSendService.USERTYPE_LENDER, lender.getId(), param); messageService.sendMessage(IMessageService.MESSAGE_TYPE_PAYBACKSUCCESS, IMessageService.USERTYPE_LENDER, lender.getId(), param); } catch (SMSException e) { log.error(e.getMessage()); } } } else { //TODO:? // Submit submit=submitService.find(cashStream.getSubmitId()); // GovermentOrder order=orderService.findGovermentOrderByProduct(submit.getProductId()); // Product product = productService.find(submit.getProductId()); // cashStreamId=accountService.unfreezeLenderAccount(cashStream.getLenderAccountId(), cashStream.getChiefamount().negate(), cashStream.getSubmitId(), "?"); // // //?lender?? // Map<String, String> param = new HashMap<String, String>(); // param.put(IMessageService.PARAM_ORDER_NAME, order.getTitle()); // param.put(IMessageService.PARAM_PRODUCT_SERIES_NAME, product.getProductSeries().getTitle()); // param.put(IMessageService.PARAM_AMOUNT, submit.getAmount().toString()); // // param.put(ILetterSendService.PARAM_TITLE, "?,"); // try{ // letterSendService.sendMessage(ILetterSendService.MESSAGE_TYPE_FINANCINGFAIL, ILetterSendService.USERTYPE_LENDER, submit.getLenderId(), param); // messageService.sendMessage(IMessageService.MESSAGE_TYPE_FINANCINGFAIL, IMessageService.USERTYPE_LENDER, submit.getLenderId(), param); // }catch(SMSException e){ // log.error(e.getMessage()); // } } cashStreamDao.updateLoanNo(cashStreamId, loanNo, null); } catch (IllegalConvertException e) { e.printStackTrace(); } } } } @Override public void check(List<String> loanNos, int auditType) { if (loanNos == null || loanNos.size() == 0) return; String baseUrl = innerThirdPaySupportService.getBaseUrl(IInnerThirdPaySupportService.ACTION_CHECK); StringBuilder loanNoSBuilder = new StringBuilder(); Map<String, String> params = new HashMap<String, String>(); params.put("PlatformMoneymoremore", innerThirdPaySupportService.getPlatformMoneymoremore()); params.put("AuditType", String.valueOf(auditType)); params.put("ReturnURL", innerThirdPaySupportService.getReturnUrl() + "/account/checkBuy/response/bg"); if ("1".equals(innerThirdPaySupportService.getAppendFlag())) params.put("NotifyURL", innerThirdPaySupportService.getNotifyUrl() + "/account/checkBuy/response/bg"); else params.put("NotifyURL", innerThirdPaySupportService.getNotifyUrl()); for (int i = 0; i < loanNos.size(); i++) { if (loanNoSBuilder.length() != 0) loanNoSBuilder.append(","); loanNoSBuilder.append(loanNos.get(i)); if ((i + 1) % 200 == 0) { params.put("LoanNoList", loanNoSBuilder.toString()); sendCheck(params, baseUrl); // // // sendCheckRollback(params); loanNoSBuilder = new StringBuilder(); } } if (loanNoSBuilder.length() > 0) { params.put("LoanNoList", loanNoSBuilder.toString()); sendCheck(params, baseUrl); // // // sendCheckRollback(params); } } private void sendCheck(Map<String, String> params, String baseUrl) { //LoanNoList + PlatformMoneymoremore + AuditType + RandomTimeStamp + Remark1 + Remark2 + Remark3 + ReturnURL + NotifyURL StringBuilder sBuilder = new StringBuilder(); sBuilder.append(StringUtil.strFormat(params.get("LoanNoList"))); sBuilder.append(StringUtil.strFormat(params.get("PlatformMoneymoremore"))); sBuilder.append(StringUtil.strFormat(params.get("AuditType"))); sBuilder.append(StringUtil.strFormat(params.get("RandomTimeStamp"))); sBuilder.append(StringUtil.strFormat(params.get("Remark1"))); sBuilder.append(StringUtil.strFormat(params.get("Remark2"))); sBuilder.append(StringUtil.strFormat(params.get("Remark3"))); sBuilder.append(StringUtil.strFormat(params.get("ReturnURL"))); sBuilder.append(StringUtil.strFormat(params.get("NotifyURL"))); RsaHelper rsa = RsaHelper.getInstance(); String signInfo = rsa.signData(sBuilder.toString(), innerThirdPaySupportService.getPrivateKey()); params.put("SignInfo", signInfo); String body = httpClientService.post(baseUrl, params); Gson gson = new Gson(); Map<String, String> returnParams = gson.fromJson(body, Map.class); try { checkBuyProcessor(returnParams); } catch (SignatureException e) { e.printStackTrace(); } catch (ResultCodeException e) { e.printStackTrace(); } } private void sendCheckRollback(Map<String, String> params) { Map<String, String> paramsRollback = new HashMap<String, String>(); paramsRollback.putAll(params); paramsRollback.put("ResultCode", "88"); StringBuilder sBuilder = new StringBuilder(); sBuilder.append(StringUtil.strFormat(paramsRollback.get("LoanNoList"))); sBuilder.append(StringUtil.strFormat(paramsRollback.get("PlatformMoneymoremore"))); sBuilder.append(StringUtil.strFormat(paramsRollback.get("AuditType"))); sBuilder.append(StringUtil.strFormat(paramsRollback.get("RandomTimeStamp"))); sBuilder.append(StringUtil.strFormat(paramsRollback.get("Remark1"))); sBuilder.append(StringUtil.strFormat(paramsRollback.get("Remark2"))); sBuilder.append(StringUtil.strFormat(paramsRollback.get("Remark3"))); sBuilder.append(StringUtil.strFormat(paramsRollback.get("ResultCode"))); RsaHelper rsa = RsaHelper.getInstance(); String signInfo = rsa.signData(sBuilder.toString(), innerThirdPaySupportService.getPrivateKey()); paramsRollback.put("SignInfo", signInfo); String body = httpClientService.post(params.get("NotifyURL"), paramsRollback); log.info(body); } @Override public CardBinding getCardBinding() throws LoginException { CardBinding cardBinding = new CardBinding(); cardBinding.setBaseUrl( innerThirdPaySupportService.getBaseUrl(IInnerThirdPaySupportService.ACTION_CARDBINDING)); HttpServletRequest req = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()) .getRequest(); HttpSession session = req.getSession(); Object currentUser = session.getAttribute(ILoginService.SESSION_ATTRIBUTENAME_USER); if (currentUser == null) throw new LoginException("??"); cardBinding.setPlatformMoneymoremore(innerThirdPaySupportService.getPlatformMoneymoremore()); cardBinding.setAction("2"); // RsaHelper rsa = RsaHelper.getInstance(); // cardBinding.setCardNo(cardNo); cardBinding.setReturnURL(innerThirdPaySupportService.getReturnUrl() + "/account/cardBinding/response"); if ("1".equals(innerThirdPaySupportService.getAppendFlag())) cardBinding.setNotifyURL( innerThirdPaySupportService.getNotifyUrl() + "/account/cardBinding/response" + "/bg"); else cardBinding.setNotifyURL(innerThirdPaySupportService.getNotifyUrl()); if (currentUser instanceof Lender) { Lender lender = (Lender) currentUser; cardBinding.setMoneymoremoreId(lender.getThirdPartyAccount()); } else if (currentUser instanceof Borrower) { Borrower borrower = (Borrower) currentUser; cardBinding.setMoneymoremoreId(borrower.getThirdPartyAccount()); } else { throw new RuntimeException("??"); } cardBinding.setSignInfo(cardBinding.getSign(innerThirdPaySupportService.getPrivateKey())); // cardBinding.setCardNo(rsa.encryptData(cardNo, publicKey)); return cardBinding; } @Override public Cash getCash(String amount) throws InsufficientBalanceException, LoginException, IllegalOperationException { Cash cash = new Cash(); cash.setBaseUrl(innerThirdPaySupportService.getBaseUrl(IInnerThirdPaySupportService.ACTION_CASH)); HttpServletRequest req = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()) .getRequest(); HttpSession session = req.getSession(); Object currentUser = session.getAttribute(ILoginService.SESSION_ATTRIBUTENAME_USER); if (currentUser == null) throw new LoginException("??"); cash.setPlatformMoneymoremore(innerThirdPaySupportService.getPlatformMoneymoremore()); cash.setAmount(amount); Integer cashStreamId = null; String cardNo = null; gpps.model.CardBinding cardBinding = null; if (currentUser instanceof Lender) { Lender lender = (Lender) currentUser; cash.setWithdrawMoneymoremore(lender.getThirdPartyAccount()); cashStreamId = accountService.cashLenderAccount(lender.getAccountId(), BigDecimal.valueOf(Double.valueOf(amount)), "??"); cardBinding = cardBindingDao.find(lender.getCardBindingId()); } else if (currentUser instanceof Borrower) { Borrower borrower = (Borrower) currentUser; // ??payback List<Integer> states = new ArrayList(); states.add(PayBack.STATE_REPAYING); states.add(PayBack.STATE_WAITFORCHECK); int count = payBackDao.countByBorrowerAndState(borrower.getAccountId(), states, -1, -1); if (count > 0) throw new IllegalOperationException( "????."); cash.setWithdrawMoneymoremore(borrower.getThirdPartyAccount()); cashStreamId = accountService.cashBorrowerAccount(borrower.getAccountId(), BigDecimal.valueOf(Double.valueOf(amount)), "??"); cardBinding = cardBindingDao.find(borrower.getCardBindingId()); cash.setFeePercent("100"); //???? } else { throw new RuntimeException("????"); } if (cardBinding == null) throw new IllegalOperationException("?"); cardNo = cardBinding.getCardNo(); //// cash.setFeeRate("0.0050"); // cash.setFeePercent("100"); cash.setCardNo(cardNo); cash.setCardType(String.valueOf(cardBinding.getCardType())); cash.setBankCode(cardBinding.getBankCode()); cash.setBranchBankName(cardBinding.getBranchBankName()); cash.setProvince(cardBinding.getProvince()); cash.setCity(cardBinding.getCity()); cash.setOrderNo(String.valueOf(cashStreamId)); cash.setReturnURL(innerThirdPaySupportService.getReturnUrl() + "/account/cash/response"); if ("1".equals(innerThirdPaySupportService.getAppendFlag())) cash.setNotifyURL(innerThirdPaySupportService.getNotifyUrl() + "/account/cash/response" + "/bg"); else cash.setNotifyURL(innerThirdPaySupportService.getNotifyUrl()); cash.setSignInfo(cash.getSign(innerThirdPaySupportService.getPrivateKey())); RsaHelper rsa = RsaHelper.getInstance(); cash.setCardNo(rsa.encryptData(cardNo, innerThirdPaySupportService.getPublicKey())); return cash; } @Override public Authorize getAuthorize() throws LoginException { Borrower borrower = borrowerService.getCurrentUser(); HttpServletRequest req = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()) .getRequest(); if (borrower == null) throw new LoginException("??"); Authorize authorize = new Authorize(); authorize.setBaseUrl(innerThirdPaySupportService.getBaseUrl(IInnerThirdPaySupportService.ACTION_AUTHORIZE)); authorize.setMoneymoremoreId(borrower.getThirdPartyAccount()); authorize.setPlatformMoneymoremore(innerThirdPaySupportService.getPlatformMoneymoremore()); authorize.setAuthorizeTypeOpen("2"); authorize.setReturnURL(innerThirdPaySupportService.getReturnUrl() + "/account/authorize/response"); if ("1".equals(innerThirdPaySupportService.getAppendFlag())) authorize.setNotifyURL( innerThirdPaySupportService.getNotifyUrl() + "/account/authorize/response" + "/bg"); else authorize.setNotifyURL(innerThirdPaySupportService.getNotifyUrl()); authorize.setSignInfo(authorize.getSign(innerThirdPaySupportService.getPrivateKey())); return authorize; } @Override public Authorize getLenderAuthorize(String loginId) throws LoginException { Borrower borrower = borrowerService.getCurrentUser(); if (borrower == null) throw new LoginException("???"); if (borrower.getPrivilege() != Borrower.PRIVILEGE_PURCHASEBACK) { throw new LoginException("??????"); } if (loginId == null || !loginId.equals(borrower.getCorporationName())) { throw new LoginException("????????"); } HttpServletRequest req = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()) .getRequest(); Lender lender = lenderDao.findByLoginId(loginId); if (lender == null) throw new LoginException("???"); Authorize authorize = new Authorize(); authorize.setBaseUrl(innerThirdPaySupportService.getBaseUrl(IInnerThirdPaySupportService.ACTION_AUTHORIZE)); authorize.setMoneymoremoreId(lender.getThirdPartyAccount()); authorize.setPlatformMoneymoremore(innerThirdPaySupportService.getPlatformMoneymoremore()); authorize.setAuthorizeTypeOpen("2"); authorize.setReturnURL(innerThirdPaySupportService.getReturnUrl() + "/account/lenderauthorize/response"); if ("1".equals(innerThirdPaySupportService.getAppendFlag())) authorize.setNotifyURL( innerThirdPaySupportService.getNotifyUrl() + "/account/lenderauthorize/response" + "/bg"); else authorize.setNotifyURL(innerThirdPaySupportService.getNotifyUrl()); authorize.setSignInfo(authorize.getSign(innerThirdPaySupportService.getPrivateKey())); return authorize; } @Override public void submitForCheckRepay(List<LoanJson> loanJsons, PayBack payback) { if (loanJsons == null || loanJsons.size() == 0) return; String baseUrl = innerThirdPaySupportService.getBaseUrl(IInnerThirdPaySupportService.ACTION_TRANSFER); Map<String, String> params = new HashMap<String, String>(); params.put("PlatformMoneymoremore", innerThirdPaySupportService.getPlatformMoneymoremore()); params.put("TransferAction", "2"); params.put("Action", "2"); params.put("TransferType", "2"); // // // params.put("NeedAudit", "1"); //? params.put("NeedAudit", null); if ("1".equals(innerThirdPaySupportService.getAppendFlag())) params.put("NotifyURL", innerThirdPaySupportService.getNotifyUrl() + "/account/repay/response/bg"); else params.put("NotifyURL", innerThirdPaySupportService.getNotifyUrl()); List<LoanJson> temp = new ArrayList<LoanJson>(); Product product = productService.find(payback.getProductId()); GovermentOrder order = orderService.findGovermentOrderByProduct(payback.getProductId()); for (int i = 0; i < loanJsons.size(); i++) { temp.add(loanJsons.get(i)); if ((i + 1) % 200 == 0) { String LoanJsonList = Common.JSONEncode(temp); params.put("LoanJsonList", LoanJsonList); temp.clear(); sendRepay(params, baseUrl, order, product, payback); } } if (temp.size() > 0) { String LoanJsonList = Common.JSONEncode(temp); params.put("LoanJsonList", LoanJsonList); sendRepay(params, baseUrl, order, product, payback); } } private void sendRepay(Map<String, String> params, String baseUrl, GovermentOrder order, Product product, PayBack payback) { StringBuilder sBuilder = new StringBuilder(); sBuilder.append(StringUtil.strFormat(params.get("LoanJsonList"))); sBuilder.append(StringUtil.strFormat(params.get("PlatformMoneymoremore"))); sBuilder.append(StringUtil.strFormat(params.get("TransferAction"))); sBuilder.append(StringUtil.strFormat(params.get("Action"))); sBuilder.append(StringUtil.strFormat(params.get("TransferType"))); sBuilder.append(StringUtil.strFormat(params.get("NeedAudit"))); sBuilder.append(StringUtil.strFormat(params.get("NotifyURL"))); RsaHelper rsa = RsaHelper.getInstance(); String signInfo = rsa.signData(sBuilder.toString(), innerThirdPaySupportService.getPrivateKey()); params.put("SignInfo", signInfo); try { params.put("LoanNoList", URLEncoder.encode(params.get("LoanJsonList"), "UTF-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } String body = httpClientService.post(baseUrl, params); Gson gson = new Gson(); // //??(Action=2 NeedAudit=1)NotifyURL?JSON???2JSONaction??action=1 // //JSON?? // List returnParams=gson.fromJson(body, List.class); // try { // repayProcessor((Map<String,String>)returnParams.get(1), order, product, payback); // } catch (SignatureException e) { // e.printStackTrace(); // } catch (ResultCodeException e) { // e.printStackTrace(); // } //??(Action=2 NeedAudit=null)??json? Map returnParams = gson.fromJson(body, Map.class); try { repayProcessor((Map<String, String>) returnParams, order, product, payback); } catch (SignatureException e) { e.printStackTrace(); } catch (ResultCodeException e) { e.printStackTrace(); } } private void sendRepayRollback(String LoanJsonList, String notifyURL) { Map<String, String> paramsRollback = new HashMap<String, String>(); try { paramsRollback.put("LoanJsonList", URLEncoder.encode(LoanJsonList, "UTF-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } paramsRollback.put("PlatformMoneymoremore", innerThirdPaySupportService.getPlatformMoneymoremore()); paramsRollback.put("ResultCode", "88"); paramsRollback.put("Message", "?"); StringBuilder sBuilder = new StringBuilder(); sBuilder.append(LoanJsonList); sBuilder.append(StringUtil.strFormat(paramsRollback.get("PlatformMoneymoremore"))); sBuilder.append(StringUtil.strFormat(paramsRollback.get("ResultCode"))); // sBuilder.append(StringUtil.strFormat(paramsRollback.get("Message"))); RsaHelper rsa = RsaHelper.getInstance(); String signInfo = rsa.signData(sBuilder.toString(), innerThirdPaySupportService.getPrivateKey()); paramsRollback.put("SignInfo", signInfo); String body = httpClientService.post(notifyURL, paramsRollback); log.info(body); } public void checkRollBack(Map<String, String> params, String[] signStrs) throws ResultCodeException, SignatureException { String resultCode = params.get("ResultCode"); if (StringUtil.isEmpty(resultCode) || !resultCode.equals("88")) throw new ResultCodeException(resultCode, params.get("Message")); StringBuilder sBuilder = new StringBuilder(); for (String str : signStrs) { sBuilder.append(StringUtil.strFormat(params.get(str))); } RsaHelper rsa = RsaHelper.getInstance(); String sign = rsa.signData(sBuilder.toString(), innerThirdPaySupportService.getPrivateKey()); if (!sign.replaceAll("\r", "").equals(params.get("SignInfo").replaceAll("\r", ""))) throw new SignatureException("???"); } public void checkBuyProcessor(Map<String, String> params) throws SignatureException, ResultCodeException { String[] signStrs = { "LoanNoList", "LoanNoListFail", "PlatformMoneymoremore", "AuditType", "RandomTimeStamp", "Remark1", "Remark2", "Remark3", "ResultCode" }; checkRollBack(params, signStrs); String auditType = params.get("AuditType"); if (!StringUtil.isEmpty(params.get("LoanNoList"))) { String[] loanNoList = params.get("LoanNoList").split(","); for (String loanNo : loanNoList) { List<CashStream> cashStreams = cashStreamDao.findSuccessByActionAndLoanNo(-1, loanNo); if (cashStreams.size() == 2) continue; //?? CashStream cashStream = cashStreams.get(0); try { Integer cashStreamId = null; if (auditType.equals("1")) // { Submit submit = submitService.find(cashStream.getSubmitId()); GovermentOrder order = orderService.findGovermentOrderByProduct(submit.getProductId()); Product product = productService.find(submit.getProductId()); Borrower borrower = borrowerService.find(order.getBorrowerId()); cashStreamId = accountService.pay(cashStream.getLenderAccountId(), borrower.getAccountId(), cashStream.getChiefamount().negate(), cashStream.getSubmitId(), ""); //?lender?? Map<String, String> param = new HashMap<String, String>(); param.put(IMessageService.PARAM_ORDER_NAME, order.getTitle()); param.put(IMessageService.PARAM_PRODUCT_SERIES_NAME, product.getProductSeries().getTitle()); param.put(IMessageService.PARAM_AMOUNT, submit.getAmount().toString()); param.put(ILetterSendService.PARAM_TITLE, "?,?"); try { letterSendService.sendMessage(ILetterSendService.MESSAGE_TYPE_FINANCINGSUCCESS, ILetterSendService.USERTYPE_LENDER, submit.getLenderId(), param); messageService.sendMessage(IMessageService.MESSAGE_TYPE_FINANCINGSUCCESS, IMessageService.USERTYPE_LENDER, submit.getLenderId(), param); } catch (SMSException e) { log.error(e.getMessage()); } } else { Submit submit = submitService.find(cashStream.getSubmitId()); GovermentOrder order = orderService.findGovermentOrderByProduct(submit.getProductId()); Product product = productService.find(submit.getProductId()); cashStreamId = accountService.unfreezeLenderAccount(cashStream.getLenderAccountId(), cashStream.getChiefamount().negate(), cashStream.getSubmitId(), "?"); //?lender?? Map<String, String> param = new HashMap<String, String>(); param.put(IMessageService.PARAM_ORDER_NAME, order.getTitle()); param.put(IMessageService.PARAM_PRODUCT_SERIES_NAME, product.getProductSeries().getTitle()); param.put(IMessageService.PARAM_AMOUNT, submit.getAmount().toString()); param.put(ILetterSendService.PARAM_TITLE, "?,"); try { letterSendService.sendMessage(ILetterSendService.MESSAGE_TYPE_FINANCINGFAIL, ILetterSendService.USERTYPE_LENDER, submit.getLenderId(), param); messageService.sendMessage(IMessageService.MESSAGE_TYPE_FINANCINGFAIL, IMessageService.USERTYPE_LENDER, submit.getLenderId(), param); } catch (SMSException e) { log.error(e.getMessage()); } } cashStreamDao.updateLoanNo(cashStreamId, loanNo, null); } catch (IllegalConvertException e) { e.printStackTrace(); } } } } public void repayProcessor(Map<String, String> params, GovermentOrder order, Product product, PayBack payback) throws SignatureException, ResultCodeException { String[] signStrs = { "LoanJsonList", "PlatformMoneymoremore", "Action", "RandomTimeStamp", "Remark1", "Remark2", "Remark3", "ResultCode" }; String loanJsonList = null; try { loanJsonList = URLDecoder.decode(params.get("LoanJsonList"), "UTF-8"); params.put("LoanJsonList", loanJsonList); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } checkRollBack(params, signStrs); List<Object> loanJsons = Common.JSONDecodeList(loanJsonList, LoanJson.class); if (loanJsons == null || loanJsons.size() == 0) return; for (Object obj : loanJsons) { LoanJson loanJson = (LoanJson) obj; Integer cashStreamId = Integer.parseInt(loanJson.getOrderNo()); String loanNo = loanJson.getLoanNo(); CashStream cashStream = cashStreamDao.find(cashStreamId); if (cashStream.getState() == CashStream.STATE_SUCCESS && loanNo.equals(cashStream.getLoanNo())) { log.debug("???"); continue; } cashStreamDao.updateLoanNo(cashStreamId, loanNo, null); // try { // accountService.changeCashStreamState(cashStreamId, CashStream.STATE_SUCCESS); // // Map<String, String> param = new HashMap<String, String>(); // param.put(IMessageService.PARAM_ORDER_NAME, order.getTitle()); // param.put(IMessageService.PARAM_PRODUCT_SERIES_NAME, product.getProductSeries().getTitle()); // param.put(IMessageService.PARAM_AMOUNT, cashStream.getChiefamount().add(cashStream.getInterest()).toString()); // param.put(ILetterSendService.PARAM_TITLE, ""); // Lender lender = lenderDao.findByAccountID(cashStream.getLenderAccountId()); // // if(lender!=null) // { // try { // letterSendService.sendMessage(ILetterSendService.MESSAGE_TYPE_PAYBACKSUCCESS, ILetterSendService.USERTYPE_LENDER, lender.getId(), param); // messageService.sendMessage(IMessageService.MESSAGE_TYPE_PAYBACKSUCCESS,IMessageService.USERTYPE_LENDER,lender.getId(), param); // } catch (SMSException e) { // log.error(e.getMessage()); // } // } // } catch (IllegalConvertException e) { // e.printStackTrace(); // } } } @Override public void checkCash(Integer cashStreamId) throws IllegalOperationException { CashStream cashStream = cashStreamDao.find(cashStreamId); if (cashStream == null) return; if (cashStream.getAction() != CashStream.ACTION_CASH) throw new IllegalOperationException("????"); if (cashStream.getState() != CashStream.STATE_SUCCESS) throw new IllegalOperationException("?????"); String baseUrl = innerThirdPaySupportService.getBaseUrl(IInnerThirdPaySupportService.ACTION_ORDERQUERY); Map<String, String> params = new HashMap<String, String>(); params.put("PlatformMoneymoremore", innerThirdPaySupportService.getPlatformMoneymoremore()); params.put("Action", "2"); params.put("LoanNo", cashStream.getLoanNo()); StringBuilder sBuilder = new StringBuilder(); sBuilder.append(StringUtil.strFormat(params.get("PlatformMoneymoremore"))); sBuilder.append(StringUtil.strFormat(params.get("Action"))); sBuilder.append(StringUtil.strFormat(params.get("LoanNo"))); RsaHelper rsa = RsaHelper.getInstance(); params.put("SignInfo", rsa.signData(sBuilder.toString(), innerThirdPaySupportService.getPrivateKey())); String body = httpClientService.post(baseUrl, params); Gson gson = new Gson(); Map<String, String> returnParams = gson.fromJson(body, Map.class); try { String withdrawsState = returnParams.get("WithdrawsState"); String loanNo = returnParams.get("LoanNo"); if (withdrawsState.equals("2")) { // accountService.returnCash(Integer.parseInt(returnParams.get("OrderNo")), loanNo); } } catch (NumberFormatException e) { e.printStackTrace(); } catch (IllegalConvertException e) { e.printStackTrace(); } } @Override public String balanceQuery(String thirdPartyAccount) { Map<String, String> params = new HashMap<String, String>(); params.put("PlatformId", thirdPartyAccount); params.put("PlatformMoneymoremore", innerThirdPaySupportService.getPlatformMoneymoremore()); StringBuilder sBuilder = new StringBuilder(); sBuilder.append(thirdPartyAccount); sBuilder.append(innerThirdPaySupportService.getPlatformMoneymoremore()); RsaHelper rsa = RsaHelper.getInstance(); String signInfo = rsa.signData(sBuilder.toString(), innerThirdPaySupportService.getPrivateKey()); params.put("SignInfo", signInfo); String body = null; try { body = httpClientService.post( innerThirdPaySupportService.getBaseUrl(IInnerThirdPaySupportService.ACTION_BALANCEQUERY), params); } catch (Throwable e) { e.printStackTrace(); } return body; } @Override public void checkWithThirdPay(Integer cashStreamId) throws IllegalOperationException, IllegalConvertException { CashStream cashStream = cashStreamDao.find(cashStreamId); if (cashStream == null) return; if (cashStream.getAction() != CashStream.ACTION_CASH && cashStream.getAction() != CashStream.ACTION_FREEZE && cashStream.getAction() != CashStream.ACTION_RECHARGE) return; if (cashStream.getState() == CashStream.STATE_SUCCESS && (cashStream.getAction() == CashStream.ACTION_FREEZE || cashStream.getAction() == CashStream.ACTION_RECHARGE)) return; String baseUrl = innerThirdPaySupportService.getBaseUrl(IInnerThirdPaySupportService.ACTION_ORDERQUERY); Map<String, String> params = new HashMap<String, String>(); params.put("PlatformMoneymoremore", innerThirdPaySupportService.getPlatformMoneymoremore()); if (cashStream.getAction() == CashStream.ACTION_CASH) params.put("Action", "2"); else if (cashStream.getAction() == CashStream.ACTION_RECHARGE) params.put("Action", "1"); params.put("OrderNo", String.valueOf(cashStream.getId())); StringBuilder sBuilder = new StringBuilder(); sBuilder.append(StringUtil.strFormat(params.get("PlatformMoneymoremore"))); sBuilder.append(StringUtil.strFormat(params.get("Action"))); sBuilder.append(StringUtil.strFormat(params.get("OrderNo"))); RsaHelper rsa = RsaHelper.getInstance(); params.put("SignInfo", rsa.signData(sBuilder.toString(), innerThirdPaySupportService.getPrivateKey())); String body = httpClientService.post(baseUrl, params); Gson gson = new Gson(); Map<String, String> returnParams = (Map<String, String>) (gson.fromJson(body, List.class).get(0)); if (cashStream.getAction() == CashStream.ACTION_CASH) { String withdrawsState = returnParams.get("WithdrawsState"); if (withdrawsState.equals("0") || withdrawsState.equals("1")) { if (cashStream.getState() == CashStream.STATE_SUCCESS) return; String loanNo = returnParams.get("LoanNo"); cashStreamDao.updateLoanNo(cashStreamId, loanNo, new BigDecimal(returnParams.get("FeeWithdraws"))); accountService.changeCashStreamState(cashStreamId, CashStream.STATE_SUCCESS); } else if (withdrawsState.equals("2")) { if (cashStream.getState() != CashStream.STATE_SUCCESS) return; String loanNo = returnParams.get("LoanNo"); accountService.returnCash(cashStreamId, loanNo);// } } else if (cashStream.getAction() == CashStream.ACTION_RECHARGE) { if (cashStream.getState() == CashStream.STATE_SUCCESS) return; if (returnParams.get("RechargeState").equals("1")) { //RechargeState:0.;1.?;2. String loanNo = returnParams.get("LoanNo"); cashStreamDao.updateLoanNo(cashStreamId, loanNo, null); accountService.changeCashStreamState(cashStreamId, CashStream.STATE_SUCCESS); } } else if (cashStream.getAction() == CashStream.ACTION_FREEZE) { if (cashStream.getState() == CashStream.STATE_SUCCESS) return; if (returnParams.get("TransferState").equals("1") && (returnParams.get("ActState").equals("3") || returnParams.get("ActState").equals("1"))) { //TransferState:0.;1. //ActState:0.?;1.;2.;3. String loanNo = returnParams.get("LoanNo"); submitService.confirmBuy(cashStream.getSubmitId()); cashStreamDao.updateLoanNo(cashStreamId, loanNo, null); accountService.changeCashStreamState(cashStreamId, CashStream.STATE_SUCCESS); } } } }