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

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(030));
            // 订单金额
            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>

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

更多微信小程序

SpringBoot 学习】42、SpringBoot 集成 wxJava 微信小程序:客服消息 【SpringBoot 学习】41、SpringBoot 集成 wxJava 微信小程序:模板消息 【SpringBoot 学习】39、SpringBoot 集成 wxJava 微信小程序:订单支付 【SpringBoot 学习】38、SpringBoot 集成 wxJava 微信小程序:授权登录

微信公众号


原文始发于微信公众号(花海里):【SpringBoot学习】40、SpringBoot 集成 wxJava 微信小程序:订单退款

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/69592.html

(0)
小半的头像小半

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!