微信退款---内附源码

今天更新一波微信退款的操作,微信退款,最主要的数据就是订单号,如果有了订单号我们就能从数据库中获取之前我们所支付成功的订单所有的数据,废话不多少来码!
Controller

//	@RequestMapping("refund")
//	public void refund(HttpServletRequest request) throws Exception{
//		String tradeno = request.getParameter("tradeno");
//		paymanager.reFund(tradeno);
//	}

这里为什么要注释起来呢?原因很简单,怕被别人恶意获取到你的订单号直接请求退款,那事情岂不是大条了!!!
Service

//退款
	public Map<String, String> reFund(String tradeno){
		WXPayConfigImpl payconfig;
		try {
			payconfig = WXPayConfigImpl.getInstance(config.getKey(), config.getAppID(),
					config.getMchID(), config.getCertLocalPath());
			WXPay wxpay = new WXPay(payconfig);
			HashMap<String, String> data = new HashMap<String, String>();
			WXPayOrders order = wxpayDao.getOrder(tradeno);
			String refundno = "T" + tradeno;
	        data.put("out_trade_no", tradeno);
	        data.put("out_refund_no", refundno);//退款订单号
	        data.put("total_fee", order.getTotalfee()+"");//总价格
	        data.put("refund_fee", order.getTotalfee()+"");//退款价格
	        data.put("refund_fee_type", "CNY");
	        data.put("op_user_id", config.getMchID());

	       
	        Map<String, String> r = wxpay.refund(data);
	        if(r.get("return_code").equals("SUCCESS") && r.get("result_code").equals("SUCCESS")){
	        	wxpayDao.reFund(tradeno,refundno);
	        }
	        return r;
	       
		} catch (Exception e) {
//			e.printStackTrace();
			Util.logException("微信退款失败", e);
			return null;
		}	
	}

WXpay

 /**
     * 作用:申请退款<br>
     * 场景:刷卡支付、公共号支付、扫码支付、APP支付
     * @param reqData 向wxpay post的请求数据
     * @return API返回数据
     * @throws Exception
     */
    public Map<String, String> refund(Map<String, String> reqData) throws Exception {
        return this.refund(reqData, this.config.getHttpConnectTimeoutMs(), this.config.getHttpReadTimeoutMs());
    }

上面那就是微信提供的代码。
走到这一部,你就能发现退款成功了。
有时候需要退回到某些页面比如

WeixinJSBridge.call('closeWindow');

直接退回到公众号页面上了,同时给出个友好提示就好了嘛!!!!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

丶懿

你的鼓励是我最大的创作动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值