Java springboot微信小程序提現,企業向個人付款

@Autowired
    WeixinMiniProgramPayProperties weixinPayProperties;

    @Override
    public Map enterprice2User(String logKey, String orderNumber, String openId, String fee, String body) throws Exception
    {
        //1.參數封裝 ,作者qq1023732997
        Map param = new HashMap();
        param.put("mch_appid", weixinPayProperties.getAppid());// 商戶賬號appid
        param.put("mchid", weixinPayProperties.getMchId());// 商戶
//        param.put("mch_id", weixinPayProperties.getMchId());// 商戶
        param.put("nonce_str", WXPayUtil.generateNonceStr());// 隨機字符串
        param.put("partner_trade_no", orderNumber);// 交易訂單號
//        param.put("out_trade_no", orderNumber);// 交易訂單號
        param.put("openid", openId); // 用戶openid
        param.put("check_name", "NO_CHECK"); // 校驗用戶姓名選項
        param.put("amount", fee); // 金額
//        param.put("total_fee", fee); // 金額
        param.put("desc", body);
//        param.put("body", body); // 商品描述
        param.put("spbill_create_ip", weixinPayProperties.getSpbillCreateIp());

        logger.info(logKey + " weixinPayProperties" + weixinPayProperties);
        String sign = WXPayUtil.generateSignature(param, weixinPayProperties.getPartnerkey());
        param.put("sign", sign);
        logger.info(logKey + " weixinService#enterprice2User:" + param);

//        HttpClient httpClient = new HttpClient(weixinPayProperties.getWechatTransfersUrl());
//        httpClient.setHttps(true);
//        httpClient.setXmlParam(xml2String(param));
//        httpClient.post();
//
//        String xmlResult = httpClient.getContent();
//        Map<String, String> mapResult = WXPayUtil.xmlToMap(xmlResult);

        String xmlResult = WXHttpCertUtils.doPost(weixinPayProperties.getWechatTransfersUrl(), xml2String(param));
        Map<String, String> mapResult = WXPayUtil.xmlToMap(xmlResult);
        logger.info(logKey + " weixinService#enterprice2User.wxpay.mp.result:" + mapResult);

        Map<String, String> result = new HashMap<>();
        result.put("code", "500");
        result.put("message", "系統錯誤");

        // {mchid=1520737191, mch_appid=wx2f030dd8ebda3a63, err_code=NOTENOUGH, return_msg=支付失敗, result_code=FAIL, err_code_des=餘額不足, return_code=SUCCESS}
        // 轉賬成功
        if("SUCCESS".equalsIgnoreCase(mapResult.get("result_code")))
        {
            result.put("code", "200");
            result.put("message", "支付成功");
        }
        // 轉帳失敗
        else if ("FAIL".equalsIgnoreCase(mapResult.get("result_code")))
        {
            result.put("code", "500");
            // 系統錯誤需要重試[請先調用查詢接口,查看此次付款結果,如結果爲不明確狀態(如訂單號不存在),請務必使用原商戶訂單號進行重試。
            if ("SYSTEMERROR".equalsIgnoreCase(mapResult.get("err_code")))
            {
//                result.put("message", "支付成功");]
            }
            // 金額超限
            else if("AMOUNT_LIMIT".equalsIgnoreCase(mapResult.get("err_code")))
            {
                result.put("message", "金額超限");
            }
            // 餘額不足
            else if("NOTENOUGH".equalsIgnoreCase(mapResult.get("err_code")))
            {
//                result.put("message", "支付成功");
            }
            // 超過頻率限制,請稍後再試。
            else if("FREQ_LIMIT".equalsIgnoreCase(mapResult.get("err_code")))
            {
                result.put("message", "超過頻率限制,請稍後再試。");
            }
            // 已經達到今日付款總額上限/已達到付款給此用戶額度上限
            else if("MONEY_LIMIT".equalsIgnoreCase(mapResult.get("err_code")))
            {
                result.put("message", "已經達到今日付款總額上限");
            }
            // 無法給非實名用戶付款
            else if ("V2_ACCOUNT_SIMPLE_BAN".equalsIgnoreCase(mapResult.get("err_code")))
            {
                result.put("message", "無法給非實名用戶付款");
            }
            // 該用戶今日付款次數超過限制,如有需要請登錄微信支付商戶平臺更改API安全配置
            else if("SENDNUM_LIMIT".equalsIgnoreCase(mapResult.get("err_code")))
            {
                result.put("message", "今日付款次數超過限制");
            }
        }
        else
        {
            // 系統錯誤
            result.put("code", "500");
            result.put("message", "系統錯誤");
        }

        return result;
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章