银联聚合支付

开发银联聚合支付,需要公司和银联有商务合作,银联提供支付对接文档,才可以。

本人参考的文档:银联商务公众号+服务窗支付接入接口规范V2.6.docx

核心代码片段

UnPayRes.java

package com.pay.unionpay.res;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

import com.pay.unionpay.util.SignUtil;
import com.pay.unionpay.util.UnPayConst;

/**
 * 银联支付下单
 * 
 * @author libaibai
 * @version 1.0 
 */
public class UnPayRes {

	private String msgSrc; // 消息来源
	private String requestTimestamp; // 请求报文时间,格式yyyy-MM-dd HH:mm:ss
	private String merOrderId; // 商户订单号
	private String mid; // 商户号
	private String tid; // 终端号

	private String goods; // 商品说明
	private String instMid = UnPayConst.INSTMID; // 业务类型
	private int totalAmount; // 支付金额,单位分
	private String notifyUrl = UnPayConst.NOTIFYURL; // 支付结果通知
//	private String returnUrl; // 支付结果通知

	private String sign; // 签名

	public UnPayRes() {
	}

	public UnPayRes(String msgSrc, String requestTimestamp, String merOrderId, String mid,
			String tid, int totalAmount, String goods, String key) {
		this.msgSrc = msgSrc;
		this.requestTimestamp = requestTimestamp;
		this.merOrderId = merOrderId;
		this.mid = mid;
		this.tid = tid;
		this.totalAmount = totalAmount;
		this.goods = goods;
		this.sign = SignUtil.getSign(toMap(), key);
	}

	public String getMsgSrc() {
		return msgSrc;
	}

	public String getRequestTimestamp() {
		return requestTimestamp;
	}

	public String getMerOrderId() {
		return merOrderId;
	}

	public String getMid() {
		return mid;
	}

	public String getTid() {
		return tid;
	}

	public String getInstMid() {
		return instMid;
	}

	public int getTotalAmount() {
		return totalAmount;
	}

	public String getNotifyUrl() {
		return notifyUrl;
	}

	public String getSign() {
		return sign;
	}

	public void setMsgSrc(String msgSrc) {
		this.msgSrc = msgSrc;
	}

	public void setRequestTimestamp(String requestTimestamp) {
		this.requestTimestamp = requestTimestamp;
	}

	public void setMerOrderId(String merOrderId) {
		this.merOrderId = merOrderId;
	}

	public void setMid(String mid) {
		this.mid = mid;
	}

	public void setTid(String tid) {
		this.tid = tid;
	}

	public void setInstMid(String instMid) {
		this.instMid = instMid;
	}

	public void setTotalAmount(int totalAmount) {
		this.totalAmount = totalAmount;
	}

	public void setNotifyUrl(String notifyUrl) {
		this.notifyUrl = notifyUrl;
	}

	public void setSign(String sign) {
		this.sign = sign;
	}

	public String getGoods() {
		return goods;
	}

	public void setGoods(String goods) {
		this.goods = goods;
	}

	public Map toMap() {
		Map map = new HashMap();
		Field[] fields = this.getClass().getDeclaredFields();
		for (Field field : fields) {
			Object obj;
			try {
				obj = field.get(this);
				if (obj != null) {
					map.put(field.getName(), obj);
				}
			} catch (IllegalArgumentException e) {
			} catch (IllegalAccessException e) {
			}
		}
		return map;
	}

	@Override
	public String toString() {
		return "msgSrc=" + msgSrc + "&requestTimestamp=" + requestTimestamp + "&merOrderId="
				+ merOrderId + "&mid=" + mid + "&tid=" + tid + "&instMid=" + instMid + "&goods="
				+ goods + "&totalAmount=" + totalAmount + "¬ifyUrl=" + notifyUrl + "&sign=" + sign;
	}
}

 

		// 获取银联下单url
		UnPayRes unpayRes = new UnPayRes(UnPayConst.MSGSRC, requestTimestamp, merOrderId, mid, tid, totalAmount, body, 
				UnPayConst.KEY);

		// UnPayService unPayService = JAXRSClientFactory.create(UnPayConst.URL,
		// UnPayService.class);
		// String returnStr = null;
		// try {
		// Response response = unPayService.pay(unpayRes);
		// returnStr = response.readEntity(String.class);
		// } catch (Exception e) {
		// LOG.error("unpayOrder-银联支付下单失败", e);
		// }
		String unPayUrl = UnPayConst.URL + "?" + unpayRes.toString();
		LOG.info("unpayOrder-获取支付unPayUrl=" + unPayUrl);

		returnMap.put("isPay", "1");
		returnMap.put("unPayUrl", unPayUrl);

 

	// 消息来源ID,银联提供,不可随意修改
	public static final String MSGSRC = "WWW.xx.COM";
	public static final String MSGID = "4675";

	// 机构商户号
	public static final String INSTMID = "xxxx";

	// 通讯密钥
	public static final String KEY = "xxxx";

	// 支付地址
	// 测试地址
	// public static final String URL = "https://qr-test2.chinaums.com/netpay-portal/webpay/pay.do";
	// 正式地址
	public static final String URL = "https://qr.chinaums.com/netpay-portal/webpay/pay.do";//

 

 

 

你可能感兴趣的:(银联聚合支付)