1. 程式人生 > >威富通支付接口

威富通支付接口

pan jeecg eve 參數 conf element cms 消息 esp

支付實體類

package cn.rmt.wxbase.vo;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * <br>
 * <b>功能:</b>支付實體類<br>
 * <b>作者:
 * <b>日期:
 *
 */
@SuppressWarnings("serial")
public class PayBaseBean implements Serializable{
    
//發送數據 private String sendData; //接收數據 private String recviceData; //返回狀態 0-成功 1-失敗 private String resultCode; //返回消息 private String resultMessage; //原生態支付信息 private String payInfo; /*********支付平臺配置*********/ //支付平臺key private String rmKey; //支付平臺通訊地址
private String payUrl; /*********商戶平臺請求參數*********/ private Double amount; private Double amountSettle; private String channel; private String tradeType; private String version; private List details; private Map<String,String> extra; private
String tokenIdUrl; /*********請求數據*********/ //接口編號 private String bifCode; //平臺編號 private String pno; //接口流水號 private String pono; //接口類型 private String service; //商戶號(對應威富通的商戶編號) private String mchId; //商戶系統內部的訂單號 private String outTradeNo; //商品描述 private String body; //微信用戶openid private String openId; //支付寶用戶id private String buyerId; //附加數據 private String attach; //總金額,以分為單位 private Double totalFee; //訂單生成的機器IP private String mchCreateIp; //接收支付通知的URL,需給絕對路徑 private String notifyUrl; //交易完成後跳轉的URL,需要給絕對路徑 private String callbackUrl; //隨機字符串 private String nonceStr; //商戶密鑰(對應威富通的商戶密鑰) private String mchKey; //威富通JS支付接口URL private String swiftpassPayUrl; //威富通初始化支付接口URL private String swiftpassInitUrl; //MD5簽名結果;除sign字段外全部累加加密 private String sign; //交易完成後跳轉的URL(輕紡交易園多商戶號模式使用) private String qfjyyCallbackUrl; public String getSendData() { return sendData; } public void setSendData(String sendData) { this.sendData = sendData; } public String getRecviceData() { return recviceData; } public void setRecviceData(String recviceData) { this.recviceData = recviceData; } public String getResultCode() { return resultCode; } public void setResultCode(String resultCode) { this.resultCode = resultCode; } public String getResultMessage() { return resultMessage; } public void setResultMessage(String resultMessage) { this.resultMessage = resultMessage; } public String getBifCode() { return bifCode; } public void setBifCode(String bifCode) { this.bifCode = bifCode; } public String getPno() { return pno; } public void setPno(String pno) { this.pno = pno; } public String getPono() { return pono; } public void setPono(String pono) { this.pono = pono; } public String getService() { return service; } public void setService(String service) { this.service = service; } public String getMchId() { return mchId; } public void setMchId(String mchId) { this.mchId = mchId; } public String getOutTradeNo() { return outTradeNo; } public void setOutTradeNo(String outTradeNo) { this.outTradeNo = outTradeNo; } public String getBody() { return body; } public void setBody(String body) { this.body = body; } public String getOpenId() { return openId; } public void setOpenId(String openId) { this.openId = openId; } public String getAttach() { return attach; } public void setAttach(String attach) { this.attach = attach; } public Double getTotalFee() { return totalFee; } public void setTotalFee(double totalFee) { this.totalFee = totalFee; } public String getMchCreateIp() { return mchCreateIp; } public void setMchCreateIp(String mchCreateIp) { this.mchCreateIp = mchCreateIp; } public String getNotifyUrl() { return notifyUrl; } public void setNotifyUrl(String notifyUrl) { this.notifyUrl = notifyUrl; } public String getCallbackUrl() { return callbackUrl; } public void setCallbackUrl(String callbackUrl) { this.callbackUrl = callbackUrl; } public String getNonceStr() { return nonceStr; } public void setNonceStr(String nonceStr) { this.nonceStr = nonceStr; } public String getMchKey() { return mchKey; } public void setMchKey(String mchKey) { this.mchKey = mchKey; } public String getSwiftpassPayUrl() { return swiftpassPayUrl; } public void setSwiftpassPayUrl(String swiftpassPayUrl) { this.swiftpassPayUrl = swiftpassPayUrl; } public String getSwiftpassInitUrl() { return swiftpassInitUrl; } public void setSwiftpassInitUrl(String swiftpassInitUrl) { this.swiftpassInitUrl = swiftpassInitUrl; } public String getSign() { return sign; } public void setSign(String sign) { this.sign = sign; } public String getRmKey() { return rmKey; } public void setRmKey(String rmKey) { this.rmKey = rmKey; } public String getPayUrl() { return payUrl; } public void setPayUrl(String payUrl) { this.payUrl = payUrl; } public String getQfjyyCallbackUrl() { return qfjyyCallbackUrl; } public void setQfjyyCallbackUrl(String qfjyyCallbackUrl) { this.qfjyyCallbackUrl = qfjyyCallbackUrl; } public Double getAmount() { return amount; } public void setAmount(Double amount) { this.amount = amount; } public Double getAmountSettle() { return amountSettle; } public void setAmountSettle(Double amountSettle) { this.amountSettle = amountSettle; } public String getChannel() { return channel; } public void setChannel(String channel) { this.channel = channel; } public String getTradeType() { return tradeType; } public void setTradeType(String tradeType) { this.tradeType = tradeType; } public String getVersion() { return version; } public void setVersion(String version) { this.version = version; } public Map<String, String> getExtra() { return extra; } public void setExtra(Map<String, String> extra) { this.extra = extra; } public void setTotalFee(Double totalFee) { this.totalFee = totalFee; } public List getDetails() { return details; } public void setDetails(List details) { this.details = details; } public String getTokenIdUrl() { return tokenIdUrl; } public void setTokenIdUrl(String tokenIdUrl) { this.tokenIdUrl = tokenIdUrl; } public String getBuyerId() { return buyerId; } public void setBuyerId(String buyerId) { this.buyerId = buyerId; } public String getPayInfo() { return payInfo; } public void setPayInfo(String payInfo) { this.payInfo = payInfo; } }
支付類主要代碼
//威富通支付 PayBaseBean p = new PayBaseBean();
//用戶openid p.setOpenId(openId);
//支付總金額 p.setTotalFee(allSumAmt);
//支付描述 p.setBody(
"學雜費");
//系統自定義交易訂單號 p.setOutTradeNo(tradeNo); //回調通知地址
p.setNotifyUrl(notifyUrl + token + config.get("COMMON_NOTIFY_URL_SM")); //支付完成返回地址 p.setCallbackUrl("/webbase/finish.html?amt=" + allSumAmt + "&payee=" + weixinAccountVO.getAccountName());//支付成功後跳轉地址 //支付方法 PayBaseBean bean = weixinPayService.swiftpassPay(p, config, token, weixinAccountVO); logger.info("支付平臺返回:" + bean.getRecviceData()); String recCode = bean.getResultCode(); if (PubConst.PAY_STATE_FAIL.equals(recCode)) { String recMsg = bean.getResultMessage(); logger.info("原因:" + recMsg + "(代碼" + recCode + ")"); String urlData = subMsg(recMsg, "Error Code:" + recCode, null, false); url += urlData; response.sendRedirect(url); } else { if (PubConst.PAY_STATE_OK.equals(recCode)) { String wxJsUrl = bean.getSendData(); System.out.println("支付跳轉地址:" + wxJsUrl); return new ResultJsonInfo(true, wxJsUrl); } else { return new ResultJsonInfo(false, "系統異常!"); } }

支付方法

    /**
     * 直接調用威富通支付通道
     */
    @Override
    public PayBaseBean swiftpassPay(PayBaseBean payBaseBean,Map<String, String> config, String token,WeixinAccountVO weixinAccountVO) {
        Map<String, Object> map = new HashMap<String, Object>();
        //簽名
        try {
            String mchId = config.get("MCH_ID");
            String mchKey = config.get("MCH_KEY");
            String notifyUrl = config.get("NOTIFY_URL");
            String callBackUrl = config.get("CALL_BACK_URL");
            
            if(StringUtils.isEmpty(notifyUrl) || StringUtils.isEmpty(callBackUrl) || StringUtils.isEmpty(mchKey) || StringUtils.isEmpty(mchId)){
                payBaseBean.setResultCode(PubConst.PAY_STATE_FAIL);
                payBaseBean.setResultMessage("invalid parameter");
                logger.info("簽名前獲取參數錯誤,請檢查配置");
                return payBaseBean;
            }
            map.put("sub_appid",weixinAccountVO.getAccountAppid());//微信公眾號開發者appid
            map.put("service", "pay.weixin.jspay");//接口類型
            map.put("mch_id", mchId);//威富通商戶號
            map.put("is_raw", "1");//是否原生態(1:是; 0:否)
            map.put("out_trade_no", payBaseBean.getOutTradeNo());//商戶訂單號
            map.put("body", payBaseBean.getBody());//商品描述
            //測試號
            if("7551000001".equals(config.get("MCH_ID"))){
                map.put("total_fee", getTotal_fee(0.01));//總金額
            }else{
                map.put("sub_openid", payBaseBean.getOpenId());//用戶openid
                map.put("total_fee", getTotal_fee(payBaseBean.getTotalFee()));//總金額
            }
//            map.put("attach", payBaseBean.getAttach());//附加信息
            map.put("mch_create_ip", getMchCreateIp());//終端IP
            map.put("notify_url",payBaseBean.getNotifyUrl());//通知地址
            //     map.put("notify_url", "http://119.147.81.22/pinganWeb/"+ token +"/notify.html");//通知地址
            map.put("callback_url", callBackUrl + token + payBaseBean.getCallbackUrl());//前臺回調地址
            map.put("nonce_str", getNonceStr());//隨機字符串
            logger.info("簽名前密鑰字符串:" + mchKey);
            String signStr = SignUtil.getSign(map, mchKey);//排序拼裝簽名字符串
            logger.info("簽名前字符串:" + signStr);
            String sign = SignUtil.MD5Encode(signStr).toUpperCase();
            logger.info("簽名後字符串:" + sign);
            map.put("sign", sign);

            map.remove("callback_url");
            map.put("callback_url", "<![CDATA["+callBackUrl + token + payBaseBean.getCallbackUrl()+"]]>");//前臺回調地址
        } catch (Exception e) {
            payBaseBean.setResultCode(PubConst.PAY_STATE_FAIL);
            payBaseBean.setResultMessage("sign error" +e.getMessage());
            logger.info("簽名時異常,請檢查簽名方法");
            return payBaseBean;
        }
        //交互
        try {
            StringBuffer sb = new StringBuffer();  
            sb.append("<xml>");  
            SignUtil.mapToXMLTest2(map, sb);  
            sb.append("</xml>"); 
            logger.info("發送請求:" + sb.toString());
            payBaseBean.setSendData(sb.toString());
            payBaseBean.setPayUrl(config.get("SWIFTPASS_INIT_URL"));//支付初始地址
            HttpRequest pay = new HttpRequest();
            pay.request(payBaseBean);
        } catch (Exception e) {
            payBaseBean.setResultCode(PubConst.PAY_STATE_FAIL);
            payBaseBean.setResultMessage("pay error");
            logger.info("支付通訊異常,請檢查支付通訊方法");
            return payBaseBean;
        }
        //驗簽
        try {
            String recData = payBaseBean.getRecviceData();
            logger.info("收到數據:" + recData);
            Map<String,Object> recMap = SignUtil.stringToXmlToMap(recData);
            String status = (String) recMap.get("status");
            if("0".equals(status)){
                String recSign = (String) recMap.get("sign");
                recMap.remove("sign");
                String signStr = SignUtil.getSign(recMap,config.get("MCH_KEY"));//排序拼裝簽名字符串
                logger.info("驗簽前字符串:" + signStr);
                String sign = SignUtil.MD5Encode(signStr).toUpperCase();
                logger.info("驗簽後字符串:" + sign);
                //校驗簽名數據
                if(recSign.equals(sign)){
                    String resultCode = (String) recMap.get("result_code");
                    if("0".equals(resultCode)){
                        //獲取是否原生處理
                        String isRaw = config.get("IS_RAW");
                        if(isRaw.equals("1")){
                            JSONObject o = new JSONObject();
                            String pay_info = (String)recMap.get("pay_info");
                            logger.info("獲取pay_info數據: "+pay_info);
                            JSONObject jsonObj =  JSONObject.parseObject(pay_info);
                            o.put("appId",jsonObj.get("appId").toString());//公眾號名稱
                            o.put("package", jsonObj.get("package").toString());//訂單詳情擴展字符串
                            o.put("timeStamp", jsonObj.get("timeStamp").toString());//時間戳,自1970年以來的秒數
                            o.put("nonceStr", jsonObj.get("nonceStr").toString());//隨機串
                            o.put("signType", jsonObj.get("signType").toString());// //微信簽名方式:MD5
                            o.put("paySign", jsonObj.get("paySign").toString());//微信簽名
                            o.put("callback_url", config.get("CALL_BACK_URL") + token + payBaseBean.getCallbackUrl());
                            cacheService.put(RAW_PAY_KEY+payBaseBean.getOutTradeNo(), o.toJSONString(),2, TimeUnit.HOURS);
                            payBaseBean.setResultCode(PubConst.PAY_STATE_OK);
                            payBaseBean.setSendData(config.get("NOTIFY_URL")+"wisdom/rawpay.html?tokenId=" + payBaseBean.getOutTradeNo());

                        }else {
                            //正常直接訪問地址
                            String token_id = (String) recMap.get("token_id");
                            payBaseBean.setResultCode(PubConst.PAY_STATE_OK);
                            payBaseBean.setSendData(config.get("SWIFTPASS_PAY_URL") + "?token_id=" + token_id);
                        }
                        //一碼通返回pay_info
                        String pay_info = (String) recMap.get("pay_info");
                        payBaseBean.setPayInfo(pay_info);
                    }else{
                        payBaseBean.setResultCode(PubConst.PAY_STATE_FAIL);
                        payBaseBean.setResultMessage((String) recMap.get("err_msg"));
                    }
                }else{
                    payBaseBean.setResultCode(PubConst.PAY_STATE_FAIL);
                    payBaseBean.setResultMessage("驗簽失敗,請檢查報文。");
                }
            }else{
                payBaseBean.setResultCode(PubConst.PAY_STATE_FAIL);
                payBaseBean.setResultMessage((String) recMap.get("message"));
            }
        } catch (Exception e) {
            payBaseBean.setResultCode(PubConst.PAY_STATE_FAIL);
            payBaseBean.setResultMessage("check sign error");
            logger.info("通訊完成,驗簽異常,請檢查支付後驗簽方法");
            return payBaseBean;
        }
        return payBaseBean;
    }

工具類
package cn.rmt.wxbase.wxpay;

import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.util.*;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.apache.commons.lang3.StringUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;

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

/**
* 簽名算法
* @param o 要參與簽名的數據對象
* @return 簽名
* @throws IllegalAccessException
*/
public static String getSign(Map<String,Object> map,String key){
ArrayList<String> list = new ArrayList<String>();
for(Map.Entry<String,Object> entry:map.entrySet()){
if(entry.getValue()!="" && null != entry.getValue()){
list.add(entry.getKey() + "=" + entry.getValue() + "&");
}
}
int size = list.size();
String [] arrayToSort = list.toArray(new String[size]);
Arrays.sort(arrayToSort, String.CASE_INSENSITIVE_ORDER);
StringBuilder sb = new StringBuilder();
for(int i = 0; i < size; i ++) {
sb.append(arrayToSort[i]);
}
String result = sb.toString();
result += "key=" + key;
return result;
}

/**
* MD5編碼
* @param origin 原始字符串
* @return 經過MD5加密之後的結果
*/
public static String MD5Encode(String origin) {
String resultString = null;
try {
resultString = origin;
MessageDigest md = MessageDigest.getInstance("MD5");
resultString = byteArrayToHexString(md.digest(resultString.getBytes("utf-8")));
} catch (Exception e) {
e.printStackTrace();
}
return resultString;
}


public static void mapToXMLTest2(Map map, StringBuffer sb) {
Set set = map.keySet();
for (Iterator it = set.iterator(); it.hasNext();) {
String key = (String) it.next();
Object value = map.get(key);
if (null == value)
value = "";
if (value.getClass().getName().equals("java.util.ArrayList")) {
ArrayList list = (ArrayList) map.get(key);
sb.append("<" + key + ">");
for (int i = 0; i < list.size(); i++) {
HashMap hm = (HashMap) list.get(i);
mapToXMLTest2(hm, sb);
}
sb.append("</" + key + ">");

} else {
if (value instanceof HashMap) {
sb.append("<" + key + ">");
mapToXMLTest2((HashMap) value, sb);
sb.append("</" + key + ">");
} else {
sb.append("<" + key + ">" + value + "</" + key + ">");
}

}

}
}
 public static Map<String,Object> stringToXmlToMap(String recData){
Map<String,Object> retMap=new HashMap<String,Object>();
try {
StringReader sr = new StringReader(recData);
InputSource is = new InputSource(sr);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder=factory.newDocumentBuilder();
Document doc = builder.parse(is);
doc.normalize();
Element root = doc.getDocumentElement();
NodeList nodeList = root.getChildNodes();
if(nodeList!=null){
for(int i=0;i<nodeList.getLength();i++){
Node node = nodeList.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
retMap.put(node.getNodeName(), node.getTextContent());
}
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return retMap;
}

}



微信支付通訊類
package cn.rmt.wxbase.wxpay;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import cn.rmt.wxbase.vo.PayBaseBean;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSession;


/**
* <br>
* <b>功能:</b>微信支付數據通訊交互<br>
* <b>作者:
* <b>日期:
* <b>版權所有:
*/
public class HttpRequest {

public void request(PayBaseBean payData) throws Exception {
HttpURLConnection connection = null;
OutputStream out = null;
BufferedReader reader = null;
String urlString = null;

try {
try {
urlString = payData.getPayUrl();
connection = (HttpURLConnection) (new URL(urlString)).openConnection();

} catch (Exception e) {
e.printStackTrace();
}

connection.setConnectTimeout(900*1000);
connection.setReadTimeout(900*1000);
connection.setRequestMethod("POST");
connection.setDoOutput(true);
//古井的模式要求為"YES"
connection.setRequestProperty("Intensoft-Request-Sign","NO");
connection.setRequestProperty("Content-Type", "application/x-fox");
connection.setRequestProperty("Content-Length", Integer.toString(payData.getSendData().getBytes().length));
// String sd=payData.replaceAll("> <","><");

// org.jeecgframework.core.util.LogUtil.info("發送數據:\r\n" + payData.getSendData());

try {
connection.connect();
out = connection.getOutputStream();
out.write(payData.getSendData().getBytes("UTF-8"));
out.flush();
} catch (Exception e) {
e.printStackTrace();
}
try {

reader = new BufferedReader(new InputStreamReader(connection.getInputStream(),"UTF-8"));
StringBuffer receiveData = new StringBuffer();
// 分段收取
char[] receive = new char[1024];
int read = 0;
while ((read = reader.read(receive)) != -1)
receiveData.append(receive, 0, read);
payData.setRecviceData(receiveData.toString());
// org.jeecgframework.core.util.LogUtil.info("收到數據:\r\n" + receiveData.toString());
} catch (Exception e) {
e.printStackTrace();
}
} finally {
if (out != null)
try {
out.close();
} catch (Exception e) {
e.printStackTrace();
}
if (reader != null)
try {
reader.close();
} catch (Exception e) {
e.printStackTrace();
}
if (connection != null)
connection.disconnect();
}
}
/**通聯支付發送請求**/
public String reqPost(String urlString ,String urlParams) throws Exception {
HttpURLConnection connection = null;
OutputStream out = null;
BufferedReader reader = null;
StringBuffer receiveData = null ;
try {
connection = (HttpURLConnection) (new URL(urlString)).openConnection();
//SSL
System.setProperty("java.protocol.handler.pkgs", "javax.net.ssl");
HostnameVerifier hv = new HostnameVerifier() {
public boolean verify(String urlHostName, SSLSession session) {
return urlHostName.equals(session.getPeerHost());
}
};
HttpsURLConnection.setDefaultHostnameVerifier(hv);
//設置請求屬性
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("accept", "*/*");
connection.setRequestProperty("connection", "Keep-Alive");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
if (connection instanceof HttpsURLConnection){
HttpsURLConnection httpsConn = (HttpsURLConnection)connection;
httpsConn.setSSLSocketFactory(SSLUtil.getInstance().getSSLSocketFactory());
} else if (connection instanceof HttpURLConnection){
HttpURLConnection httpConn = (HttpURLConnection)connection;
} else {
throw new Exception("不是http/https協議的url");
}
//建立連接
connection.connect();
//發送數據
out = connection.getOutputStream();
out.write(urlParams.getBytes("UTF-8"));
out.flush();

//獲取數據
reader = new BufferedReader(new InputStreamReader(connection.getInputStream(),"UTF-8"));
receiveData = new StringBuffer();
// 分段收取
char[] receive = new char[1024];
int read = 0;
while ((read = reader.read(receive)) != -1)
receiveData.append(receive, 0, read);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (out != null)
try {
out.close();
} catch (Exception e) {
e.printStackTrace();
}
if (reader != null)
try {
reader.close();
} catch (Exception e) {
e.printStackTrace();
}
if (connection != null)
connection.disconnect();
}
return receiveData.toString();
}
}
回調接口方法
@RequestMapping(value="/{token}/notify")
@RmtSecurityAuth(filterRule= RmtSecurityAuth.FilterRule.ANON)
public void notifyGet(@PathVariable String token,HttpServletRequest req,HttpServletResponse resp) {
logger.info("收到通知---->");
String respString = "error";
try {
Map<String, String> map = parseXml(req);//威富通返回xml

logger.info("通知內容:" + map.toString());
if(map != null && map.size() > 0) {
WeixinAccountVO accountVO = weixinAccountService.getWeixinAccountByToken(token);
Map<String, String> AccountConfigMap = weixinAccountConfigService.getAccountConfigList(accountVO.getId());
if (map.containsKey("sign")) {
if (!checkParam(map, AccountConfigMap.get("MCH_KEY"))) {//KEY
logger.info("---------驗證簽名不通過-------------");
} else {
String returnCode = map.get("status");
if (returnCode != null && PubConst.PAY_STATE_OK.equals(returnCode)) {
respString = "success";
String orderNo = map.get("out_trade_no");
logger.info("處理訂單號:" + orderNo);
if (PubConst.PAY_STATE_SUCCESS.equals(map.get("result_code"))) {

//根據訂單流水號查詢中間表
WeixinMidPayInfoVO vo = weixinMidPayInfoService.findMidPayInfoByOrderNo(orderNo);
if (vo == null) {
logger.info("訂單號" + orderNo + "不存在!");
} else {
String flag = vo.getIsRec();
if ("0".equals(flag)) {
logger.info("訂單號" + orderNo + "已處理");
} else {


String[] pdid = vo.getOrderId().split(",");
if (pdid.length > 0) {
for (int i = 0; i < pdid.length; i++) {
WxSchoolWisdomPayInfoVO vos = wxSchoolWisdomPayInfoService.findById(pdid[i]);
List<String> proIds = new ArrayList<String>();//項目id
List<String> dtlIds = new ArrayList<String>();//明細id
//更新待繳費項目表狀態
if ("" != vos.getpId() && null != vos.getpId()) {
String[] ids = vos.getpId().split(",");
for (int g = 0; g < ids.length; g++) {
String id = ids[g];
proIds.add(id);
}

for (int j = 0; j < proIds.size(); j++) {
WxSchoolWisdomPaymentDetailVO detailVO = new WxSchoolWisdomPaymentDetailVO();
detailVO = wxSchoolWisdomPaymentDetailService.findById(proIds.get(j));
detailVO.setTransactionId(orderNo);
detailVO.setPayState("0");//0:成功,1:未支付
detailVO.setPayEndDate(DateTools.getFormattingDateString(map.get("time_end"), "yyyyMMddHHmmss"));
wxSchoolWisdomPaymentDetailService.update(null, detailVO);
}
}
//明細表更新狀態
if ("" != vos.getdId() && null != vos.getdId()) {
String[] ids = vos.getdId().split(",");
for (int f = 0; f < ids.length; f++) {
String id = ids[f];
dtlIds.add(id);
}
WxSchoolWisdomPaymentDetailInfoVO detailInfoVO = new WxSchoolWisdomPaymentDetailInfoVO();
for (int j = 0; j < dtlIds.size(); j++) {
detailInfoVO = wxSchoolWisdomPaymentDetailInfoService.findById(dtlIds.get(j));
detailInfoVO.setTransactionId(orderNo);
detailInfoVO.setPayState("0");//0:成功,1:未支付
detailInfoVO.setPayEndDate(DateTools.getFormattingDateString(map.get("time_end"), "yyyyMMddHHmmss"));
wxSchoolWisdomPaymentDetailInfoService.update(null, detailInfoVO);
}
}
}
//更新中間表狀態
vo.setIsRec(PubConst.PAY_RESULT_OK);//已返回
vo.setRecState(map.get("result_code"));
vo.setTransactionId(map.get("transaction_id"));
vo.setPayEndDate(DateTools.getFormattingDateString(map.get("time_end"), "yyyyMMddHHmmss"));
weixinMidPayInfoService.saveOrUpdate(null, vo);
logger.info("訂單號" + orderNo + "對應表名為:" + vo.getTableName());
//更新單據狀態為已成功
WeixinMidPayInfoQueryParam param = new WeixinMidPayInfoQueryParam();
param.setWeixinMidPayInfo(vo);
int result = weixinMidPayInfoService.updateTableState(param);
if (result > 0) {
logger.info("訂單號:" + orderNo + "支付成功。");
if (!StringUtils.isBlank(vo.getEndCallBackEvent())) {
//從地址獲取PAY_END_CALL_BACK放到參數中,區分要實例化哪個對象
Map<String, Object> endParam = new HashMap<String, Object>();
endParam.put("transactionId", vo.getTransactionId());
endParam.put("tableName", vo.getTableName());
endParam.put(WeixinPayConst.PAY_END_CALL_BACK, vo.getEndCallBackEvent());
payEndCallBackService.doEndPay(endParam);
}
}
}
}
}
} else {
logger.info("訂單號:" + orderNo + "支付失敗");
}
} else {
logger.info("返回狀態失敗");
}
}
} else {
logger.info("無返回簽名數據");
}
}else{
logger.info("返回數據異常");
}
resp.getWriter().write(respString);
} catch (Exception e) {
logger.error(e.getMessage());
try {
resp.getWriter().write(respString);
} catch (IOException e1) {

}
}
}
 

威富通支付接口