Java教程

java聚合支付之建行

本文主要是介绍java聚合支付之建行,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

前缀:

       因为工作的需要,需要聚合支付来完成收费,因为本人写过工行聚合支付,来对比一下俩家聚合支付,工行聚合文档网上直接有(https://open.icbc.com.cn/icbc/apip/service.html),建行的话,还得申请,有银行人员给你。工行文档比较方便看,知道自己干嘛,都不需要问工行人员,唯一一点不好的就是,工行回调地址必须是80或者443端口,不知道最近工行有没有改变,20年的时候是需要指定的端口才能回调。建行的文档就是分的太细了,害我走了好多冤枉路,不得不吐槽一下,回调地址建行比较好,没有什么要求,废话不多说,直接上代码吧。

1.pom坐标

    

     <!-- https://mvnrepository.com/artifact/com.sun.xml.ws/jaxws-rt -->
        <dependency>
            <groupId>com.sun.xml.ws</groupId>
            <artifactId>jaxws-rt</artifactId>
            <version>2.3.0</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <version>2.1.2</version>
        </dependency>
        <dependency>
        <groupId> com.sun.xml.bind</groupId>
        <artifactId> jaxb-core</artifactId>
        <version> 2.2.11</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/javax.xml.bind/activation -->
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>activation</artifactId>
            <version>1.0.2</version>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.1</version>
        </dependency>
        <!--colletion集合-->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-collections4</artifactId>
            <version>4.3</version>
        </dependency>
        <!--xml注解-->
        <dependency>
            <groupId>com.thoughtworks.xstream</groupId>
            <artifactId>xstream</artifactId>
            <version>1.4.10</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/commons-httpclient/commons-httpclient -->
        <!--httpclientt-->
        <dependency>
            <groupId>commons-httpclient</groupId>
            <artifactId>commons-httpclient</artifactId>
            <version>3.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.74</version>
        </dependency>

  2.建行提供的工具类

  1)HttpClientUtil ===》用来访问建行接口

package com.baiyou.qrcode.util;


import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;


import java.io.IOException;
import java.util.Iterator;
import java.util.Map;

public class HttpClientUtil {


	public static String httpReader(String url, String code){
		System.out.println("GetPage:"+url);
		
		HttpClient client = new HttpClient();
		GetMethod method = new GetMethod(url);
		
		String result = null;
		try {
			client.executeMethod(method);
			int status = method.getStatusCode();
			if (status == HttpStatus.SC_OK) {
				result = method.getResponseBodyAsString();
			} else {
				System.out.println("Method failed: " + method.getStatusLine());
			}
		} catch (HttpException e) {
			System.out.println("Please check your provided http address!");
			e.printStackTrace();
		} catch (IOException e) {
		
			e.printStackTrace();
		} finally{
			if(method!=null)method.releaseConnection();
			method = null;
			client = null;
		}
		return result;
	}
	
	public static String httpGet(String url,String code) {
		System.out.println("GetPage:"+url);
		String content = null;
		HttpClient httpClient = new HttpClient();
		httpClient.getParams().setParameter(HttpMethodParams.USER_AGENT,"Mozilla/5.0 (X11; U; Linux i686; zh-CN; rv:1.9.1.2) Gecko/20090803 Fedora/3.5.2-2.fc11 Firefox/3.5.2");
		GetMethod method = new GetMethod(url);
		try {
			int statusCode = httpClient.executeMethod(method);
			System.out.println("httpClientUtils::statusCode="+statusCode);
			System.out.println(method.getStatusLine());
			content = new String(method.getResponseBody(), code);
			
		} catch (Exception e) {
			System.out.println("time out");
			e.printStackTrace();
		} finally {
			if(method!=null)method.releaseConnection();
			method = null;
			httpClient = null;
		}
		return content;
	}
	
	public static String httpPost(String url, Map paramMap, String code) {
		System.out.println("GetPage:"+url);
		String content = null;
		if (url == null || url.trim().length() == 0 || paramMap == null
				|| paramMap.isEmpty())
			return null;
		HttpClient httpClient = new HttpClient();

		httpClient.getParams().setParameter(HttpMethodParams.USER_AGENT,"Mozilla/5.0 (X11; U; Linux i686; zh-CN; rv:1.9.1.2) Gecko/20090803 Fedora/3.5.2-2.fc11 Firefox/3.5.2");//

		
		PostMethod method = new PostMethod(url);
		Iterator it = paramMap.keySet().iterator();
		while (it.hasNext()) {
			String key = it.next() + "";
			Object o = paramMap.get(key);
			if (o != null && o instanceof String) {
				method.addParameter(new NameValuePair(key, o.toString()));
			}
			if (o != null && o instanceof String[]) {
				String[] s = (String[]) o;
				if (s != null)
					for (int i = 0; i < s.length; i++) {
						method.addParameter(new NameValuePair(key, s[i]));
					}
			}
		}
		try {
			int statusCode = httpClient.executeMethod(method);
			System.out.println("httpClientUtils::statusCode="+statusCode);
			System.out.println(method.getStatusLine());
			content = new String(method.getResponseBody(), code);
			
		} catch (Exception e) {
			System.out.println("time out");
			e.printStackTrace();
		} finally {
			if(method!=null)method.releaseConnection();
			method = null;
			httpClient = null;
		}
		return content;

	}

	public static String httpPost(String url, Map paramMap) {

		return HttpClientUtil.httpPost(url, paramMap, "UTF-8");
	}
}

2)MD5

package com.baiyou.qrcode.util;

import java.io.*;
import java.security.*;

public class MD5 {

    public static String md5Str(String str)
    {
        if (str == null)return "";
        return md5Str(str, 0);
    }


    /**
     * 计算消息摘要。
     * @param data 计算摘要的数据。
     * @param offset 数据偏移地址。
     * @param length 数据长度。
     * @return 摘要结果。(16字节)
     */
    public static String md5Str(String str, int offset)
    {
        try
        {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            byte[] b = str.getBytes("UTF8");
            md5.update(b, offset, b.length);
            return byteArrayToHexString(md5.digest());
        }
        catch (NoSuchAlgorithmException ex)
        {
            ex.printStackTrace();
            return null;
        }
        catch (UnsupportedEncodingException ex)
        {
            ex.printStackTrace();
            return null;
        }
    }

    /**
     *
     * @param b byte[]
     * @return String
     */
    public static String byteArrayToHexString(byte[] b)
    {
        String result = "";
        for (int i = 0; i < b.length; i++)
        {
            result += byteToHexString(b[i]);
        }
        return result;
    }

    private static String[] hexDigits =
            {
                    "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b",
                    "c", "d", "e", "f"};

    /**
     * 将字节转换为对应的16进制明文
     * @param b byte
     * @return String
     */
    public static String byteToHexString(byte b)
    {
        int n = b;
        if (n < 0)
        {
            n = 256 + n;
        }
        int d1 = n / 16;
        int d2 = n % 16;
        return hexDigits[d1] + hexDigits[d2];
    }

}

3)获取明天日期字符串

package com.baiyou.qrcode.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 获取明天时间
 * @author yangjie
 *
 */
public class TomorrowUtil {
    /**
     * 获取明天的日期字符串
     * @return
     */
    public static String tomorrowDateStr(){
        Date date=new Date();//取时间
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        //把日期往后增加一天.整数往后推,负数往前移动
        calendar.add(calendar.DATE,1);

        //这个时间就是日期往后推一天的结果
        date=calendar.getTime();

        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
        String tomorrowStr = formatter.format(date);
        return tomorrowStr;
    }
}

 

2.生成二维码方法和查询是否支付方法

package com.baiyou.qrcode.jianghang;


import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Map;
import com.baiyou.qrcode.pojo.CrcodeResponse;
import com.baiyou.qrcode.pojo.Document;
import com.baiyou.qrcode.util.HttpClientUtil;
import com.baiyou.qrcode.util.MD5;
import com.baiyou.qrcode.util.TomorrowUtil;

import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;

/**
 * 建行二维码相关接口
 * @author yangjie
 *
 */
public class JIanghang {

	Logger logger = LoggerFactory.getLogger(JIanghang.class);
	/**
	 * 商户代码
	 */
	private static String MERCHANTID="";
	/**
	 * 商户柜台代码
	 */
	private static String  POSID="";
	/**
	 * 分行代码
	 */
	private  static String   BRANCHID="";
	/**
	 * 公钥  后九位
	 */
	private static String PUB32TR2= "";
	/**
	 * 操作员编号
	 */
	private static  String   USER_ID="";
	/**
	 * 操作员密码
	 */
	private static  String   PASSWORD="";

	private static   String   bankURL="https://ibsbjstar.ccb.com.cn/CCBIS/ccbMain";
	/**
	 * 日志
	 */
	/**
	 * 生成二维码
	 * @param ORDERID  订单号 (商户代码后 9 位+自定义字符串(21位))
	 * @param PAYMENT   金额
	 */
	public  void   createQrCode(String ORDERID,  String  PAYMENT) {
		logger.info("==================================生成二维码===================================");
		logger.info("入参:ORDERID:"+ORDERID+"\t"+"PAYMENT:"+PAYMENT);
		//建行访问路径
		//币种
		String CURCODE="01";
		//建行交易码  统一为530550
		String TXCODE = "530550";
		//备注1
		String REMARK1 = "";
		//备注2
		String REMARK2 = "";
		/**
		 * 返回类型   0或空:返回二维码页面,只支持建行龙支付;
		 1:返回 JSON 格式【二维码信息串】,只支持建行龙支付;
		 2:返回聚合扫码二维码页面;
		 3:返回聚合扫码 JSON格式【二维码信息串】聚合扫码只能上送 2 或 3
		 4:返回聚合银联二维码信息串
		 */
		String RETURNTYPE="3";
		//失效时间     格式YYYYMMDDHHMMSS
		String TIMEOUT = TomorrowUtil.tomorrowDateStr();
		StringBuffer tmp = new StringBuffer(); //验签字段
		tmp.append("MERCHANTID=");
		tmp.append(this.MERCHANTID);
		tmp.append("&POSID=");
		tmp.append(this.POSID);
		tmp.append("&BRANCHID=");
		tmp.append(this.BRANCHID);
		tmp.append("&ORDERID=");
		tmp.append(ORDERID);
		tmp.append("&PAYMENT=");
		tmp.append(PAYMENT);
		tmp.append("&CURCODE=");
		tmp.append(CURCODE);
		tmp.append("&TXCODE=");
		tmp.append(TXCODE);
		tmp.append("&REMARK1=");
		tmp.append(REMARK1);
		tmp.append("&REMARK2=");
		tmp.append(REMARK2);
		tmp.append("&RETURNTYPE=");
		tmp.append(RETURNTYPE);
		tmp.append("&TIMEOUT=");
		tmp.append(TIMEOUT);
		tmp.append("&PUB=");
		tmp.append(this.PUB32TR2);

		Map map = new HashMap();
		map.put("CCB_IBSVersion","V6");	//必输项
		map.put("MERCHANTID",MERCHANTID);
		map.put("BRANCHID",BRANCHID);
		map.put("POSID",POSID);
		map.put("ORDERID",ORDERID);
		map.put("PAYMENT",PAYMENT);
		map.put("CURCODE",CURCODE);
		map.put("TXCODE",TXCODE);
		map.put("REMARK1",REMARK1);
		map.put("REMARK2",REMARK2);
		map.put("RETURNTYPE",RETURNTYPE);
		map.put("TIMEOUT",TIMEOUT);
		map.put("MAC", MD5.md5Str(tmp.toString()));
		//请求二维码生成链接串
		logger.info("入参:"+map);
		String post = HttpClientUtil.httpPost(this.bankURL, map);
		logger.info("第一次响应的信息:"+post);
		CrcodeResponse crcodeResponse= JSONObject.parseObject(post,CrcodeResponse.class);
		if(crcodeResponse.getSUCCESS()!=null   &&  crcodeResponse.getSUCCESS().equals("true") ) {
			try {
				String   payUrl=crcodeResponse.getPAYURL();
				String   response=HttpClientUtil.httpGet(payUrl, "utf-8");
				String qrurl = JSONObject.parseObject(response).getString("QRURL");
				String decode = URLDecoder.decode(qrurl, "utf-8");
				logger.info("二维码信息:"+decode);
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	/**
	 * 查询支付是否成功
	 * @param ORDERDATE  订单时间
	 * @param ORDERID   订单号码
	 */
	//服务器反馈
	public  void  searchIsPayForWeb(String ORDERDATE,String ORDERID) {
		logger.info("===========================================查询商户是否支付成功====================");
		logger.info("入参:ORDERDATE"+ORDERDATE+"\t"+"ORDERID:"+ORDERID);
		//商户代码
		// String MERCHANTID ="";
		//分行代码
		//  String BRANCHID="";
		//柜台号
		//String POSID="";
		//订单日期   ORDERDATE 与 ORDERID 必须有一个输入
		// String ORDERDATE="20160811";
		//起始时间   元素必须有,但值可为空
		String BEGORDERTIME="00:00:00";
		//订单截止时间   元素必须有,但值可为空
		String ENDORDERTIME="23:59:59";
		//订单号   元素必须有,但值可为空
		// String ORDERID = "";
		//查询密码    必输项,主管或操作员的登录密码
		String QUPWD="";
		//流水类型 TYPE   必输项  0支付流水   1退款流水
		String TYPE="0";
		//交易码
		String TXCODE="410408";
		//流水状态  必须项    0未结算流水    1已结算流水
		String KIND="0";
		//交易状态    必须项   0失败   1成功   2不确定   3全部    已结算流水查询不支持全部
		String STATUS="1";
		//  查询方式 SEL_TYPE     必输项   1页面形式   2文件返回形式   3xml页面形式
		String SEL_TYPE="3";
		//页码page
		String PAGE = "1";
		//操作员
		String OPERATOR="";
		String BEGORDERID="";
		String ENDORDERID="";
		//预留字段
		String CHANNEL = "";
		String bankURLSearch="https://ibsbjstar.ccb.com.cn/app/ccbMain";

		String param ="MERCHANTID="+this.MERCHANTID+"&BRANCHID="+this.BRANCHID+"&POSID="+this.POSID+"&ORDERDATE="+ORDERDATE+"&BEGORDERTIME="+BEGORDERTIME
				+"&ENDORDERTIME="+ENDORDERTIME+"&BEGORDERID="+BEGORDERID+"&ENDORDERID="+ENDORDERID+"&QUPWD=&TXCODE="+TXCODE
				+"&SEL_TYPE="+SEL_TYPE+"&OPERATOR="+OPERATOR;
		if("410408".equals(TXCODE)){
			param ="MERCHANTID="+MERCHANTID+"&BRANCHID="+BRANCHID+"&POSID="+POSID+"&ORDERDATE="
					+ORDERDATE+"&BEGORDERTIME="+BEGORDERTIME+"&ENDORDERTIME="+ENDORDERTIME+"&ORDERID="
					+ORDERID+"&QUPWD=&TXCODE="+TXCODE+"&TYPE="+TYPE+"&KIND="+KIND+"&STATUS="+STATUS+
					"&SEL_TYPE="+SEL_TYPE+"&PAGE="+PAGE+"&OPERATOR="+OPERATOR+"&CHANNEL="+CHANNEL;
		}
		Map map = new HashMap();
		map.put("MERCHANTID",this.MERCHANTID);

		map.put("BRANCHID",this.BRANCHID);
		map.put("POSID",this.POSID);

		map.put("ORDERDATE",ORDERDATE);

		map.put("BEGORDERTIME",BEGORDERTIME);

		map.put("ENDORDERTIME",ENDORDERTIME);

		map.put("BEGORDERID",BEGORDERID);

		map.put("ENDORDERID",ENDORDERID);

		map.put("QUPWD",QUPWD);

		map.put("TXCODE",TXCODE);

		if("410408".equals(TXCODE)){
			map.put("TYPE",TYPE);
			map.put("KIND",KIND);
			map.put("STATUS",STATUS);
			map.put("ORDERID",ORDERID);
			map.put("PAGE",PAGE);
			map.put("CHANNEL",CHANNEL);
		}
		map.put("SEL_TYPE",SEL_TYPE);

		map.put("OPERATOR",OPERATOR);
		map.put("MAC",MD5.md5Str(param));
		logger.info("入参"+map);
		String ret = HttpClientUtil.httpPost(bankURLSearch, map);
		ret = ret.replaceAll("\\n", "").
				replaceAll("\\t", "").
				replaceAll("\\r", "");

	    if(ret !=null   &&  !ret.equals("")){
			JAXBContext jaxbContext=null;
			Unmarshaller unmarshaller=null;
			Document document=null;
	    	try {
				logger.info("ret::"+ret);
				jaxbContext = JAXBContext.newInstance(Document.class);
				unmarshaller = jaxbContext.createUnmarshaller();
				document= (Document)unmarshaller.unmarshal(new StringReader(ret));
				logger.info("document==={}"+document);
			}catch (Exception   e){
	    		e.printStackTrace();
			}
		}
	}


}

 

3.实体类

1)建行生成二维码第一次响应实体类

package com.baiyou.qrcode.pojo;

import java.io.Serializable;

/**
 * 建行响应信息
 * @author yangjie
 *
 */
public class CrcodeResponse  implements Serializable{
	/**
	 * 响应成功信息
	 */
	private  String  SUCCESS;
	/**
	 *二次请求路径
	 */
	private   String   PAYURL;
	public String getSUCCESS() {
		return SUCCESS;
	}
	public void setSUCCESS(String sUCCESS) {
		SUCCESS = sUCCESS;
	}
	public String getPAYURL() {
		return PAYURL;
	}
	public void setPAYURL(String pAYURL) {
		PAYURL = pAYURL;
	}
}

2)回调入参的实体类

package com.baiyou.qrcode.pojo;

import lombok.Data;

import java.io.Serializable;

@Data
public class PayCallBackEntity  implements Serializable {
    private String POSID; //商户柜台代码
    private String BRANCHID;//分行代码
    private String ORDERID; //定单号
    private String PAYMENT; //付款金额
    private String CURCODE;  //币种
    private String REMARK1;  //备注一
    private String REMARK2;  //备注二
    private String ACC_TYPE;  //账户类型  服务器通知中有此字段返回且参与验签
    private String SUCCESS;  //成功标志  成功-Y,失败-N
    private String TYPE;   //接口类型  分行业务人员在P2员工渠道后台设置防钓鱼的开关。 1.开关关闭时,无此字段返回且不参与验签 2.开关打开时,有此字段返回且参与验签。参数值为 1-防钓鱼接口

    private String REFERER;  //Referer信息  分行业务人员在P2员工渠道后台设置防钓鱼开关。 1.开关关闭时,无此字段返回且不参与验签。 2.开关打开时,有此字段返回且参与验签
    private String CLIENTIP;  //客户端IP  分行业务人员在P2员工渠道后台设置防钓鱼的开关。 1.开关关闭时,无此字段返回且不参与验签 2.开关打开时,有此字段返回且参与验签。参数值为 客户在建行系统中的IP
    private String ACCDATE;  //系统记账日期  商户登陆商户后台设置返回记账日期的开关 1.开关关闭时,无此字段返回且不参与验签。 2.开关打开时,有此字段返回且参与验签。参数值格式为YYYYMMDD(如20100907)。
    private String USRMSG; //支付账户信息  分行业务人员在P2员工渠道后台设置防钓鱼开关和返回账户信息的开关。 1.开关关闭时,无此字段返回且不参与验签。2.开关打开但支付失败时,无此字段返回且不参与验签。3.开关打开且支付成功时,有此字段返回且参与验签。无PAYTYPE返回时,参数值格式如下:“姓名|账号加密后的密文”。有PAYTYPE返回时,该参数值为空。
    private String USRINFO;   //客户加密信息   分行业务人员在P2员工渠道后台设置防钓鱼开关和客户信息加密返回的开关。 1.开关关闭时,无此字段返回且不参与验签
    private String PAYTYPE;  //支付方式   ALIPAY:支付宝 WEIXIN:微信 为空:建行龙支付 该字段有返回时参与验签,无此字段返回时不参与验签。
    private String SIGN;  //数字签名
}

3)建行回调的信息,将xml转化实体类

package com.baiyou.qrcode.pojo;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import java.util.ArrayList;
import java.util.List;

/**
 * 查询建行响应的类
 */
@XmlRootElement(name = "DOCUMENT")
public class Document {
    /**
     * 返回码   交易返回码,成功时总为 000000
     */
    @XmlElement(name = "RETURN_CODE")
    private String   RETURN_CODE;
    /**
     * 响应信息
     */
    @XmlElement(name = "RETURN_MSG")
    private   String   RETURN_MSG;
    /**
     * 当前页
     */
    @XmlElement(name = "CURPAGE")
    private String    CURPAGE;
    /**
     * 总页数
     */
    @XmlElement(name = "PAGECOUNT")
    private   String   PAGECOUNT;
    /**
     * 总笔数
     */
    @XmlElement(name = "TOTAL")
     private   String   TOTAL;
    /**
     * 支付总金额
     */
    @XmlElement(name = "PAYAMOUNT")
    private   String    PAYAMOUNT;
    /**
     * 退款总金额
     */
    @XmlElement(name = "REFUNDAMOUNT")
    private   String    REFUNDAMOUNT;

    @XmlElement(name = "QUERYORDER")
    private List<QueryOrder>  queryOrders=new ArrayList<>();
     @XmlTransient
    public String getRETURN_CODE() {
        return RETURN_CODE;
    }

    public void setRETURN_CODE(String RETURN_CODE) {
        this.RETURN_CODE = RETURN_CODE;
    }
    @XmlTransient
    public String getRETURN_MSG() {
        return RETURN_MSG;
    }

    public void setRETURN_MSG(String RETURN_MSG) {
        this.RETURN_MSG = RETURN_MSG;
    }
    @XmlTransient
    public String getCURPAGE() {
        return CURPAGE;
    }

    public void setCURPAGE(String CURPAGE) {
        this.CURPAGE = CURPAGE;
    }
    @XmlTransient
    public String getPAGECOUNT() {
        return PAGECOUNT;
    }

    public void setPAGECOUNT(String PAGECOUNT) {
        this.PAGECOUNT = PAGECOUNT;
    }
    @XmlTransient
    public String getTOTAL() {
        return TOTAL;
    }

    public void setTOTAL(String TOTAL) {
        this.TOTAL = TOTAL;
    }
    @XmlTransient
    public String getPAYAMOUNT() {
        return PAYAMOUNT;
    }

    public void setPAYAMOUNT(String PAYAMOUNT) {
        this.PAYAMOUNT = PAYAMOUNT;
    }
    @XmlTransient
    public String getREFUNDAMOUNT() {
        return REFUNDAMOUNT;
    }

    public void setREFUNDAMOUNT(String REFUNDAMOUNT) {
        this.REFUNDAMOUNT = REFUNDAMOUNT;
    }
    @XmlTransient
    public List<QueryOrder> getQueryOrders() {
        return queryOrders;
    }

    public void setQueryOrders(List<QueryOrder> queryOrders) {
        this.queryOrders = queryOrders;
    }

    @Override
    public String toString() {
        return "Document{" +
                "RETURN_CODE='" + RETURN_CODE + '\'' +
                ", RETURN_MSG='" + RETURN_MSG + '\'' +
                ", CURPAGE='" + CURPAGE + '\'' +
                ", PAGECOUNT='" + PAGECOUNT + '\'' +
                ", TOTAL='" + TOTAL + '\'' +
                ", PAYAMOUNT='" + PAYAMOUNT + '\'' +
                ", REFUNDAMOUNT='" + REFUNDAMOUNT + '\'' +
                ", queryOrders=" + queryOrders +
                '}';
    }

    /**
     * 子类   详细信息
     */
    public static class  QueryOrder{
        /**
         * 商户代码
         */
        @XmlElement(name = "MERCHANTID")
        private   String    MERCHANTID;
        /**
         * 分行代码
         */
        @XmlElement(name = "BRANCHID")
        private   String   BRANCHID;
        /**
         * 柜台号码
         */
        @XmlElement(name = "POSID")
        private   String   POSID;
        /**
         * 订单号
         */
        @XmlElement(name = "ORDERID")
        private   String  ORDERID;
        /**
         * 支付/退款交易时间
         */
        @XmlElement(name = "ORDERDATE")
        private   String  ORDERDATE;
        /**
         * 记录日期
         */
        @XmlElement(name = "ACCDATE")
        private   String    ACCDATE;
        /**
         * 支付金额
         */
        @XmlElement(name = "AMOUNT")
        private   String   AMOUNT;
        /**
         * 支付、退款状态
         */
        @XmlElement(name = "STATUSCODE")
        private  String   STATUSCODE;
        /**
         * 退款金额
         */
        @XmlElement(name = "STATUS")
        private  String  STATUS;
        /**
         * 签名串
         */
        @XmlElement(name = "SIGN")
        private String   SIGN;

        @XmlTransient
        public String getMERCHANTID() {
            return MERCHANTID;
        }

        public void setMERCHANTID(String MERCHANTID) {
            this.MERCHANTID = MERCHANTID;
        }
        @XmlTransient
        public String getBRANCHID() {
            return BRANCHID;
        }

        public void setBRANCHID(String BRANCHID) {
            this.BRANCHID = BRANCHID;
        }
        @XmlTransient
        public String getPOSID() {
            return POSID;
        }

        public void setPOSID(String POSID) {
            this.POSID = POSID;
        }
        @XmlTransient
        public String getORDERID() {
            return ORDERID;
        }

        public void setORDERID(String ORDERID) {
            this.ORDERID = ORDERID;
        }
        @XmlTransient
        public String getORDERDATE() {
            return ORDERDATE;
        }

        public void setORDERDATE(String ORDERDATE) {
            this.ORDERDATE = ORDERDATE;
        }
        @XmlTransient
        public String getACCDATE() {
            return ACCDATE;
        }

        public void setACCDATE(String ACCDATE) {
            this.ACCDATE = ACCDATE;
        }
        @XmlTransient
        public String getAMOUNT() {
            return AMOUNT;
        }

        public void setAMOUNT(String AMOUNT) {
            this.AMOUNT = AMOUNT;
        }
        @XmlTransient
        public String getSTATUSCODE() {
            return STATUSCODE;
        }

        public void setSTATUSCODE(String STATUSCODE) {
            this.STATUSCODE = STATUSCODE;
        }
        @XmlTransient
        public String getSTATUS() {
            return STATUS;
        }

        public void setSTATUS(String STATUS) {
            this.STATUS = STATUS;
        }
        @XmlTransient
        public String getSIGN() {
            return SIGN;
        }

        public void setSIGN(String SIGN) {
            this.SIGN = SIGN;
        }

        @Override
        public String toString() {
            return "QueryOrder{" +
                    "MERCHANTID='" + MERCHANTID + '\'' +
                    ", BRANCHID='" + BRANCHID + '\'' +
                    ", POSID='" + POSID + '\'' +
                    ", ORDERID='" + ORDERID + '\'' +
                    ", ORDERDATE='" + ORDERDATE + '\'' +
                    ", ACCDATE='" + ACCDATE + '\'' +
                    ", AMOUNT='" + AMOUNT + '\'' +
                    ", STATUSCODE='" + STATUSCODE + '\'' +
                    ", STATUS='" + STATUS + '\'' +
                    ", SIGN='" + SIGN + '\'' +
                    '}';
        }
    }
}

4.回调接口

package com.baiyou.qrcode.controller;

import com.baiyou.qrcode.jianghang.JIanghang;
import com.baiyou.qrcode.pojo.PayCallBackEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 建行回调信息
 */
@RestController
@RequestMapping(value = "/lis/qecode")
public class ReposeControlller {
    Logger logger = LoggerFactory.getLogger(ReposeControlller.class);
    /**
     *
     */
    @RequestMapping(value = "/notify")
    public   String   reposeController( PayCallBackEntity   payCallBackEntity, HttpServletResponse  response){
       logger.info("payCallBackEntity ={}"+payCallBackEntity);
        System.out.println("payCallBackEntity = " + payCallBackEntity);
        String success = payCallBackEntity.getSUCCESS();
        String orderId = payCallBackEntity.getORDERID();
        String payment = payCallBackEntity.getPAYMENT();
        logger.info("success: -" + success);
        logger.info("orderId: -" + orderId);
        if ("Y".equals(success)) {
            JIanghang  jIanghang=new JIanghang();
          jIanghang.searchIsPayForWeb("", orderId);
        } else {
            //支付失败
        }
    return "ok";
    }
}

备注:我是基于web接入处理的。你也可以参考https://blog.csdn.net/TimorRed/article/details/105070419这位大佬的,我也是借鉴这位大佬。

这篇关于java聚合支付之建行的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!