Java微信支付之关闭订单

2025-05-29 0 59

本文实例为大家分享了java微信支付之关闭订单的具体代码,供大家参考,具体内容如下

官方文档

一、应用场景

商户订单支付失败需要生成新单号重新发起支付,要对原订单号调用关单,避免重复支付
系统下单后,用户支付超时,系统退出不再受理,避免用户继续,请调用关单接口
注意:订单生成后不能马上调用关单接口,最短调用时间间隔为5分钟。

二、接口地址

https://api.mch.weixin.qq.com/pay/closeorder

三、请求参数

只能根据自己商户系统的订单号关闭

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27
package com.phil.wechatpay.model.rep;

import java.io.serializable;

/**

* 关闭订单请求参数(正常xml)

* @author phil

* @date 2017年7月25日

*

*/

public class closeorderparams extends abstractpayparams implements serializable{

/**

*

*/

private static final long serialversionuid = -4206464928803827244l;

private string out_trade_no; //商户订单号

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;

}

}

四、返回结果

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28
package com.phil.wechatpay.model.resp;

import java.io.serializable;

import com.phil.common.annotation.notrequire;

/**

* 关闭订单返回参数(带<![cdata[]]>xml格式)

*

* @author phil

* @date 2017年7月25日

*

*/

public class closeorderresult extends abstractpayresult implements serializable {

private static final long serialversionuid = -1996103742747816922l;

private string return_code; // 返回状态码success/fail

@notrequire

private string return_msg; //返回信息

/**** return_code 为success ****/

private string result_code;// 业务结果

private string result_msg;// 业务结果描述

@notrequire

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

@notrequire

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

}

五、关闭订单

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52
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.resp.closeorderresult;

import com.phil.wechatpay.service.wechatpayservice;

/**

* 关闭订单

* @author phil

* @date 2017年7月25日

*

*/

@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("");//自己传入

//请求的xml

string closeorderxml = wechatpayservice.abstractpaytoxml(closeorderparams);//签名合并到service

// 返回<![cdata[success]]>格式的xml

string closeorderresultxml = httprequtil.httpsdefaultexecute(httprequtil.post_method,wechatconfig.close_order_url, null, closeorderxml);

// 进行签名校验

if (signatureutil.checkissignvalidfromweixin(closeorderresultxml)) {

closeorderresult = xmlutil.getobjectfromxml(closeorderresultxml, closeorderresult.class);

}

return closeorderresult;

}

}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持快网idc。

原文链接:https://blog.csdn.net/phil_jing/article/details/77948695

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 Java微信支付之关闭订单 https://www.kuaiidc.com/111734.html

相关文章

发表评论
暂无评论