/**
* 微信提现零钱
*/
@Override
public AjaxResult withdraw(PayVo payVo) {
String outTradeNo = WXPayUtil.generateNonceStr();
Map<String,String> param = new HashMap<>();
param.put("mch_appid",appId);
param.put("mchid",michIdPatient);
param.put("nonce_str",outTradeNo);
param.put("partner_trade_no",outTradeNo);
param.put("openid",payVo.getOpenId());
param.put("check_name","NO_CHECK");
param.put("amount",String.valueOf(payVo.getTotalPrice() * 100));
param.put("desc","withdraw");//提现
param.put("spbill_create_ip",spbillCreateIp);
try {
//创建流水
String xml = WXPayUtil.generateSignedXml(param, apikeyPatient);
xml = new String(xml.getBytes("UTF-8"), "ISO8859-1");
//2.发送请求
CloseableHttpClient httpClient = null;
CloseableHttpResponse httpResponse = null;
KeyStore keyStore = getCertificate(michIdPatient);
SSLContext sslContext = SSLContexts.custom().loadKeyMaterial(keyStore, michIdPatient.toCharArray()).build();
SSLConnectionSocketFactory sslf = new SSLConnectionSocketFactory(sslContext);
httpClient = HttpClients.custom().setSSLSocketFactory(sslf).build();
HttpPost httpPost = new HttpPost(withdrawUrl);
StringEntity reqEntity = new StringEntity(xml);
// 设置类型
reqEntity.setContentType("application/x-www-form-urlencoded");
httpPost.setEntity(reqEntity);
httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
String resultStr = EntityUtils.toString(httpEntity, "UTF-8");
log.info("微信响应报文:" + resultStr);
EntityUtils.consume(httpEntity);
//提现成功
Map<String, String> str = WXPayUtil.xmlToMap(resultStr);
if ("SUCCESS".equals(str.get("result_code"))) {
//修改流水状态
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
微信零钱提现
最新推荐文章于 2024-07-24 16:29:50 发布