java对接支付宝单笔转账接口

java对接⽀付宝单笔转账接⼝证书模式及⾮证书模式转账
查询证书路径
public String queryPath()throws FileNotFoundException, ServerException {
String basePath = URL("classpath:").getPath();
basePath =this.initCart(basePath);
return basePath;
}
private String initCart(String basePath)throws ServerException {
ains("jar!")){
if(basePath.startsWith("file:")){
basePath = place("file:","");
}
String appCertPath = AppCertPath();
this.checkAndcopyCart(basePath, appCertPath);
String alipayCertPath = AlipayCertPath();
this.checkAndcopyCart(basePath, alipayCertPath);
String alipayRootCertPath = AlipayRootCertPath();
this.checkAndcopyCart(basePath, alipayRootCertPath);
}
return basePath;
}
private void checkAndcopyCart(String basePath, String path)throws ServerException {
InputStream cartInputStream = null;
OutputStream cartOutputStream = null;
String cartPath = basePath + path;
File cartFile =new File(cartPath);
File parentFile = ParentFile();
parentFile.mkdirs();
try{
if(!ists()){
cartInputStream = DefaultClassLoader().getResourceAsStream(path);
cartOutputStream =new FileOutputStream(cartFile);
byte[] buf =new byte[1024];
int bytesRead;
while((bytesRead = ad(buf))!=-1){
cartOutputStream.write(buf,0, bytesRead);
}
cartInputStream.close();
cartOutputStream.close();
}
}catch(IOException e){
throw new Message());
}
}
调⽤⽀付宝转账接⼝ 如果⾮证书模式 则可以直接将 构造client 之前的都不要
String basePath =this.queryPath();
// 构造client
CertAlipayRequest certAlipayRequest =new CertAlipayRequest();
// 设置⽹关地址
certAlipayRequest.GatewayUrl());
// 设置应⽤Id
certAlipayRequest.Appid());
// 设置应⽤私钥
certAlipayRequest.AppPrivateKey());
// 设置请求格式,固定值json
certAlipayRequest.setFormat("json");
// 设置字符集
certAlipayRequest.Charset());
// 设置签名类型
certAlipayRequest.SignType());
// 设置应⽤公钥证书路径
certAlipayRequest.setCertPath(basePath + AppCertPath());
// 设置⽀付宝公钥证书路径
certAlipayRequest.setAlipayPublicCertPath(basePath + AlipayCertPath()); // 设置⽀付宝根证书路径
certAlipayRequest.setRootCertPath(basePath + AlipayRootCertPath()); // 构造client
AlipayClient alipayClient =new DefaultAlipayClient(certAlipayRequest);
Map<String, String> map =new HashMap<>();
map.put("out_biz_no","⾃⼰平台订单Id");
map.put("biz_scene","DIRECT_TRANSFER");
map.put("product_code","TRANS_ACCOUNT_NO_PWD");
map.put("trans_amount","转账⾦额");
map.put("order_title","转账标题");
map.put("remark","转账备注");
// 转账账户
Map<String, String> map2 =new HashMap<>();
map2.put("identity","转账账户⽀付宝账户");
map2.put("identity_type","ALIPAY_LOGON_ID");
map2.put("name","转账账户真实姓名");
map.put("payee_info", FastJsonUtil.beanToJson(map2));
// 转成json格式放⼊
String json = FastJsonUtil.beanToJson(map);
AlipayFundTransUniTransferRequest request =new AlipayFundTransUniTransferRequest();  request.setBizContent(json);
log.info("请求参数:"+ BizContent());
AlipayFundTransUniTransferResponse response = null;
try{
response = ificateExecute(request);
if("10000".Code())){
log.info("打印⽇志返回结果-----"+ TransDate());
ateTuple("0","转账成功!");
}else{
log.info("打印⽇志返回结果-----"+ Body());
Code(), SubMsg());
}
}catch(AlipayApiException e){
log.info("打印⽇志返回结果-----"+ response);
转接口e.printStackTrace();
ateTuple("1","转账失败!");
}
注意 付款⽅余额必须⼤于1元 否则会提⽰付款⽅余额不够

本文发布于:2024-09-24 08:28:29,感谢您对本站的认可!

本文链接:https://www.17tex.com/tex/4/358964.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:证书   设置   转账   模式   账户   路径   余额   付款
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议