微信支付-电商收付通开发-06.商户提现

查询二级商户余额

这里的特殊情况下商家可以在微信支付平台直接申请提现,我自己测试的小微商户并没有发现可以提现的地方,不过可以修改结算银行卡信息。
在这里插入图片描述
测试类代码:


    /**
     * 查询账户实时余额
     */
    @Test
    public void queryBalance() {
        String param = WxPayConfig.testMerchantId;
        Map<String, String> headersMap = WxPayUtils.getHeaderMap("GET", WxPayConfig.fund_balance_ecommerce_query_url + param, "");
        ResponseAndStatusAndHeaders response = ClientUtil.getAndPostJson("GET", WxPayConfig.fund_balance_ecommerce_query_url + param, null, headersMap);
        if (response.getStatus() != Status.SUCCESS || response.getResponseData() == null) {
            LogUtil.printErrorLog(LogUtil.log_front_wxpay + "查询账户实时余额请求错误,返回信息为:\n" + response.toString() + "\n请求的参数为:\n" + param + "\n\n");
            return;
        }
        LogUtil.printInfoLog(LogUtil.log_front_wxpay + "查询账户实时余额请求成功,返回信息为:\n" + response.toString() + "\n请求的参数为:\n" + param + "\n\n");
        /*{
            "available_amount": 119,
            "pending_amount": 10,
            "sub_mchid": "1595728911"
        }*/
    }

二级商户余额提现

提现流程图:
在这里插入图片描述

  • 提现微信不收取手续费,全额到账。
  • 提现会在第二天到账银行卡中。

测试类代码:

    /**
     * 商户余额提现
     */
    @Test
    public void mchWithdraw() {
        JSONObject reqJsonObject = new JSONObject();
        //二级商户号
        reqJsonObject.put("sub_mchid", WxPayConfig.testMerchantIdHht);
        //平台提现订单号(字母数字)
        reqJsonObject.put("out_request_no", "20200527584262");
        //提现金额
        reqJsonObject.put("amount", 10);

        Map<String, String> headersMap = WxPayUtils.getHeaderMap("POST", WxPayConfig.fund_withdraw_ecommerce_url, reqJsonObject.toJSONString());
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqJsonObject.toJSONString());

        ResponseAndStatusAndHeaders response = ClientUtil.getAndPostJson("POST", WxPayConfig.fund_withdraw_ecommerce_url, requestBody, headersMap);
        if (response.getStatus() != Status.SUCCESS || response.getResponseData() == null) {
            LogUtil.printErrorLog(LogUtil.log_front_wxpay + "请求二级商户提现接口错误,返回信息为:\n" + response.toString() + "\n请求的参数为:\n" + reqJsonObject + "\n\n");
            return;
        }
        LogUtil.printInfoLog(LogUtil.log_front_wxpay + "请求二级商户提现接口成功,返回信息为:\n" + response.toString() + "\n请求的参数为:\n" + reqJsonObject + "\n\n");

        JSONObject jsonObject = JSON.parseObject(response.getResponseData().toString());
        /*{
            "out_request_no": "20200527584262",
            "sub_mchid": "1595728911",
            "withdraw_id": "209000120887412202005281822192220"
        }*/
        String withdraw_id = jsonObject.getString("withdraw_id");
        System.out.println("提现成功,微信支付提现订单号为:" + withdraw_id);
    }

查询二级商户提现单

  • 只支持查询90天内的提现订单
  • 两种查询方式(微信支付提现单号和商户提现单号查询),两种查询方式返回结果一致。

测试类代码:

    /**
     * 查询提现状态接口(仅支持90天内)
     */
    @Test
    public void queryWithdraw() {
        String param = "2005282315530253" + "?sub_mchid=" + WxPayConfig.testMerchantId;
        Map<String, String> headersMap = WxPayUtils.getHeaderMap("GET", WxPayConfig.fund_withdraw_ecommerce_query_url + param, "");

        ResponseAndStatusAndHeaders response = ClientUtil.getAndPostJson("GET", WxPayConfig.fund_withdraw_ecommerce_query_url + param, null, headersMap);
        if (response.getStatus() != Status.SUCCESS || response.getResponseData() == null) {
            LogUtil.printErrorLog(LogUtil.log_front_wxpay + "查询提现状态接口请求错误,返回信息为:\n" + response.toString() + "\n请求的参数为:\n" + param + "\n\n");
            return;
        }
        LogUtil.printInfoLog(LogUtil.log_front_wxpay + "查询提现状态接口请求成功,返回信息为:\n" + response.toString() + "\n请求的参数为:\n" + param + "\n\n");

        JSONObject jsonObject = JSON.parseObject(response.getResponseData().toString());
        /*{
            "amount": 10,
            "bank_memo": "",
            "create_time": "2020-05-28T16:19:55+08:00",
            "out_request_no": "20200527584262",
            "reason": "",
            "remark": "",
            "sp_mchid": "1586786671",
            "status": "CREATE_SUCCESS",
            "sub_mchid": "1595728911",
            "update_time": "2020-05-28T16:19:55+08:00",
            "withdraw_id": "209000120887412202005281822192220"
        }*/

        /*提现状态,枚举值:
        CREATE_SUCCESS:受理成功
        SUCCESS:提现成功
        FAIL:提现失败
        REFUND:提现退票
        CLOSE:关单*/
        String status = jsonObject.get("status").toString();
        //更新时间
        Timestamp timestamp = DateUtil.stringToTimestampByFormatStr(jsonObject.get("update_time").toString(), DateUtil.dateFormat18);
        //失败原因
        String reason = jsonObject.get("reason").toString();
        System.out.println("提现单状态为:" + status);
    }

参考链接

微信电商收付通-余额提现API文档:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/fund/chapter3_2.shtml
微信电商收付通-余额查询API文档:
https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/amount/chapter3_1.shtml

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值