一 得到请求参数(即金额、商户号、签名、returnURL、adviceUrl)
commonPayConfig = payMentService.getPaymentHuichao();
//参数得到
configVo = payMentService.getHuichaoparameter(getSession(),charge, commonPayConfig);
(configVo 即请求信息)
二、发送请求
<%@ page contentType="text/html;charset=UTF-8"%>
<html>
<head>
<title>汇潮支付</title>
<meta http-equiv="Content-Type"content="text/html; charset=utf-8">
</head>
<body onLoad="document.E_FORM.submit();">
<form action="https://pay.ecpss.cn/sslpayment"method="post"
name="E_FORM">
//https…. 为回潮支付接口url
<input type="hidden"name="MerNo" value="${configVo.merchantCode}">
<input type="hidden"name="BillNo" value="${configVo.billNo}">
<input type="hidden"name="Amount" value="${configVo.amount}">
<input type="hidden"name="ReturnURL" value="${configVo.returnUrl}">
<input type="hidden"name="AdviceURL" value="${configVo.adviceUrl}">
<input type="hidden"name="MD5info" value="${configVo.md5info}">
<input type="hidden"name="Remark" value="${configVo.remark}">
<input type="hidden"name="shippingFirstName" value="">
<input type="hidden"name="shippingLastName" value="">
<input type="hidden"name="shippingEmail" value="">
<input type="hidden"name="shippingPhone" value="">
<input type="hidden"name="shippingZipcode" value="">
<input type="hidden"name="shippingAddress" value="">
<input type="hidden"name="shippingCity" value="">
<input type="hidden"name="shippingSstate" value="">
<input type="hidden"name="shippingCountry" value="">
<input type="hidden"name="products" value="${configVo.products}">
</form>
</body>
</html>
三、在返回页面(同步returnUrl、异步adviceUrl)进行数据处理(充值。。。等)
(1)returnUrl
package com.ebt.web.fn.network;
import java.math.BigDecimal;
import javax.jms.Session;
import javax.servlet.http.HttpServlet;
importjavax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
importorg.apache.struts2.ServletActionContext;
import com.ebt.domain.fn.Charge;
import com.ebt.domain.fn.VDealerAccount;
import com.ebt.framework.BaseAction;
importcom.ebt.framework.ResubmissionSupport;
importcom.ebt.framework.TransactionSupport;
import com.ebt.pub.AppContext;
import com.ebt.pub.Tools;
import com.ebt.service.fn.AccountService;
import com.ebt.service.fn.ChargeService;
importcom.ebt.service.fn.ChargeServiceFactory;
importcom.ebt.service.fn.EBT2DealerCollectionService;
import com.ebt.vo.fn.CollectionConditionVO;
import com.ebt.vo.fn.EcpssRespEntityVo;
import com.ebt.vo.sys.user.SysUserVO;
/**
* 第三方接口返回接收
*
*@author 梁鹏
*
*/
public class PayReturnAction extendsBaseAction implements TransactionSupport,ResubmissionSupport{
privateChargeService chargeService = ChargeServiceFactory.getChargeService();
privateCollectionConditionVO conditionVo;
privateEBT2DealerCollectionService ebt2DealerCollectionService;
privateBigDecimal afterAmount;
privateAccountService accountService;
Chargecharge;
publicboolean required() {
if(sActionType == null || "".equals(sActionType)) {
returnfalse;
}else {
returntrue;
}
}
protectedString perform() throws Exception {
HttpServletRequestrequest = ServletActionContext.getRequest();
EcpssRespEntityVores = new EcpssRespEntityVo();
res.setBillNo(request.getParameter("BillNo"));
res.setAmount(request.getParameter("Amount"));
res.setResult(request.getParameter("Result"));
res.setMd5info(request.getParameter("MD5info"));
res.setSignMD5info(request.getParameter("SignMD5info"));
res.setSucceed(request.getParameter("Succeed"));
charge= chargeService.getChargeBean("chargeBillNo", res.getBillNo());
if (Tools.eq(res.getSucceed(),"88")){
//修改状态 以及添加流水账 并且 更改虚拟账户余额
if(charge != null){
SysUserVOuser = AppContext.getCurrentUser();
conditionVo= new CollectionConditionVO();
conditionVo.setPartyId(charge.getBelongId());
conditionVo.setRoleType(Long.parseLong(user.getRoleType()));
conditionVo.setReceiveAmount(newBigDecimal(res.getAmount()));
chargeService.synChargeMethod(charge,res,conditionVo,ebt2DealerCollectionService,user);
//页面参数
VDealerAccountaccount = accountService.loadDealerAccount(user.getPartyId());
afterAmount= account.getAmount();
}
return SUCCESS;
}
returnERROR;
}
publicEBT2DealerCollectionService getEbt2DealerCollectionService() {
returnebt2DealerCollectionService;
}
publicvoid setEbt2DealerCollectionService(
EBT2DealerCollectionServiceebt2DealerCollectionService) {
this.ebt2DealerCollectionService= ebt2DealerCollectionService;
}
publicCollectionConditionVO getConditionVo() {
returnconditionVo;
}
publicvoid setConditionVo(CollectionConditionVO conditionVo) {
this.conditionVo= conditionVo;
}
publicBigDecimal getAfterAmount() {
returnafterAmount;
}
publicvoid setAfterAmount(BigDecimal afterAmount) {
this.afterAmount= afterAmount;
}
publicAccountService getAccountService() {
returnaccountService;
}
publicvoid setAccountService(AccountService accountService) {
this.accountService= accountService;
}
publicCharge getCharge() {
returncharge;
}
publicvoid setCharge(Charge charge) {
this.charge= charge;
}
}
(2)adviceUrl
package com.ebt.web.fn.network;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.util.Date;
importjavax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
importorg.apache.commons.beanutils.BeanUtils;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
importorg.apache.struts2.ServletActionContext;
importorg.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
importorg.springframework.transaction.PlatformTransactionManager;
importorg.springframework.transaction.TransactionDefinition;
importorg.springframework.transaction.TransactionStatus;
import org.springframework.transaction.TransactionUsageException;
importorg.springframework.transaction.support.DefaultTransactionDefinition;
importorg.springframework.web.struts.ActionSupport;
import com.ebt.dao.sys.TSysUserDAO;
import com.ebt.dao.sys.TSysUserDAOFactory;
import com.ebt.domain.fn.Charge;
import com.ebt.domain.sys.TSysUser;
importcom.ebt.framework.ApplicationContextUtils;
import com.ebt.pub.Tools;
import com.ebt.service.fn.ChargeService;
importcom.ebt.service.fn.ChargeServiceFactory;
import com.ebt.service.fn.EBT2DealerCollectionService;
import com.ebt.service.fn.TransService;
importcom.ebt.service.fn.impl.EBT2DealerCollectionServiceImpl;
import com.ebt.vo.fn.CollectionConditionVO;
import com.ebt.vo.fn.EcpssRespEntityVo;
public class PayAdviceAction extendsActionSupport{
privateChargeService chargeService = ChargeServiceFactory.getChargeService();
privateCollectionConditionVO conditionVo;
EBT2DealerCollectionServiceebt2DealerCollectionService = new EBT2DealerCollectionServiceImpl();
TSysUserDAOdao = TSysUserDAOFactory.getTSysUserDAO();
publicLogger log = LogManager.getLogger(PayAdviceAction.class);
privatePlatformTransactionManager txService;
privateApplicationContext applicationContext = ApplicationContextUtils.getInstance().getApplicationContext();
privateTransactionStatus transactionStatus;
publicString perform() throws Exception {
//注入对象
inject();
//清空事务信息,为下一次事务做好准备?
TransServicetransService = (TransService) applicationContext
.getBean("transService");
transService.clear();
HttpServletRequestrequest = ServletActionContext.getRequest();
HttpServletResponseresponse = ServletActionContext.getResponse();
EcpssRespEntityVores = new EcpssRespEntityVo();
res.setBillNo(request.getParameter("BillNo"));
res.setAmount(request.getParameter("Amount"));
res.setResult(request.getParameter("Result"));
res.setMd5info(request.getParameter("MD5info"));
res.setSignMD5info(request.getParameter("SignMD5info"));
res.setSucceed(request.getParameter("Succeed"));
Chargecharge = chargeService.getChargeBean("chargeBillNo",res.getBillNo());
log.debug("start-------------------------------PayAdviceAction--------");
if (Tools.eq(res.getSucceed(),"88")){
log.debug("one-------------------------------PayAdviceAction--------");
//修改状态 以及添加流水账 并且 更改虚拟账户余额
if(charge != null){
log.debug("two-------------------------------PayAdviceAction--------");
try{
beginTrans();
TSysUser user = (TSysUser)dao.loadByProperty(TSysUser.class, "partyId",charge.getBelongId()).get(0);
conditionVo= new CollectionConditionVO();
conditionVo.setPartyId(charge.getBelongId());
conditionVo.setRoleType(Long.parseLong(user.getRoleType()));
conditionVo.setReceiveAmount(newBigDecimal(res.getAmount()));
chargeService.synChargeMethod(charge,res,conditionVo,ebt2DealerCollectionService,user);
commitTrans();
}catch (Exception e) {
rollbackTrans();
}
}
response.getWriter().print("ok");
}else{
response.getWriter().print("error!");
}
returnnull;
}
/**
* 开始事务操作
*/
protectedvoid beginTrans() {
txService= (PlatformTransactionManager) applicationContext.getBean("transactionManager");
DefaultTransactionDefinitiondef = new DefaultTransactionDefinition();
def.setName("mytrans");
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
transactionStatus= txService.getTransaction(def);
}
/**
* 提交事务操作
*/
protectedvoid commitTrans() {
if(txService == null || transactionStatus == null) {
thrownew TransactionUsageException("没有开启事务,提交事务失败");
}
txService.commit(transactionStatus);
}
/**
* 回滚事务操作
*/
protectedvoid rollbackTrans() {
if(txService == null || transactionStatus == null) {
thrownew TransactionUsageException("没有开启事务,回滚事务失败");
}
txService.rollback(transactionStatus);
}
publicEBT2DealerCollectionService getEbt2DealerCollectionService() {
returnebt2DealerCollectionService;
}
publicvoid setEbt2DealerCollectionService(
EBT2DealerCollectionServiceebt2DealerCollectionService) {
this.ebt2DealerCollectionService= ebt2DealerCollectionService;
}
/**
* 需要使用注入方法的Service字段后缀
*/
privatestatic final String SERVICE_NAME_POSTFIX = "Service";
/**
* 需要使用注入方法的Dao字段的后缀
*/
privatestatic final String DAO_NAME_POSTFIX = "Dao";
privatevoid inject() {
ActionSupportaction = this;
//获得所有定义的字段的名称
Field[]f = action.getClass().getDeclaredFields();
for(int i = 0; i < f.length; i++) {
StringpropertyName = f[i].getName();
//根据字段的名字,判断是否使用注入方法
//判断依据:
//1 名称格式为 xxxxService,例如:policyService
//2 名称格式为 xxxxDao,例如:prdtDao
if(propertyName.lastIndexOf(SERVICE_NAME_POSTFIX) == propertyName
.length()
-SERVICE_NAME_POSTFIX.length()
||propertyName.lastIndexOf(DAO_NAME_POSTFIX) == propertyName
.length()
-DAO_NAME_POSTFIX.length()) {
try{
//
ObjectbeanInstance = applicationContext
.getBean(propertyName);
if(beanInstance != null) {
BeanUtils.setProperty(action,propertyName,
beanInstance);
log.info("Bean[ " + f[i].getName() + " ] 注入成功");
//f[i].set(action, beanInstance);
}
}catch (BeansException e) {
log.fatal("Bean[ " + f[i].getName() + " ] 没有定义");
}catch (Exception e) {
log.fatal("Bean[ " + f[i].getName() + " ] 注入失败");
log.error("",e);
}
}
}
}
}