/**
*项目:xmlInterf
*通联支付网络有限公司
* 作者:张广海
* 日期:Jan 2, 2013
* 功能说明:系统对接xml 测试demo
*/
package com.wx.activitys.xmlInterf.allinpay.xmltrans.service;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.UnsupportedEncodingException;
import java.net.ConnectException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.apache.commons.codec.binary.Base64InputStream;
import org.apache.commons.io.IOUtils;
import com.wx.activitys.base.utils.FileUtil;
import com.wx.activitys.xmlInterf.aipg.accttrans.AcctTransferReq;
import com.wx.activitys.xmlInterf.aipg.acctvalid.ValbSum;
import com.wx.activitys.xmlInterf.aipg.acctvalid.ValidBD;
import com.wx.activitys.xmlInterf.aipg.acctvalid.ValidBReq;
import com.wx.activitys.xmlInterf.aipg.acctvalid.VbDetail;
import com.wx.activitys.xmlInterf.aipg.ahquery.AHQueryReq;
import com.wx.activitys.xmlInterf.aipg.cash.CashReq;
import com.wx.activitys.xmlInterf.aipg.common.AipgReq;
import com.wx.activitys.xmlInterf.aipg.common.AipgRsp;
import com.wx.activitys.xmlInterf.aipg.common.FtpXml;
import com.wx.activitys.xmlInterf.aipg.common.InFTP;
import com.wx.activitys.xmlInterf.aipg.common.InfoReq;
import com.wx.activitys.xmlInterf.aipg.common.XSUtil;
import com.wx.activitys.xmlInterf.aipg.idverify.IdVer;
import com.wx.activitys.xmlInterf.aipg.payreq.Body;
import com.wx.activitys.xmlInterf.aipg.payreq.Trans_Detail;
import com.wx.activitys.xmlInterf.aipg.payreq.Trans_Sum;
import com.wx.activitys.xmlInterf.aipg.refund.Refund;
import com.wx.activitys.xmlInterf.aipg.rnp.Rnp;
import com.wx.activitys.xmlInterf.aipg.rnp.Rnpa;
import com.wx.activitys.xmlInterf.aipg.rnp.RnpaRet;
import com.wx.activitys.xmlInterf.aipg.rnp.Rnpc;
import com.wx.activitys.xmlInterf.aipg.rnp.Rnpr;
import com.wx.activitys.xmlInterf.aipg.rtreq.Trans;
import com.wx.activitys.xmlInterf.aipg.rtrsp.TransRet;
import com.wx.activitys.xmlInterf.aipg.signquery.NSignReq;
import com.wx.activitys.xmlInterf.aipg.signquery.QSignDetail;
import com.wx.activitys.xmlInterf.aipg.singleacctvalid.ValidR;
import com.wx.activitys.xmlInterf.aipg.singleacctvalid.ValidRet;
import com.wx.activitys.xmlInterf.aipg.transquery.QTDetail;
import com.wx.activitys.xmlInterf.aipg.transquery.QTransRsp;
import com.wx.activitys.xmlInterf.aipg.transquery.TransQueryReq;
import com.wx.activitys.xmlInterf.allinpay.XmlTools;
import com.wx.activitys.xmlInterf.allinpay.xmltrans.pojo.TranxCon;
/**
*/
public class TranxServiceImpl {
TranxCon tranxContants=new TranxCon();
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
/**
* 单笔退款
* 日期:Apr 28, 2015
* @author 曾招军
* @param trx_code
* @throws Exception
*/
public void refundTranx(String url, String trx_code, String busicode, boolean isTLTFront) throws Exception {
String xml = "";
AipgReq aipg = new AipgReq();
InfoReq info = makeReq(trx_code);
aipg.setINFO(info);
Refund refund = new Refund();
refund.setBUSINESS_CODE(busicode);
refund.setMERCHANT_ID(tranxContants.merchantId); //商户号
refund.setORGBATCHID("20060400000044520161019000500000515"); //交易的文件名
refund.setORGBATCHSN("0"); //实时收款设置为0
refund.setACCOUNT_NO("6212263803005657667");
refund.setACCOUNT_NAME("刘一");
refund.setAMOUNT("60");
refund.setREMARK("全部退还");
aipg.addTrx(refund);
xml = XmlTools.buildXml(aipg, true);
dealRet(sendToTlt(xml,isTLTFront,url));
}
/**
* 日期:Sep 4, 2012
* 功能:
* @param trx_code
* @throws Exception
*/
public void batchTranx(String url,String trx_code,String busicode, boolean isTLTFront) throws Exception {
String xml="";
AipgReq aipg=new AipgReq();
InfoReq info=makeReq(trx_code);
aipg.setINFO(info);
Body body = new Body() ;
Trans_Sum trans_sum = new Trans_Sum() ;
trans_sum.setBUSINESS_CODE(busicode) ;
trans_sum.setMERCHANT_ID(tranxContants.merchantId) ;
trans_sum.setTOTAL_ITEM("2") ;
trans_sum.setTOTAL_SUM("4") ;
body.setTRANS_SUM(trans_sum) ;
List <Trans_Detail>transList = new ArrayList<Trans_Detail>() ;
Trans_Detail trans_detail = new Trans_Detail() ;
Trans_Detail trans_detail2 = new Trans_Detail() ;
trans_detail.setSN("0000000000000020000111111") ;
trans_detail.setACCOUNT_NAME("张三") ;
trans_detail.setACCOUNT_PROP("0") ;
trans_detail.setACCOUNT_NO("6225211503906389") ;
trans_detail.setBANK_CODE("0308") ;
trans_detail.setAMOUNT("2") ;
trans_detail.setCURRENCY("CNY");
// trans_detail.setSETTGROUPFLAG("xCHM");
// trans_detail.setSUMMARY("分组清算");
// trans_detail.setUNION_BANK("234234523523");
transList.add(trans_detail) ;
trans_detail2.setSN("0000000000000020000011111") ;
trans_detail2.setACCOUNT_NAME("张三") ;
// trans_detail.setACCOUNT_PROP("1") ;
trans_detail2.setACCOUNT_NO("6225211503906389") ;
trans_detail2.setBANK_CODE("0308") ;
trans_detail2.setAMOUNT("2") ;
trans_detail2.setCURRENCY("CNY");
// trans_detail2.setSETTGROUPFLAG("CHM");
// trans_detail2.setSUMMARY("分组清算");
transList.add(trans_detail2);
body.setDetails(transList) ;
aipg.addTrx(body) ;
xml=XmlTools.buildXml(aipg,true);
dealRet(sendToTlt(xml,isTLTFront,url));
}
/**
* 组装报文头部
* @param trxcod
* @return
*日期:Sep 9, 2012
*/
private InfoReq makeReq(String trxcod)
{
InfoReq info=new InfoReq();
info.setTRX_CODE(trxcod);
info.setREQ_SN(tranxContants.merchantId+"-"+String.valueOf(System.currentTimeMillis()));
info.setUSER_NAME(tranxContants.userName);
info.setUSER_PASS(tranxContants.password);
info.setLEVEL("5");
info.setDATA_TYPE("2");
info.setVERSION("03");
if("300000".equals(trxcod)||"300001".equals(trxcod)||"300003".equals(trxcod)||"REFUND".equals(trxcod)){
info.setMERCHANT_ID(tranxContants.merchantId);
}
return info;
}
public String sendXml(String xml,String url,boolean isFront) throws UnsupportedEncodingException, Exception{
System.out.println("======================发送报文======================:\n"+xml);
String resp=XmlTools.send(url,xml);
System.out.println("======================响应内容======================") ;
boolean flag= this.verifyMsg(resp, tranxContants.tltcerPath,isFront);
if(flag){
System.out.println("响应内容验证通过");
}else{
System.out.println("响应内容验证不通过");
}
System.out.println(resp);
return resp;
}
public String sendToTlt(String xml,boolean flag,String url) {
try{
if(!flag){
xml=this.signMsg(xml);
}else{
xml=xml.replaceAll("<SIGNED_MSG></SIGNED_MSG>", "");
}
return sendXml(xml,url,flag);
}catch(Exception e){
e.printStackTrace();
if(e.getCause() instanceof ConnectException||e instanceof ConnectException){
System.out.println("请求链接中断,如果是支付请求,请做交易结果查询,以确认该笔交易是否已被通联受理,避免重复交易");
}
}
return "请求链接中断,如果是支付请求,请做交易结果查询,以确认该笔交易是否已被通联受理,避免重复交易";
}
/**
* 报文签名
* @param msg
* @return
*日期:Sep 9, 2012
* @throws Exception
*/
public String signMsg(String xml) throws Exception{
xml=XmlTools.signMsg(xml, tranxContants.pfxPath,tranxContants.pfxPassword, false);
return xml;
}
/**
* 验证签名
* @param msg
* @return
*日期:Sep 9, 2012
* @throws Exception
*/
public boolean verifyMsg(String msg,String cer,boolean isFront) throws Exception{
boolean flag=XmlTools.verifySign(msg, cer, false,isFront);
System.out.println("验签结果["+flag+"]") ;
return flag;
}
/**
*下载对账文件
* @see com.aipg.core.TranxOperati
It'sokay
- 粉丝: 0
- 资源: 3
最新资源
- java毕设项目之毕业生学历证明系统+vue(完整前后端+说明文档+mysql+lw).zip
- 高校学术交流平台_g75441il_233-QQ.zip
- 个性化智能学习系统(编号:22575176).zip
- 共享经济背景下校园闲置物品交易平台(编号:33061160).zip
- java毕设项目之个性化旅游攻略定制系统设计与实现+jsp(完整前后端+说明文档+mysql+lw).zip
- 基于MATLAB的导航科学计算库
- 基于JavaScript的在线考试系统(编号:65965158)(1).zip
- 湖南交通工程学院学生就业信息系统_u26ajz8t_205-wx.zip
- 基于Java WEB旅游门票信息系统设计与实现_70rn7486_206-wx.zip
- 基于javaweb宿舍管理系统(编号:18018175).zip
- 基于JavaWeb的教务管理系统(编号:75778125).zip
- Python结合Pygame库实现圣诞主题动画和音乐效果的代码示例
- 基于JavaWeb的毕业季旅游一站式定制服务平台_88z1j4jp_208-wx-(1).zip
- RGMII delay问题
- java毕设项目之基于JSP的网络游戏交易系统的设计与实现+jsp(完整前后端+说明文档+mysql+lw).zip
- 国际象棋检测2-YOLO(v5至v9)、COCO、CreateML、Darknet、Paligemma、TFRecord数据集合集.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈