威富通支付接口
支付实体类
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) {
}
}
}
What do you want to be?