0
点赞
收藏
分享

微信扫一扫

【SpringBoot学习】40、SpringBoot 集成 wxJava 微信小程序:订单退款

爱做梦的老巫婆 2022-03-25 阅读 55

文章目录

SpringBoot 集成 wxJava 微信小程序:订单退款

1、退款流程

    @ApiOperation(value = "退款")
    @PostMapping("refund")
    public AjaxResult refund(@RequestBody WxRefundVo entity) {
        return weiXinPayService.refund(entity);
    }
    /**
     * 退款
     * https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_4
     * @return
     * @param entity
     */
    AjaxResult refund(WxRefundVo entity);

    @Override
    public AjaxResult refund(WxRefundVo entity) {
        try {
            WxPayRefundRequest request = new WxPayRefundRequest();
            request.setAppid(wxPayProperties.getAppId());
            request.setMchId(wxPayProperties.getMchId());
            // 商户订单号
            request.setOutTradeNo("8152f7d6-3e0a-4e55-9618-b5a7baa9");
            // 商户退款单号
            request.setOutRefundNo("TK" + UUID.randomUUID().toString().replace("-", "").substring(0, 30));
            // 订单金额
            request.setTotalFee((int) (0.01 * 100));
            // 退款金额
            request.setRefundFee((int) (0.01 * 100));
            // 退款原因
            request.setRefundDesc("常规退款");
            WxPayRefundResult refund = wxPayService.refund(request);
            log.info("退款结果:{}", refund);
            return AjaxResult.success("退款成功");
        } catch (WxPayException e) {
            log.error("退款失败:{}", e.toString());
            return AjaxResult.error(e.getMessage());
        }
    }

2、前端测试退款

实际参数根据业务请求

<template>
  <view style="padding: 15px;">
    <u-button @click="submit" type="primary">订单退款</u-button>
  </view>
</template>

<script>
let that;
export default {
  name: "sedMessage",
  data() {
    return {
    }
  },
  onLoad() {
    that = this;
  },
  methods: {
    submit() {
      that.$u.post('/au/weixinPay/refund', {}).then(res => {
        that.$msg(res.msg);
      });
    }
  }
}
</script>

<style scoped>

</style>

微信公众号

举报

相关推荐

0 条评论