支付宝B2C转账 alipay.fund.trans.uni.transfer(单笔转账接口)

1,192 阅读1分钟

alipay.fund.trans.uni.transfer(单笔转账接口)

首先支付宝接口更新后,原单笔转账到支付宝账户功能 alipay.fund.trans.toaccount.transfer(单笔转账到支付宝账户接口) 已经弃用;
新申请的应用无法使用该接口,原共性方法也会失效。
相应功能改为调用资金类API alipay.fund.trans.uni.transfer(单笔转账接口)
https://opendocs.alipay.com/apis/api_28/alipay.fund.trans.uni.transfer
(本来这种接口直接看文档就得了,但出于某些莫名的原因,在我向客服反应过一次之后,支付宝的文档的请求示例依旧是错误的)

注意事项

1.资金类接口不能用普通公钥的方式进行接口加密

具体可参见支付宝密钥生成文档

接地气的描述我一篇关于资金类接口绑号的文章

2.由于接口加密方式的改变,接口也有一定变化

        Vendor("Pay.alipay2.AopSdk");

		$config = [
			'app_id' => app_id,
			'merchant_private_key' => 'merchant_private_key',
			'alipay_public_key' => 'alipay_public_key',
			'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
			'charset' => "UTF-8",
			'sign_type' => "RSA2",
		];

		$appCertPath = "appCertPublicKey.crt";
		$alipayCertPath = "alipayCertPublicKey_RSA2.crt";
		$rootCertPath = "alipayRootCert.crt";

		$aop = new AopCertClient();
		$aop->gatewayUrl         = 'https://openapi.alipay.com/gateway.do';
		$aop->appId              = $config['app_id'];
		$aop->rsaPrivateKey      = $config['merchant_private_key'];
		$aop->alipayrsaPublicKey = $aop->getPublicKey($alipayCertPath);
		$aop->signType           = 'RSA2';
		$aop->postCharset        = 'utf-8';
		$aop->format             = 'json';
//		$aop->isCheckAlipayPublicCert = true;//是否校验自动下载的支付宝公钥证书,如果开启校验要保证支付宝根证书在有效期内
		$aop->appCertSN = $aop->getCertSN($appCertPath);//调用getCertSN获取证书序列号
		$aop->alipayRootCertSN = $aop->getRootCertSN($rootCertPath);//调用getRootCertSN获取支付宝根证书序列号

		$request = new AlipayFundTransUniTransferRequest();
		$request->setBizContent("{".
			//商户端的唯一订单号,对于同一笔转账请求,商户需保证该订单号唯一
			"\"out_biz_no\":\"{$order_number}\",".
			"\"trans_amount\":\"{$amount}\",".
			"\"product_code\":\"TRANS_ACCOUNT_NO_PWD\",".
			"\"biz_scene\":\"DIRECT_TRANSFER\",".
			"\"order_title\":\"{$memo}\",".
			"\"payee_info\":{".
			"\"identity\":\"{$pay_no}\",".
			"\"identity_type\":\"ALIPAY_LOGON_ID\",".
			"\"name\":\"{$pay_name}\"".
			"},".
			"\"remark\":\"{$memo}\"".
			"}");

//		$result = $aop->execute($request,null,$app_auth_token); //第三方应用要传入app_auth_token
		$result = $aop->execute($request);
		
		$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
		return $result->$responseNode;

相应的,公钥证书方式加密的应用,在调用其它服务时,也AopCertClient完成参数初始化,否则会提示公钥不匹配的报错 如果想采用普通公钥的调用方式,可以建两个应用,设置不同的加密方式