This article shares the specific code for java WeChat payment closing orders for your reference. The specific content is as follows
Official Documentation
1. Application scenarios
Merchant order payment failed and needs to generate a new order number and initiate payment again. You must call the check order for the original order number to avoid repeated payment system payment timeout, and the system exit will no longer be accepted. To avoid the user's order, please call the check order interface.
Note: The order-off interface cannot be called immediately after the order is generated, and the minimum call time interval is 5 minutes.
2. Interface address
https://api.mch.weixin.qq.com/pay/closeorder
3. Request parameters
Only close according to the order number of your merchant system
package com.phil.wechatpay.model.rep; import java.io.Serializable; /** * Close order request parameters (normal XML) * @author phil * @date July 25, 2017* */ public class CloseOrderParams extends AbstractPayParams implements Serializable{ /** * */ private static final long serialVersionUID = -4206464928803827244L; private String out_trade_no; // Merchant order number 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; } }4. Return the result
package com.phil.wechatpay.model.resp; import java.io.Serializable; import com.phil.common.annotation.NotRequire; /** * Close order return parameter (with <![CDATA[]]>XML format) * * @author phil * @date July 25, 2017* */ public class CloseOrderResult extends AbstractPayResult implements Serializable { private static final long serialVersionUID = -1996103742747816922L; private String return_code; // Return status code SUCCESS/FAIL @NotRequire private String return_msg; //Return information/**** return_code is SUCCESS ****/ private String result_code;// Business result private String result_msg;// Business result description @NotRequire private String err_code;// Error return information description @NotRequire private String err_code_des;// Error return information description}5. Close the order
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.CloseOrderParams; import com.phil.wechatpay.model.rep.CloseOrderResult; import com.phil.wechatpay.service.WechatPayService; /** * Close order* @author phil * @date July 25, 2017* */ @Controller @RequestMapping("/wxpay/") public class WeChatPayCloseOrderController { @Autowired private WechatPayService wechatPayService; @ResponseBody @RequestMapping("closeOrder") public CloseOrderResult closeOrder(HttpServletRequest request, HttpServletResponse response) throws Exception { CloseOrderResult closeOrderResult = null; CloseOrderParams closeOrderParams = new CloseOrderParams(); closeOrderParams.setAppid(WechatConfig.APP_ID); closeOrderParams.setMch_id(WechatConfig.MCH_ID); closeOrderParams.setNonce_str(PayUtil.createNonceStr()); closeOrderParams.setOut_trade_no(""); // Pass in // Requested xml String closeOrderXml = wechatPayService.abstractPayToXml(closeOrderParams);//Merge the signature into service // Return XML in <![CDATA[SUCCESS]]> format String closeOrderResultXmL = HttpReqUtil.HttpsDefaultExecute(HttpReqUtil.POST_METHOD,WechatConfig.CLOSE_ORDER_URL, null, closeOrderXml); // Perform signature verification if (SignatureUtil.checkIsSignValidFromWeiXin(closeOrderResultXmL)) { closeOrderResult = XmlUtil.getObjectFromXML(closeOrderResultXmL, CloseOrderResult.class); } return closeOrderResult; } }The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.