WeChat Pay for Corporate Payments


Overview

Provides the function of enterprises paying to users, and supports enterprises to pay through API interface, or to operate payment through the webpage function of WeChat Pay merchant platform.

There are two ways for
business payment 1. Business payment to change
2. Business payment to bank

Conditions for opening: 1. The merchant account has been registered for
90 days
. 2. The merchant account has been in regular transactions for 30 consecutive days .

Need to recharge before payment:
before calling the API interface for payment or operating payment through the WeChat payment merchant platform webpage function, you need to log in to the WeChat payment merchant platform, and recharge through the webpage recharge function (merchant platform - transaction center)

充值, 商户平台网页功能操作付款, please refer to the official documentation其他限制条件 for details

Here's how to passAPI接口付款

Certificate download

Refer to Security Specifications -3. Merchant Certificate

Download: WeChat Merchant Platform (pay.weixin.qq.com) –> Account Center –> Account Settings –> API Security –> Certificate Download

Business payment to change

How to get openId when paying to change openId? Refer to authorization to obtain user information

Interface in IJPay

https://gitee.com/Javen205/IJPay
https://github.com/Javen205/IJPay

  • Business payment to change
  • Inquire about business payments
    /**
     * 企业付款到零钱
     * @param params
     *            请求参数
     * @param certPath
     *            证书文件目录
     * @param certPassword
     *            证书密码
     * @return {String}
     */
    public static String transfers(Map<String, String> params, String certPath, String certPassword) {
        return WxPayApi.doPostSSL(TRANSFERS_URL, params, certPath, certPassword);
    }

    /**
     * 查询企业付款到零钱
     * @param params
     *            请求参数
     * @param certPath
     *            证书文件目录
     * @param certPassword
     *            证书密码
     * @return {String}
     */
    public static String getTransferInfo(Map<String, String> params, String certPath, String certPassword) {
        return WxPayApi.doPostSSL(GETTRANSFERINFO_URL, params, certPath, certPassword);
    }

code example

https://github.com/Javen205/IJPay-Demo

    /**
     * 企业付款到零钱
     */
    public void transfers() {
        String openId = getSessionAttr("openId");
        Map<String, String> params = new HashMap<String, String>();
        params.put("mch_appid", appid);
        params.put("mchid", mch_id);
        String nonceStr = String.valueOf(System.currentTimeMillis());
        params.put("nonce_str", nonceStr);
        String partnerTradeNo = String.valueOf(System.currentTimeMillis());
        params.put("partner_trade_no", partnerTradeNo);
        params.put("openid", openId);
        params.put("check_name", "NO_CHECK");
        params.put("amount", "100");
        params.put("desc", "IJPay提现测试-By Javen");
        String ip = IpKit.getRealIp(getRequest());
        if (StrKit.isBlank(ip)) {
            ip = "127.0.0.1";
        }
        params.put("spbill_create_ip", ip);

        params.put("sign", PaymentKit.createSign(params, partnerKey));
System.out.println("certPath>"+certPath);
        // 提现
        String transfers = WxPayApi.transfers(params, certPath, mch_id);

        log.info("提现结果:" + transfers);
        System.out.println("提现结果:" + transfers);

        Map<String, String> map = PaymentKit.xmlToMap(transfers);
        String return_code = map.get("return_code");
        String result_code = null;
        if (("SUCCESS").equals(return_code)) {
            result_code = map.get("result_code");
            if (("SUCCESS").equals(result_code)) {
                //提现成功
            } else {
                //提现失败
            }
        }
        renderText(transfers);
    }
    /**
     * 查询企业付款到零钱
     */
    public void transferInfo() {
        try {
            String partner_trade_no = getPara("partner_trade_no");
            Map<String, String> params = new HashMap<String, String>();
            params.put("nonce_str", System.currentTimeMillis()+"");
            params.put("partner_trade_no", partner_trade_no);
            params.put("mch_id", mch_id);
            params.put("appid", appid);
            params.put("sign", PaymentKit.createSign(params, partnerKey));

            String transferInfo = WxPayApi.getTransferInfo(params , certPath, mch_id);
            renderText(transferInfo);
        } catch (Exception e) {
            e.printStackTrace();
            renderText(e.getMessage());
        }
    }

Business payment to bank card

  • Two-way certificate required
  • The payee's bank card number and user name need to be encrypted with RSA algorithm
  • The interface outputs the public key in PKCS#1 format by default. Java RSA encryption needs to use PKCS#8, otherwise there will be an abnormal algid parse error, not a sequence ​Official document
<xml>
<return_code><![CDATA[SUCCESS]]></return_code>
<return_msg><![CDATA[OK]]></return_msg>
<result_code><![CDATA[SUCCESS]]></result_code>
<mch_id><![CDATA[1262075601]]></mch_id>
<pub_key><![CDATA[-----BEGIN RSA PUBLIC KEY-----
MIIBCgKCAQEA6Bl76IwSvBTiibZ+CNRUA6BfahMshZ0WJpHD1GpmvcQjeN6Yrv6c
9eIl6gB4nU3isN7bn+LmoVTpH1gHViaV2YyG/zXj4z4h7r+V+ezesMqqorEg38BC
NUHNmhnw4/C0I4gBAQ4x0SJOGnfKGZKR9yzvbkJtvEn732JcEZCbdTZmaxkwlenX
vM+mStcJaxBCB/h5xJ5VOF5nDbTPzLphIpzddr3zx/Jxjna9QB1v/YSKYXn+iuwr
uNUXGCvvxBWaBGKrjOdRTRy9adWOgNmtuYDQJ2YOfG8PtPe06ELKjmr2CfaAGrKK
UroyaGvy3qxAV0PlT+UQ4ADSXWt/zl0o5wIDAQAB
-----END RSA PUBLIC KEY-----
]]></pub_key>
</xml>

Save the obtained to a pub_keyfilepublic.pem

-----BEGIN RSA PUBLIC KEY-----
MIIBCgKCAQEA6Bl76IwSvBTiibZ+CNRUA6BfahMshZ0WJpHD1GpmvcQjeN6Yrv6c
9eIl6gB4nU3isN7bn+LmoVTpH1gHViaV2YyG/zXj4z4h7r+V+ezesMqqorEg38BC
NUHNmhnw4/C0I4gBAQ4x0SJOGnfKGZKR9yzvbkJtvEn732JcEZCbdTZmaxkwlenX
vM+mStcJaxBCB/h5xJ5VOF5nDbTPzLphIpzddr3zx/Jxjna9QB1v/YSKYXn+iuwr
uNUXGCvvxBWaBGKrjOdRTRy9adWOgNmtuYDQJ2YOfG8PtPe06ELKjmr2CfaAGrKK
UroyaGvy3qxAV0PlT+UQ4ADSXWt/zl0o5wIDAQAB
-----END RSA PUBLIC KEY-----

Convert public key in PKCS#1 format to public key in PKCS#8 format

Convert public key in PKCS#1 format to PKCS#8

Interface in IJPay

  • Business payment to bank card
  • Query business payment to bank card
  • Get RSA encryption public key
    /**
     * 企业付款到银行
     * @param params
     *            请求参数
     * @param certPath
     *            证书文件目录
     * @param certPassword
     *            证书密码
     * @return {String}
     */
    public static String payBank(Map<String, String> params, String certPath, String certPassword) {
        return WxPayApi.doPostSSL(PAY_BANK_URL, params, certPath, certPassword);
    }

    /**
     * 查询企业付款到银行
     * @param params
     *            请求参数
     * @param certPath
     *            证书文件目录
     * @param certPassword
     *            证书密码
     * @return {String}
     */
    public static String queryBank(Map<String, String> params, String certPath, String certPassword) {
        return WxPayApi.doPostSSL(QUERY_BANK_URL, params, certPath, certPassword);
    }
    /**
     * 获取RSA加密公钥
     * @param params
     *            请求参数
     * @param certPath
     *            证书文件目录
     * @param certPassword
     *            证书密码
     * @return {String}
     */
    public static String getPublicKey(Map<String, String> params, String certPath, String certPassword) {
        return WxPayApi.doPostSSL(GETPUBLICKEY_URL, params, certPath, certPassword);
    }

sample code

    /**
     * 获取RSA加密公钥
     * 接口默认输出PKCS#1格式的公钥,商户需根据自己开发的语言选择公钥格式
     * Java RSA加密需要使用PKCS#8 不然会出现异常algid parse error, not a sequence​
     * PKCS#1 转 PKCS#8:
     * openssl rsa -RSAPublicKey_in -in <filename> -pubout
     */
    public void getPublicKey(){
        try {
            Map<String, String> params = new HashMap<String, String>();
            params.put("mch_id", mch_id);
            params.put("nonce_str", String.valueOf(System.currentTimeMillis()));
            params.put("sign_type", "MD5");
            String createSign = PaymentKit.createSign(params, partnerKey);
            params.put("sign", createSign);
            String publicKeyStr = WxPayApi.getPublicKey(params , certPath, mch_id);
            renderText(publicKeyStr);
        } catch (Exception e) {
            e.printStackTrace();
            renderText(e.getMessage());
        }
    }
    /**
     * 企业付款到银行卡
     */
    public void payBank() {
        try {
            //假设获取到的RSA加密公钥为PUBLIC_KEY(PKCS#8格式)
            final String PUBLIC_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6Bl76IwSvBTiibZ+CNRUA6BfahMshZ0WJpHD1GpmvcQjeN6Yrv6c9eIl6gB4nU3isN7bn+LmoVTpH1gHViaV2YyG/zXj4z4h7r+V+ezesMqqorEg38BCNUHNmhnw4/C0I4gBAQ4x0SJOGnfKGZKR9yzvbkJtvEn732JcEZCbdTZmaxkwlenXvM+mStcJaxBCB/h5xJ5VOF5nDbTPzLphIpzddr3zx/Jxjna9QB1v/YSKYXn+iuwruNUXGCvvxBWaBGKrjOdRTRy9adWOgNmtuYDQJ2YOfG8PtPe06ELKjmr2CfaAGrKKUroyaGvy3qxAV0PlT+UQ4ADSXWt/zl0o5wIDAQAB";   

            Map<String, String> params = new HashMap<String, String>();
            params.put("mch_id", mch_id);
            params.put("partner_trade_no", System.currentTimeMillis()+"");
            params.put("nonce_str", System.currentTimeMillis()+"");
            params.put("enc_bank_no", RSAUtils.encryptByPublicKeyByWx("6214837805417833", PUBLIC_KEY));//收款方银行卡号
            params.put("enc_true_name", RSAUtils.encryptByPublicKeyByWx("周业文", PUBLIC_KEY));//收款方用户名    
            params.put("bank_code", "1001");//收款方开户行        
            params.put("amount", "1");
            params.put("desc", "IJPay 测试付款到银行卡-By Javen");
            params.put("sign", PaymentKit.createSign(params, partnerKey));
            String payBank = WxPayApi.payBank(params , certPath, mch_id);
            renderText(payBank);
        } catch (Exception e) {
            e.printStackTrace();
            renderText(e.getMessage());
        }
    }
    /**
     * 查询企业付款到银行
     */
    public void queryBank() {
        try {
            String partner_trade_no = getPara("partner_trade_no");
            Map<String, String> params = new HashMap<String, String>();
            params.put("mch_id", mch_id);
            params.put("partner_trade_no", partner_trade_no);
            params.put("nonce_str", System.currentTimeMillis()+"");
            params.put("sign", PaymentKit.createSign(params, partnerKey));
            String queryBank = WxPayApi.queryBank(params, certPath, mch_id);
            renderText(queryBank);
        } catch (Exception e) {
            e.printStackTrace();
            renderText(e.getMessage());
        }

    }

WeChat payment, Alipay payment blog column

IJPay puts payments at your fingertips with access to documents

If you have any questions, please leave a message for discussion

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325726024&siteId=291194637