先看下支付流程图:
一、跟据接口文档将请求支付平台的参数写成一个实体。
二、充值记录表设计,以及对应的实体
三、页面发起请求,把该充值记录加到充值表中,支付状体为等待支付。组成请求参数的实体,到页面,发起请求。
四、用户支付成功后,立刻调用后台通知URL,注意:此方法需要外网可以访问进来。根据参数修改支付状态,返回给支付平台一个字符串,同时页面显示支付成功
。
五、如果遇到,用户充值成功,但是没有收到支付平台发来的请求情况下,需要一个查账的功能。之前充值的页面显示一个查看支付结果按钮,调用此功能。
/** * 山东高速查账任务 * @param transNo 商户请求的交易流水号 * @param id 商户订单号 * @param checkCount * @return * @throws Exception */ @Override @Transactional(propagation=Propagation.REQUIRED,readOnly=false,rollbackFor={Exception.class,RuntimeException.class}) public Boolean getSpeedPayRechargeInfoByInterface(String transNo,Long id) throws BusinessException{ ICache<String, String> cache = CacheManager.getInstance().getCache(CommonConstant.FIN_SUPPER_APP_INFO_CACHE_UUID); String sa = cache.get("SDGS-SDGS_RECHARGE"); SpeedPayDto dto = JSON.parseObject(sa, SpeedPayDto.class); ProtocolSocketFactory fcty = new MySecureProtocolSocketFactory(); Protocol.registerProtocol("https", new Protocol("https", fcty, 443)); HttpClient client = new HttpClient(); PostMethod post = new PostMethod(dto.getUrl()); post.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8"); String sign = SpeedPayDto.char_set +dto.getPartner_id() +transNo +SpeedPayDto.sign_type +SpeedPayDto.OrderSearch +SpeedPayDto.version_no +id.toString()+dto.getKey(); String mac = MD5Util.MD5Encode(sign, "utf-8"); NameValuePair[] names = { new NameValuePair("char_set", SpeedPayDto.char_set), new NameValuePair("partner_id",dto.getPartner_id()), new NameValuePair("request_id",transNo), new NameValuePair("sign_type",SpeedPayDto.sign_type), new NameValuePair("biz_type",SpeedPayDto.OrderSearch), new NameValuePair("version_no",SpeedPayDto.version_no), new NameValuePair("order_id",id.toString()), new NameValuePair("mac",mac.toLowerCase()) }; post.setRequestBody(names); try { client.executeMethod(post); byte[] str = post.getResponseBody(); String ss = new String(str,"utf-8"); Map<String,String> resultMap = SpeedPayCheckUtil.parseResponseString(ss); String status = resultMap.get("status"); this.isInDbAndStatusUnDo(id); if(StringUtils.isEmpty(status)){ return false; } if(status.equals(SUCCESS)){ FinAutoRechargeEntity finReChargeRecordEntity = this.getEntityByMap(resultMap); finReChargeRecordEntity.setOrderId(id); finReChargeRecordEntity.setStatus("pay_success"); finAutoReChargeDao.updateAutoRechargeByEntity(finReChargeRecordEntity); // this.insertFinOperInfoEntity(id); return true; }else if(status.equals(FAILD)){ FinAutoRechargeEntity finReChargeRecordEntity = this.getEntityByMap(resultMap); finReChargeRecordEntity.setOrderId(id); finReChargeRecordEntity.setStatus("pay_fail"); finAutoReChargeDao.updateAutoRechargeByEntity(finReChargeRecordEntity); } } catch (HttpException e) { log.error(FinRechargeExptionConstant.HTTP_EXP,e); throw new BusinessException(FinRechargeExptionConstant.HTTP_EXP); } catch (IOException e) { log.error(FinRechargeExptionConstant.IO_EXP,e); throw new BusinessException(FinRechargeExptionConstant.IO_EXP); } catch (Exception e) { log.error(FinRechargeExptionConstant.IO_EXP,e); //e.printStackTrace(); throw new BusinessException(e.getMessage()); } return false; }