java 微信转账_java配合uniapp的微信支付、商户转账等解决方案

private static final String TRANSFERS_PAY = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers";

private static final String TRANSFERS_PAY_QUERY = "https://api.mch.weixin.qq.com/mmpaymkttransfers/gettransferinfo";

private static final String APP_ID = MyWxpayConfig.APP_ID;private static final String MCH_ID =MyWxpayConfig.MCH_ID;

publicMap wxSendWallet (IP地址) {boolean tansferStatus=false;

String responseInfo="";String xml=wxSendWallet(用户openId,金额,IP地址 );try{//指定读取证书格式为PKCS12

KeyStore keyStore = KeyStore.getInstance("PKCS12");

InputStream instream = Thread.currentThread().getContextClassLoader().getResourceAsStream("cert/apiclient_cert.p12");try{

keyStore.load(instream, MyWxpayConfig.MCH_ID.toCharArray());

}finally{

instream.close();

}

SSLContext sslcontext =SSLContexts.custom().loadKeyMaterial(keyStore, MyWxpayConfig.MCH_ID.toCharArray()).build();

SSLConnectionSocketFactory sslsf = newSSLConnectionSocketFactory(

sslcontext,new String[]{"TLSv1"}, null, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

CloseableHttpClient httpclient =HttpClients.custom().setSSLSocketFactory(sslsf).build();

HttpPost httppost= new HttpPost("https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers");

httppost.addHeader("Content-Type", "text/xml");

StringEntity se= new StringEntity(xml, "UTF-8");

httppost.setEntity(se);

CloseableHttpResponse responseEntry=httpclient.execute(httppost);try{

HttpEntity entity=responseEntry.getEntity();if (entity != null) {SAXReader saxReader= newSAXReader();

Document document=saxReader.read(entity.getContent());

Element rootElt=document.getRootElement();

String resultCode= rootElt.elementText("result_code");if (resultCode.equals("SUCCESS")) {tansferStatus=true;

//成功后操作

} else{

//失败后操作responseInfo=rootElt.elementText("err_code_des");

}

}

EntityUtils.consume(entity);

}catch(Exception e) {}finally{

responseEntry.close();

}

}catch(Exception e) {}if(tansferStatus==true){}

HashMap responseBody = new HashMap<>();

responseBody.put("status",tansferStatus);

responseBody.put("responseInfo",responseInfo);returnresponseBody;

}public staticString wxSendWallet( 用户openId,金额,IP地址) {

String data= null;try{

String nonceStr=WXPayUtil.generateNonceStr();

SortedMap parameters = new TreeMap();

parameters.put("mch_appid",APP_ID );

parameters.put("mchid", MCH_ID);

parameters.put("nonce_str", nonceStr);

String outTradeNo= UUID.randomUUID().toString().replaceAll("-", "");

parameters.put("partner_trade_no", outTradeNo);

parameters.put("openid", 用户openId);

parameters.put("check_name", "NO_CHECK");

parameters.put("amount", 金额);

parameters.put("spbill_create_ip", IP地址);

parameters.put("desc", 商家名称);//签名

parameters.put("sign", WXPayUtil.generateSignature(parameters, MyWxpayConfig.APP_KEY));

data=WXPayUtil.mapToXml(parameters);

}catch(Exception e) {

e.printStackTrace();

}returndata;

}//元转分

public String changeY2F(doubleprice) {int amount= (int) (price * 100);returnString.valueOf(amount);

}

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值