開發銀聯聚合支付,需要公司和銀聯有商務合作,銀聯提供支付對接文檔,纔可以。
本人蔘考的文檔:銀聯商務公衆號+服務窗支付接入接口規範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<String, Object> toMap() {
Map<String, Object> map = new HashMap<String, Object>();
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";//