特殊格式的 匯潮支付介面對接
阿新 • • 發佈:2019-01-25
在公司業務中,對接匯潮支付,--------該需求是調用匯潮的支付介面,他們作為中颱,由他們呼叫支付寶介面
在非同步回撥的時候,遇到了“引數通過 post 方式提交, Content-Type: application/x-www-form-urlencoded ”,回撥引數接收不到,無法轉化,的問題。
解決思路如下,以往都是用json的方式,所以在controller裡面寫了@RequestBody,實際是,直接用一個物件接收,不用寫@RequestBody,然後下面在serviceImpl裡面,程式碼轉換。
貼出程式碼
/** * 支付方式非同步通知介面* @param getHcPayRequest 非同步通知獲得json字串 * @return 非同步通知結果 success/fail */ /*匯潮支付--支付方式非同步通知介面*/ public String notifyInfos(HcPayRequest getHcPayRequest) { logger.info("匯潮非同步回撥引數" + JSON.toJSONString(getHcPayRequest)); ParserConfig.getGlobalInstance().setAutoTypeSupport(true);//針對fastjson解析 mq裡面的redis獲取值的解析,不然會出錯String merchantOutOrderNo =getHcPayRequest.getMerchantOutOrderNo();;//商戶訂單號 String merid = getHcPayRequest.getMerid();//商戶號 String msg =getHcPayRequest.getMsg();//訂單的詳細資訊 msg->pay Money String res = null; try { res = URLDecoder.decode(msg,"UTF-8"); } catch (UnsupportedEncodingException e) { logger.error("匯潮非同步回撥引數解碼失敗-" + JSON.toJSONString(msg)); e.printStackTrace(); } JSONObject jsonObject = JSON.parseObject(res); System.out.println(getHcPayRequest.toString()); String orderNo =getHcPayRequest.getOrderNo();//平臺訂單號 String orderMoney = (String)jsonObject.get( "payMoney" );// 支付金額 /** * 通知引數樣例: * 在匯潮的介面文件裡面有這個 * merchantOutOrderNo=2017091316410597&merid= * yft2017082500005&msg={"payMoney":"1.00"}&noncestr=adfasdfqwer&orderNo=20170913164 * 1128501&payResult=1&sign= 078c2637c96d714880fdb3364d440b51 */ String trasactionId = orderNo;//平臺訂單編號 比如支付寶平臺 try { if (redisTemplate.hasKey(Constants.HC_PREFIX + trasactionId)) { //放進Redis logger.info("hcpay有重複通知" + trasactionId); return "success"; } else { redisTemplate.opsForValue().set(Constants.HC_PREFIX + trasactionId, "1", 2880, TimeUnit.MINUTES); } } catch (Exception e) { e.printStackTrace(); logger.error("hcpay寫redis出錯" + e.getMessage()); } HcPayRequest hcPayRequestnew = new HcPayRequest(); hcPayRequestnew.setMerchantOutOrderNo(merchantOutOrderNo); hcPayRequestnew.setOrderNo(orderNo); hcPayRequestnew.setAmount(orderMoney); EvaFeeInfo evaFeeInfoNew =(EvaFeeInfo)redisTemplate.opsForValue().get(Constants.HC_PREFIX +Constants.PAY_PG+ merchantOutOrderNo); if(evaFeeInfoNew!=null){ logger.info("hc匯潮支付redis獲取的param" + JSON.toJSONString(evaFeeInfoNew)); if (Constants.PAY_PG.equals(evaFeeInfoNew.getFlag())) {//評估費 EvaFeeInfo evaFeeInfo = new EvaFeeInfo(); evaFeeInfo.setEvaAmount(evaFeeInfoNew.getEvaAmount());// evaFeeInfo.setUserId(evaFeeInfoNew.getUserId());// evaFeeInfo.setMobile(evaFeeInfoNew.getMobile());// evaFeeInfo.setCouponId(evaFeeInfoNew.getCouponId());// evaFeeInfo.setRepayNo(orderNo); evaFeeInfo.setTradeNo(evaFeeInfoNew.getTradeNo());//商家唯一標示 訂單號 evaFeeInfo.setCurrentCash(evaFeeInfoNew.getCurrentCash());// evaFeeInfo.setIsUseCash(evaFeeInfoNew.getIsUseCash());// hcPayRequestnew.setFlag(Constants.PAY_PG); try { logger.info("評估費傳送rabbitmq"); rabbitmqProducerProxy.convertAndSend("evaFee.ibank", evaFeeInfo); } catch (Exception e) { e.printStackTrace(); } } } RecFeeInfo recFeeInfoNew =(RecFeeInfo)redisTemplate.opsForValue().get(Constants.HC_PREFIX +Constants.PAY_TJ+merchantOutOrderNo); if(recFeeInfoNew!=null){ logger.info("hc匯潮支付redis獲取的param" + JSON.toJSONString(recFeeInfoNew)); if (Constants.PAY_TJ.equals(recFeeInfoNew.getFlag())) {//推薦費 RecFeeInfo recFeeInfo = new RecFeeInfo(); recFeeInfo.setRecAmount(recFeeInfoNew.getRecAmount());// recFeeInfo.setUserId(recFeeInfoNew.getUserId());// recFeeInfo.setMobile(recFeeInfoNew.getMobile());// recFeeInfo.setBorrowPeriods(recFeeInfoNew.getBorrowPeriods());//借款週期// recFeeInfo.setLoanAmount(recFeeInfoNew.getLoanAmount());// // recFeeInfo.setType(hcPayRequest.getType());-------------------------------------------- recFeeInfo.setRepayNo(orderNo);// recFeeInfo.setTradeNo(recFeeInfoNew.getTradeNo());//商家唯一標示 訂單號 recFeeInfo.setCouponId(recFeeInfoNew.getCouponId());// recFeeInfo.setAppCodeList(recFeeInfoNew.getAppCodeList());// recFeeInfo.setCurrentCash(recFeeInfoNew.getCurrentCash());// recFeeInfo.setIsUseCash(recFeeInfoNew.getIsUseCash());// hcPayRequestnew.setFlag(Constants.PAY_TJ); try { logger.info("推薦費傳送rabbitmq order"); rabbitmqProducerProxy.convertAndSend("recFee.ibank", recFeeInfo); //去掉 發給 user的推薦費 // logger.info("推薦費傳送rabbitmq user"); // rabbitmqProducerProxy.convertAndSend("recUser.ibank", recFeeInfo); } catch (Exception e) { e.printStackTrace(); } } } RechargeFeeInfo rechargeFeeInfoNew =(RechargeFeeInfo)redisTemplate.opsForValue().get(Constants.HC_PREFIX + Constants.PAY_XJ +merchantOutOrderNo); if(rechargeFeeInfoNew!=null){ if(Constants.PAY_XJ.equals(rechargeFeeInfoNew.getFlag())){//充值現金券 RechargeFeeInfo rechargeFeeInfo = new RechargeFeeInfo(); rechargeFeeInfo.setAccountNumber(rechargeFeeInfoNew.getAccountNumber());//手機號// rechargeFeeInfo.setAmount(rechargeFeeInfoNew.getAmount());// rechargeFeeInfo.setCashId(rechargeFeeInfoNew.getCashId());// rechargeFeeInfo.setOperStatus(1);// /**充值是否成功 0:失敗 1:成功*/ rechargeFeeInfo.setRechargeFlowNo(orderNo); rechargeFeeInfo.setTradeNo(rechargeFeeInfoNew.getTradeNo());//商家唯一標示 訂單號 rechargeFeeInfo.setStatusMsg("1");//匯潮支付 1 為成功(目前只有成功才通知) hcPayRequestnew.setFlag(Constants.PAY_XJ); try { logger.info("hc匯潮支付充值現金券傳送rabbitmq order"); rabbitmqProducerProxy.convertAndSend("rechargeFee.ibank", rechargeFeeInfo); } catch (Exception e) { e.printStackTrace(); logger.error("hc匯潮支付現金券充值 異常", e); } } } payLogService.saveHcPay(hcPayRequestnew,Constants.REPAY_STATUS_ZERO ); logger.info("匯潮支付支付成功" + orderNo); return "success"; }
/** * 支付方式非同步通知介面 * @param getHcPayRequest 非同步通知獲得json字串 * @return 非同步通知結果 success/fail */ /*匯潮支付--支付方式非同步通知介面*/ @RequestMapping(value = "/notifyInfos",method = RequestMethod.POST) public String notifyInfos( HcPayRequest getHcPayRequest){ String toSuccessOrFail = hcPayService.notifyInfos(getHcPayRequest); return toSuccessOrFail; }