首先微信和支付宝的流程都是前台先拿到code,然后微信是通过code拿到用户appid执行转账,支付宝是通过code拿到userid执行转账。
微信需要开通企业提现到零钱的业务,支付宝需要开通单笔资金转账到支付宝所对应的业务,如果要获取用户信息的话,还要开通会员信息功能。
微信对应的开发文档:https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_1
支付宝对应的开发文档:https://docs.open.alipay.com/api_28/alipay.fund.trans.toaccount.transfer/
下面是支付宝提现到用户支付宝功能代码
public Welipayorder authtoken(String code){
ReturnResult result = new ReturnResult();
// 公钥签名
try {
AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", AlipayConfig.APP_ID,AlipayConfig.APP_PRIVATE_KEY, AlipayConfig.FORMAT, AlipayConfig.CHARSET, AlipayConfig.ALIPAY_PUBLIC_KEY, "RSA2");
AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest();
System.out.println(code);
request.setCode(code);
request.setGrantType("authorization_code");
try {
System.out.println(request);
AlipaySystemOauthTokenResponse oauthTokenResponse = alipayClient.execute(request);
System.out.println(oauthTokenResponse.getBody());
String out_bi_zno = trandno();
weli.setOutbizno(out_bi_zno);
AlipayFundTransToaccountTransferRequest request1 = new AlipayFundTransToaccountTransferRequest();
System.out.println("payee_account========"+oauthTokenResponse.getAlipayUserId());
request1.setBizContent("{" +
"\"out_biz_no\""+":\""+ weli.getOutbizno() +"\"," +
"\"payee_type\":\"ALIPAY_USERID\"," +
"\"payee_account\""+":\""+ oauthTokenResponse.getUserId()+"\"," +
"\"amount\":\"0.1\"," +
"\"payer_show_name\":\"毛毛的\"," +
// "\"payee_real_name\":\"毛俊刚\"," +
"\"remark\":\"app提现到用户支付宝\"" +
" }");
System.out.println(request1.toString());
AlipayFundTransToaccountTransferResponse response = alipayClient.execute(request1);
if(response.isSuccess()){
System.out.println("调用成功");
} else {
System.out.println("调用失败");
}
} catch (AlipayApiException e) {
//处理异常
e.printStackTrace();
}
} catch (Exception e) {
// TODO: handle exception
}
return weli;
}
public String trandno(){
/**---------------开始生成订单号 ------------------------**/
//当前时间 yyyyMMddHHmmss
String currTime = TenpayUtil.getCurrTime();
//8位日期
String strTime = currTime.substring(8, currTime.length());
//四位随机数
String strRandom = TenpayUtil.buildRandom(4) + "";
//10位序列号,可以自行调整
String strReq = strTime + strRandom;
//订单号,此处用时间加随机数生成,只要保持全局唯一就行
String out_trade_no = strReq;
out_trade_no = String.valueOf(UUID.next());
return out_trade_no;
}
由于微信封装的比较多,所以关于 微信的提现方法更多内容,可百度云盘下载关于微信提现项目源码:https://pan.baidu.com/s/1lV8DYen7I6HW-tQVYfihJw
注意:微信提现读取证书路径windows绝对路径为:D:\\demo\\apiclient_cert.p12,如果在linux上面则路径为:/usr/demo/
apiclient_cert.p12。window用"\\"标识目录分隔,二linux则用"/"标识目录分隔。