java 微信公众号支付,微信公众号提现到银行卡,企业付款到银行卡demo
开发文档:https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_1#
开通条件:
1、商户号已入驻90日
2、商户号有30天连续正常交易
3、 登录微信支付商户平台-产品中心,开通企业付款。
开始之前认真看一遍开发文档还是很有用的。
1、 调用获取RSA公钥API获取RSA公钥,落地成本地文件(PKCS#1)假设wx_public_key.pem
String url = "https://fraud.mch.weixin.qq.com/risk/getpublickey"; Map<String,String> map = new HashMap<>(); map.put("mch_id",Constant.WXPAY_MCHID); map.put("nonce_str", WXPayUtil.generateNonceStr()); map.put("sign_type","MD5"); map.put("sign", WXPayUtil.generateSignature(map,Constant.WXPAY_KEY)); String certificate_path = "conf"+File.separator+"apiclient_cert.p12"; String request = CommonUtil.request(url, WXPayUtil.mapToXml(map), certificate_path); return request;
2、 RSA公钥格式PKCS#1转PKCS#8
1)、openssl安装:http://blog.csdn.net/shiyong1949/article/details/78212971?locationNum=10&fps=1
2)、命令:openssl rsa -RSAPublicKey_in -in <filename> -pubout
3)、替换原来wx_public_key.pem文件的内容为转换后的PKCS#8(最终需要用的文件)
如下:
3、java 部分demo
String request = ""; Map<String,String> data = new HashMap<>(); if(WithDrawApplyTypeEnum.WxWalletWithdraw.getKey()==withdrawApply.getType().intValue()){ //提现到零钱 data = getWithdrawWalletMap(withdrawApply,withdrawApply.getPlatform().intValue()); request = CommonUtil.request(WXPayConstants.WITHDRAW_WALLET_URL, WXPayUtil.mapToXml(data), Constant.APICLIENT_CERT_P12); }else if(WithDrawApplyTypeEnum.WxBankWithdraw.getKey()==withdrawApply.getType().intValue()){ //提现到银行卡 data = getWithdrawBankMap(withdrawApply); request = CommonUtil.request(WXPayConstants.WITHDRAW_BANK_URL, WXPayUtil.mapToXml(data), Constant.APICLIENT_CERT_P12); } Map<String, String> result = WXPayUtil.xmlToMap(request); if("SUCCESS".equals(result.get(