现在微信支付也有一定的用户量所以现在为大家提供一个微信支付的对账文档和方法
对账逻辑这个因公司的需求不一样而不同,所以这里我们只介绍微信对账的接口调用和返回数据
1:微信对账接口分析
微信支付实际上是调用财付通的支付接口进行支付的
首先你要的知道你的商户号和秘钥
对账接口查询的只能查询昨天和昨天以前的订单信息 并且如果想下载昨天订单要在今天的7点之后进行
java代码如下:
public List getWechatBeanList(String time) {
try{
List list = new ArrayList();
//创建分账请求对象
DownloadBillRequestHandler reqHandler = new DownloadBillRequestHandler(null, null);
//通信对象
TenpayHttpClient httpClient = new TenpayHttpClient();
//-----------------------------
//设置请求参数
//-----------------------------
reqHandler.init();
reqHandler.setKey(key);
reqHandler.setGateUrl("http://mch.tenpay.com/cgi-bin/mchdown_real_new.cgi");
//-----------------------------
//设置接口参数
//-----------------------------
String timestamp = Long.toString(System.currentTimeMillis()/1000);
reqHandler.setParameter("spid", bargainor_id);
reqHandler.setParameter("trans_time", time);
reqHandler.setParameter("stamp", timestamp);
reqHandler.setParameter("cft_signtype", "0");
reqHandler.setParameter("mchtype", "1");
//设置请求内容
httpClient.setReqContent(reqHandler.getRequestURL());
System.out.println(reqHandler.getRequestURL());
// out.println(reqHandler.getRequestURL());
//设置发送类型 GET
httpClient.setMethod("POST");
//后台调用
if(httpClient.call()) {
String resContent = httpClient.getResContent();
System.out.println("-------------------------");
System.out.println(resContent);
System.out.println("-------------------------");
logger.info("[流水#"+loggerTrace+"][获取微信支付对账信息#成功][数据#"+JsonUtil.convertObject2Json(resContent)+"]");
String [] resContentStr = resContent.split("\\r?\\n");
if(resContentStr[0].equals("")){
logger.info("[流水#"+loggerTrace+"][当天没有微信支付记录]");
return null;
}
for(int i = 1 ;i= resContentStr.length - 3){
break;
}
if(!resContentStr[i].equals("")){
String [] values = resContentStr[i].split(",");
WechatBean bean = new WechatBean();
bean.setPaySuccrssDate(values[0]);
bean.setCaiFuTongTraceNo(values[1]);
bean.setPayTraceNo(values[2].substring(2, values[2].length()));
bean.setPayType(values[3]);
bean.setBankTraceNo(values[4]);
double amount = Double.valueOf(values[5]);
int finalAmount = (int)amount*100;
bean.setAmount(finalAmount);
bean.setStatus(values[6]);
bean.setMome(values[7]);
list.add(bean);
}
}
return list;
} else {
logger.info("[流水#"+loggerTrace+"][微信支付对账#后台调用通信失败[数据#"+JsonUtil.convertObject2Json(httpClient.getResponseCode()+httpClient.getErrInfo())+"]");
System.out.println("后台调用通信失败");
System.out.println(httpClient.getResponseCode());
System.out.println(httpClient.getErrInfo());
//有可能因为网络原因,请求已经处理,但未收到应答。
return null;
}
}catch(Exception e){
e.printStackTrace();
logger.info("[流水#"+loggerTrace+"][微信支付对账#异常】[数据#"+JsonUtil.convertObject2Json(e)+"]");
return null;
}
}
随带也说一下支付宝对账接口吧
支付宝对账接口中返回给你的是分页的信息
根据查询的页码和一页大小给你返回信息
/*
*获取支付宝分页对账返回xml
*/
public static String getAilpayQueryPageLog(Object[]values,String pageNo){
Map sParaTemp = new HashMap();
sParaTemp.put("service", "account.page.query");
sParaTemp.put("partner", AlipayConfig.partner);
sParaTemp.put("_input_charset", AlipayConfig.input_charset);
sParaTemp.put("page_no", pageNo);
sParaTemp.put("gmt_start_time", (String)values[0]);
sParaTemp.put("gmt_end_time", (String)values[1]);
try {
String sHtmlText = AlipaySubmit.buildRequest("", "", sParaTemp);
return sHtmlText;
} catch (Exception e) {
e.printStackTrace();
return "";
}
}
然后解析xml得到对象
/*
* 解析xml返回PageAccountQueryRecode对象
*/
public PageAccountQueryRecode getPageAccountQueryRecode(String xml){
try{
PageAccountQueryRecode pageAccountQueryRecode = XmlParser.xmlToBbject(xml);
return pageAccountQueryRecode;
}catch(Exception e){
e.printStackTrace();
return null;
}
}
class XmlParser{
public static PageAccountQueryRecode xmlToBbject(String Xml){
try{
PageAccountQueryRecode pageAccountQueryRecode = new PageAccountQueryRecode();
List list = new ArrayList();
Document doc = DocumentHelper.parseText(Xml);
Element rootElt = doc.getRootElement();
System.out.println(rootElt.getName());
Element response = rootElt.element("response");
System.out.println(response.getName() );
Element account_page_query_result = response.element("account_page_query_result");
System.out.println(account_page_query_result.getName() );
Element account_log_list = account_page_query_result.element("account_log_list");
System.out.println(account_log_list.getName() );
List list1 = account_log_list.elements("AccountQueryAccountLogVO");
System.out.println(list1.size() );
for( Element e : list1){
TAlipaySellet vo = new TAlipaySellet();
vo.setBalance(e.element("balance") != null ?e.element("balance").getTextTrim():" ");
// vo.setBank_account_name(accountQueryAccountLogVO.element("bank_account_name").getTextTrim());
// vo.setBank_account_no(accountQueryAccountLogVO.element("bank_account_no").getTextTrim());
// vo.setBank_name(accountQueryAccountLogVO.element("bank_name").getTextTrim());
vo.setBuyerAccount(e.element("buyer_account") != null ? e.element("buyer_account").getTextTrim(): " ");
vo.setCurrency(e.element("currency") != null ?e.element("currency").getTextTrim(): " ");
vo.setDepositBankNo(e.element("deposit_bank_no") != null ?e.element("deposit_bank_no").getTextTrim():" ");
double income = Double.valueOf(e.element("income").getTextTrim());
income = income*100;
vo.setIncome((int)income);
vo.setGoodsTitle(e.element("goods_title")!=null ?e.element("goods_title").getTextTrim():" ");
vo.setIwAccountLogId(e.element("iw_account_log_id") != null ? e.element("iw_account_log_id").getTextTrim() : " ");
vo.setMemo(e.element("memo").getTextTrim());
vo.setMerchantOutOrderNo(e.element("merchant_out_order_no") != null ?e.element("merchant_out_order_no").getTextTrim(): " ");
// vo.setOther_account_email(accountQueryAccountLogVO.element("other_account_email").getTextTrim());
// vo.setOther_account_fullname(accountQueryAccountLogVO.element("other_account_fullname").getTextTrim());
// vo.setOther_user_id(accountQueryAccountLogVO.element("other_user_id").getTextTrim());
double outcome = Double.valueOf(e.element("outcome").getTextTrim());
outcome = outcome*100;
vo.setOutcome((int)outcome);
vo.setPartnerId(e.element("partner_id") != null ?e.element("partner_id").getTextTrim() : " ");
vo.setRate(e.element("rate") != null ?e.element("rate").getTextTrim() :" ");
vo.setSellerAccount(e.element("seller_account") != null ? e.element("seller_account").getTextTrim() : " ");
vo.setSellerFullname(e.element("seller_fullname") != null ?e.element("seller_fullname").getTextTrim() : " ");
vo.setServiceFee(e.element("service_fee") != null ?e.element("service_fee").getTextTrim(): " ");
vo.setServiceFeeRatio(e.element("service_fee_ratio") != null ?e.element("service_fee_ratio").getTextTrim():" ");
vo.setSignProductName(e.element("sign_product_name") != null ?e.element("sign_product_name").getTextTrim() :" ");
vo.setSubTransCodeMsg(e.element("sub_trans_code_msg") != null ?e.element("sub_trans_code_msg").getTextTrim(): " ");
vo.setTotalFee(e.element("total_fee") != null ?e.element("total_fee").getTextTrim(): " ");
vo.setTradeNo(e.element("trade_no") != null ? e.element("trade_no").getTextTrim(): " ");
vo.setTradeRefundAmount(e.element("trade_refund_amount") != null ?e.element("trade_refund_amount").getTextTrim(): " ");
// vo.setTrans_account(accountQueryAccountLogVO.element("trans_account").getTextTrim());
vo.setTransCodeMsg(e.element("trans_code_msg") != null ?e.element("trans_code_msg").getTextTrim():" ");
vo.setTransDate(e.element("trans_date") != null ?e.element("trans_date").getTextTrim() :" ");
// vo.setTransOutOrderNo(e.element("trans_out_order_no").getTextTrim());
list.add(vo);
}
pageAccountQueryRecode.setAccountQueryAccountLogVOList(list);
pageAccountQueryRecode.setIs_success(rootElt.element("is_success").getTextTrim());
pageAccountQueryRecode.setSign(rootElt.element("sign").getTextTrim());
pageAccountQueryRecode.setSign_type(rootElt.element("sign_type").getTextTrim());
Element has_next_page = account_page_query_result.element("has_next_page");
Element page_no = account_page_query_result.element("page_no");
Element page_size = account_page_query_result.element("page_size");
pageAccountQueryRecode.setHas_next_page(has_next_page.getText());
pageAccountQueryRecode.setPage_size(page_size.getText());
pageAccountQueryRecode.setPage_no(page_no.getText());
return pageAccountQueryRecode;
/*
* -----------------------------------------------------------------------------------
PageAccountQueryRecode pageAccountQueryRecode = new PageAccountQueryRecode();
List list = new ArrayList();
Document doc = DocumentHelper.parseText(Xml);
Element rootElt = doc.getRootElement();
pageAccountQueryRecode.setIs_success(rootElt.element("is_success").getTextTrim());
pageAccountQueryRecode.setSign(rootElt.element("sign").getTextTrim());
pageAccountQueryRecode.setSign_type(rootElt.element("sign_type").getTextTrim());
Iterator iter = rootElt.elementIterator("request");
while (iter.hasNext()) {
Element recordEle = (Element) iter.next();
pageAccountQueryRecode.setPage_no(recordEle.selectSingleNode("param[@name='page_no']").getText());
pageAccountQueryRecode.setGmt_end_time(recordEle.selectSingleNode("param[@name='gmt_end_time']").getText());
pageAccountQueryRecode.setGmt_start_time(recordEle.selectSingleNode("param[@name='gmt_start_time']").getText());
// Iterator recordEleIter = recordEle.elementIterator("param");
// while (recordEleIter.hasNext()) {
// Element param = (Element) recordEleIter.next();
// param.attributeValue("name");
// System.out.println(param.selectSingleNode("param[@name='sign']").getText());
// System.out.println(param.getName());
// System.out.println(param.getStringValue());
// System.out.println(param.attributeValue("name"));
// }
}
Iterator responseiter = rootElt.elementIterator("response");
Element responseNode = rootElt.element("response");
Element account_page_query_result = responseNode.element("account_page_query_result");
Element account_log_list = account_page_query_result.element("account_log_list");
Element has_next_page = account_page_query_result.element("has_next_page");
Element page_no = account_page_query_result.element("page_no");
Element page_size = account_page_query_result.element("page_size");
pageAccountQueryRecode.setHas_next_page(has_next_page.getText());
pageAccountQueryRecode.setPage_size(page_size.getText());
Iterator accountQueryAccountLogVOIter = account_log_list.elementIterator("AccountQueryAccountLogVO");
while (accountQueryAccountLogVOIter.hasNext()) {
Element accountQueryAccountLogVO = (Element) accountQueryAccountLogVOIter.next();
String str = accountQueryAccountLogVO.element("balance").getTextTrim();
TAlipaySellet vo = new TAlipaySellet();
vo.setBalance(accountQueryAccountLogVO.element("balance").getTextTrim());
// vo.setBank_account_name(accountQueryAccountLogVO.element("bank_account_name").getTextTrim());
// vo.setBank_account_no(accountQueryAccountLogVO.element("bank_account_no").getTextTrim());
// vo.setBank_name(accountQueryAccountLogVO.element("bank_name").getTextTrim());
vo.setBuyerAccount(accountQueryAccountLogVO.element("buyer_account").getTextTrim());
vo.setCurrency(accountQueryAccountLogVO.element("currency").getTextTrim());
vo.setDepositBankNo(accountQueryAccountLogVO.element("deposit_bank_no").getTextTrim());
// vo.setIncome(Integer.valueOf(accountQueryAccountLogVO.element("income").getTextTrim()));
vo.setGoodsTitle(accountQueryAccountLogVO.element("goods_title").getTextTrim());
vo.setIwAccountLogId(accountQueryAccountLogVO.element("iw_account_log_id").getTextTrim());
vo.setMemo(accountQueryAccountLogVO.element("memo").getTextTrim());
vo.setMerchantOutOrderNo(accountQueryAccountLogVO.element("merchant_out_order_no").getTextTrim());
// vo.setOther_account_email(accountQueryAccountLogVO.element("other_account_email").getTextTrim());
// vo.setOther_account_fullname(accountQueryAccountLogVO.element("other_account_fullname").getTextTrim());
// vo.setOther_user_id(accountQueryAccountLogVO.element("other_user_id").getTextTrim());
// vo.setOutcome(Integer.valueOf(accountQueryAccountLogVO.element("outcome").getTextTrim()));
vo.setPartnerId(accountQueryAccountLogVO.element("partner_id").getTextTrim());
vo.setRate(accountQueryAccountLogVO.element("rate").getTextTrim());
vo.setSellerAccount(accountQueryAccountLogVO.element("seller_account").getTextTrim());
vo.setSellerFullname(accountQueryAccountLogVO.element("seller_fullname").getTextTrim());
vo.setServiceFee(accountQueryAccountLogVO.element("service_fee").getTextTrim());
vo.setServiceFeeRatio(accountQueryAccountLogVO.element("service_fee_ratio").getTextTrim());
vo.setSignProductName(accountQueryAccountLogVO.element("sign_product_name").getTextTrim());
vo.setSubTransCodeMsg(accountQueryAccountLogVO.element("sub_trans_code_msg").getTextTrim());
vo.setTotalFee(accountQueryAccountLogVO.element("total_fee").getTextTrim());
vo.setTradeNo(accountQueryAccountLogVO.element("trade_no").getTextTrim());
vo.setTradeRefundAmount(accountQueryAccountLogVO.element("trade_refund_amount").getTextTrim());
// vo.setTrans_account(accountQueryAccountLogVO.element("trans_account").getTextTrim());
vo.setTransCodeMsg(accountQueryAccountLogVO.element("trans_code_msg").getTextTrim());
vo.setTransDate(accountQueryAccountLogVO.element("trans_date").getTextTrim());
// vo.setTrans_out_order_no(accountQueryAccountLogVO.element("trans_out_order_no").getTextTrim());
list.add(vo);
}
pageAccountQueryRecode.setAccountQueryAccountLogVOList(list);
return pageAccountQueryRecode;
*/
}catch(Exception e){
e.printStackTrace();
return null;
}
支付宝接口返回的是实体类
/**
* 支付宝对账分页xml同步返回参数结果集
*PageAccountQueryRecode.java
*@author 汉维
*@email [email protected]
*@2014年9月11日下午1:16:38
*/
@XmlRootElement(name = "alipay")
@XmlAccessorType(XmlAccessType.FIELD)
public class PageAccountQueryRecode {
private String is_success;//请求是否成功
private String sign_type;//签名方式
private String sign;//签名
private String error;//错误提示码
private String has_next_page;//是否有下一页
private String page_no;//当前页号
private String page_size;//分页大小
private String account_log_list;//账务明细列表
private String gmt_end_time;//
private String gmt_start_time;//
private List accountQueryAccountLogVOList ;//单个账务明细集合
public List getAccountQueryAccountLogVOList() {
return accountQueryAccountLogVOList;
}
public void setAccountQueryAccountLogVOList(
List accountQueryAccountLogVOList) {
this.accountQueryAccountLogVOList = accountQueryAccountLogVOList;
}
public String getIs_success() {
return is_success;
}
public void setIs_success(String is_success) {
this.is_success = is_success;
}
public String getSign_type() {
return sign_type;
}
public void setSign_type(String sign_type) {
this.sign_type = sign_type;
}
public String getSign() {
return sign;
}
public void setSign(String sign) {
this.sign = sign;
}
public String getError() {
return error;
}
public void setError(String error) {
this.error = error;
}
public String getHas_next_page() {
return has_next_page;
}
public void setHas_next_page(String has_next_page) {
this.has_next_page = has_next_page;
}
public String getPage_no() {
return page_no;
}
public void setPage_no(String page_no) {
this.page_no = page_no;
}
public String getPage_size() {
return page_size;
}
public void setPage_size(String page_size) {
this.page_size = page_size;
}
public String getAccount_log_list() {
return account_log_list;
}
public void setAccount_log_list(String account_log_list) {
this.account_log_list = account_log_list;
}
public PageAccountQueryRecode(String is_success, String sign_type,
String sign, String error, String has_next_page, String page_no,
String page_size, String account_log_list,
List accountQueryAccountLogVOList) {
super();
this.is_success = is_success;
this.sign_type = sign_type;
this.sign = sign;
this.error = error;
this.has_next_page = has_next_page;
this.page_no = page_no;
this.page_size = page_size;
this.account_log_list = account_log_list;
this.accountQueryAccountLogVOList = accountQueryAccountLogVOList;
}
public PageAccountQueryRecode() {
super();
}
public String getGmt_end_time() {
return gmt_end_time;
}
public void setGmt_end_time(String gmt_end_time) {
this.gmt_end_time = gmt_end_time;
}
public String getGmt_start_time() {
return gmt_start_time;
}
public void setGmt_start_time(String gmt_start_time) {
this.gmt_start_time = gmt_start_time;
}
}