支付宝单笔转账开发

1、下载SDK  https://github.com/alipay/alipay-sdk-php-all/tree/master 使用v2

2、引入SDK (沙箱测试:https://open.alipay.com/develop/sandbox/app)

setPrivateKey($privateKey);
$alipayConfig->setServerUrl("https://openapi-sandbox.dl.alipaydev.com/gateway.do");
//沙箱地址,上线时需要切换正式地址
$alipayConfig->setAppId("9021000133613273");
$alipayConfig->setCharset("UTF-8");//注意这里是UTF - 8,坑爹的玩意
$alipayConfig->setSignType("RSA2");
$alipayConfig->setEncryptKey("");
$alipayConfig->setFormat("json");
$alipayConfig->setAppCertPath("商户公钥证书");
$alipayConfig->setAlipayPublicCertPath("支付宝公钥证书");
$alipayConfig->setRootCertPath("支付宝根证书");
$alipayClient = new AopCertClient($alipayConfig);
$alipayClient->isCheckAlipayPublicCert = true;
$request = new AlipayFundTransUniTransferRequest();
$data = array();

$oid = date("YmdHis").rand(1,9); //处理单号
$money = 0.01; //转账金额
$phone = 'zhangsan123'; //用户账号
$name = '张三'; //用户真实姓名

$data["out_biz_no"] = $oid;
$data["trans_amount"] = $money;
$data["product_code"] = 'TRANS_ACCOUNT_NO_PWD';
$data["biz_scene"] = 'DIRECT_TRANSFER';
$data["order_title"] = '转账介绍'; 
$data["payee_info"] = array();
$data["payee_info"]["identity"] = $phone;
$data["payee_info"]["identity_type"] = 'ALIPAY_LOGON_ID';
$data["payee_info"]["name"] = $name;
$request->setBizContent(json_encode($data, true));

$responseResult = $alipayClient->execute($request);
$responseApiName = str_replace(".","_",$request->getApiMethodName())."_response";
$response = $responseResult->$responseApiName;
if(!empty($response->code)&&$response->code==10000){
	echo "success";
}
else{
	echo json_encode($responseResult);
}

你可能感兴趣的:(android)