java+支付宝转账+证书(一秒接入)

import com.alipay.api.AlipayApiException;
import com.alipay.api.CertAlipayRequest;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayFundTransUniTransferRequest;
import com.alipay.api.response.AlipayFundTransUniTransferResponse;
public class alipayClient {
	
	public static void main(String[] args) throws AlipayApiException {
	//获取根目录
 		String filePath=alipayClient.class.getResource("/").getPath();	
 		System.out.println(filePath);
		CertAlipayRequest   certAlipayRequest   =   new   CertAlipayRequest ();
		 certAlipayRequest . setServerUrl ( "https://openapi.alipay.com/gateway.do" );
		 certAlipayRequest . setAppId ( "");
		 certAlipayRequest . setPrivateKey ( "" );//密钥
		 certAlipayRequest . setFormat ( "json" );
		 certAlipayRequest . setCharset ( "UTF-8" );
		 certAlipayRequest . setSignType ( "RSA2" );
		 certAlipayRequest . setCertPath (filePath+"appCertPublicKey.crt");//应用证书
		 certAlipayRequest . setAlipayPublicCertPath (filePath+"alipayCertPublicKey_RSA2.crt");//支付证书
		 certAlipayRequest . setRootCertPath (filePath+"alipayRootCert.crt" );
		 DefaultAlipayClient   alipayClient   = new DefaultAlipayClient(certAlipayRequest);
		 AlipayFundTransUniTransferRequest   request   =   new   AlipayFundTransUniTransferRequest ();
		
		
		
		//订单号
		Map<String, Object> map = new DateFormat().dateFormat();
		String order = (String) map.get("random");
		System.out.println(order);
		//价格
		Double  money = 0.1;
		//转账标题
		String order_title = "";
		//支付宝会员id
		String identity = "";
		//实名信息
		String name = "";
		
		//付款方式
		//      单笔无密转账到支付宝账户固定为:
		//		TRANS_ACCOUNT_NO_PWD;
		//		单笔无密转账到银行卡固定为:
		//		TRANS_BANKCARD_NO_PWD;
		//		收发现金红包固定为:
		//		STD_RED_PACKET;
		
		request.setBizContent("{" +
		"\"out_biz_no\":\"201806300001\"," +
				
		"\"trans_amount\":"+money+"," +
		"\"product_code\":\"TRANS_ACCOUNT_NO_PWD\"," +
		"\"biz_scene\":\"DIRECT_TRANSFER\"," +
		"\"order_title\":\""+order_title+"\"," +
//		"\"original_order_id\":\"20190620110075000006640000063056\"," +
		"\"payee_info\":{" +
		"\"identity\":\""+identity+"\"," +
		"\"identity_type\":\"ALIPAY_LOGON_ID\"," +
		"\"name\":\""+name+"\"" +
		"    }," +
//		"\"remark\":\"单笔转账\"," +
//		"\"business_params\":\"{\\\"sub_biz_scene\\\":\\\"REDPACKET\\\"}\"" +
		"  }");
		AlipayFundTransUniTransferResponse response = alipayClient.certificateExecute(request);
		if(response.isSuccess()){
		System.out.println("调用成功");
		} else {
		System.out.println("调用失败");
		}
}
}

POM(低版本的会出错)

		<!-- https://mvnrepository.com/artifact/com.alipay.sdk/alipay-sdk-java -->
		<dependency>
		    <groupId>com.alipay.sdk</groupId>
		    <artifactId>alipay-sdk-java</artifactId>
		    <version>4.10.0.ALL</version>
		</dependency>
上一篇:php支付宝支付


下一篇:SOFA入门