微信订单查询java开发_Java微信支付开发之查询订单

该接口提供所有微信支付订单的查询,商户可以通过查询订单接口主动查询订单状态,完成下一步的业务逻辑。

一、应用场景

当商户后台、网络、服务器等出现异常,商户系统最终未接收到支付通知

调用支付接口后,返回系统错误或未知交易状态情况

调用刷卡支付API,返回USERPAYING的状态

调用关单或撤销接口API之前,需确认支付状态

二、请求参数

可以根据微信订单号(优先使用)或者商户订单号进行查询

package com.phil.wechatpay.model.rep;

import java.io.Serializable;

/**

* 查询订单请求参数(正常XML)

* @author phil

* @date 2017年7月25日

*

*/

public class OrderQueryParams extends AbstractPayParams implements Serializable{

/**

*

*/

private static final long serialVersionUID = -168458096490563992L;

private String transaction_id; //微信订单号,优先

private String out_trade_no; //商户订单号 二选一

public String getTransaction_id() {

return transaction_id;

}

public void setTransaction_id(String transaction_id) {

this.transaction_id = transaction_id;

}

public String getOut_trade_no() {

return out_trade_no;

}

public void setOut_trade_no(String out_trade_no) {

this.out_trade_no = out_trade_no;

}

}

三、返回结果

自己酌情封装

package com.phil.wechatpay.model.resp;

import java.io.Serializable;

import com.phil.common.annotation.NotRequire;

/**

* 查询订单返回参数(带XML格式)

*

* @author phil

* @date 2017年7月25日

*

*/

public class OrderQueryResult extends AbstractPayResult implements Serializable {

/**

*

*/

private static final long serialVersionUID = -1996103742747816922L;

private String return_code; // 返回状态码SUCCESS/FAIL

@NotRequire

private String err_code;// 错误返回的信息描述

@NotRequire

private String err_code_des;// 错误返回的信息描述

/**** return_code 、result_code、trade_state ***为SUCCESS ****/

.....

}

四、查询订单

package com.phil.wechatpay.controller;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;

import com.phil.common.config.WechatConfig;

import com.phil.common.util.HttpReqUtil;

import com.phil.common.util.PayUtil;

import com.phil.common.util.SignatureUtil;

import com.phil.common.util.XmlUtil;

import com.phil.wechatpay.model.rep.OrderQueryParams;

import com.phil.wechatpay.model.resp.OrderQueryResult;

import com.phil.wechatpay.service.WechatPayService;

/**

* 查询订单

* @author phil

* @date 2017年7月25日

*

*/

@Controller

@RequestMapping("/wxpay/")

public class WechatPayOrderQueryController {

@Autowired

private WechatPayService wechatPayService;

@ResponseBody

@RequestMapping("orderQuery")

public OrderQueryResult orderQuery(HttpServletRequest request, HttpServletResponse response) throws Exception {

OrderQueryResult orderQueryResult = null;

OrderQueryParams orderQueryParams = new OrderQueryParams();

orderQueryParams.setAppid(WechatConfig.APP_ID);

orderQueryParams.setMch_id(WechatConfig.MCH_ID);

orderQueryParams.setNonce_str(PayUtil.createNonceStr());

orderQueryParams.setTransaction_id(""); //二者选其一,推荐transaction_id

//orderQueryParams.setOut_trade_no("");

//请求的xml

String orderQueryXml = wechatPayService.abstractPayToXml(orderQueryParams);//签名合并到service

// 返回格式的XML

String orderQueryResultXmL = HttpReqUtil.HttpsDefaultExecute(HttpReqUtil.POST_METHOD,WechatConfig.ORDER_QUERY_URL, null, orderQueryXml);

// 进行签名校验

if (SignatureUtil.checkIsSignValidFromWeiXin(orderQueryResultXmL)) {

orderQueryResult = XmlUtil.getObjectFromXML(orderQueryResultXmL, OrderQueryResult.class);

}

return orderQueryResult;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值