微信退款

微信退款其实跟微信支付差不多,也需要签名,通过签名后请求退款地址。其中需要加载微信退款的证书,关于证书可以上

微信商户平台登录下载。

基本代码如下:

        SortedMap<String, String> sm=new TreeMap<>();
sm.put("appid", AppWxConfig.appid);//应用id
sm.put("mch_id", AppWxConfig.mch_id);//商户id
String str=AppPayUtil.create_nonce_str();
sm.put("nonce_str", str);//随机字符串
sm.put("out_trade_no", orders.getOrderNo());//商户订单号
sm.put("out_refund_no", "123321");//商户退款单号

String s=orders.getPayMoney();
int s1=(int)(Double.valueOf(s)*100);
sm.put("total_fee", String.valueOf(s1));//订单金额

sm.put("refund_fee","1");//退款金额

String sign=" ";//定义签名

/*
* 生成签名
*/
sign=AppPayUtil.createSign("UTF-8", sm,AppWxConfig.wx_api_key);

sm.put("sign", sign);//签名

String xml=AppPayUtil.getRequestXml(sm);//封装xml数据

RefundRequest refundRequest = new RefundRequest(); 
String result1=refundRequest.httpsRequest(AppWxConfig.REFUND_URL, xml, AppWxConfig.certPath);//请求退款地址
System.out.println("------------------------"+result1);
 
Map<String, Object> getMap = XmlConverUtil.xmltoMap(new String(result1.toString().getBytes())); 
           if("SUCCESS".equals(getMap.get("return_code")) && "SUCCESS".equals(getMap.get("return_msg"))){  
               result.put("code", getMap.get("return_code"));
               result.put("message", getMap.get("return_msg"));

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值