rocalex / global-open-sdk-php
此包的最新版本(0.1.2)没有提供许可证信息。
0.1.2
2023-07-08 03:19 UTC
README
Language:PHP
PHP version:5.4.7+
Copyright:Ant financial services group
1 重要提示
SDK 主要展示如何访问支付宝网关,但不能保证性能和稳定性。
2 创建订单的示例代码
$alipayCreateOrderRequest = new AlipayCreateOrderRequest(); $clientId = "your clientId"; $path = "/ams/sandbox/api/v1/payments/create"; $productCode = ProductCodeType::CASHIER_PAYMENT; $paymentRequestId = "demo-test-id"; $order = new Order(); $order->setOrderDescription("test order desc"); $order->setReferenceOrderId("102775745075669"); $orderAmount = new Amount(); $orderAmount->setCurrency("USD"); $orderAmount->setValue("100"); $order->setOrderAmount($orderAmount); $paymentAmount = new Amount(); $paymentAmount->setCurrency("USD"); $paymentAmount->setValue("100"); $paymentNotifyUrl = "https://www.alipay.com/notify"; $paymentRedirectUrl = "https://www.alipay.com"; $alipayCreateOrderRequest->setClientId($clientId); $alipayCreateOrderRequest->setPath($path); $alipayCreateOrderRequest->setProductCode($productCode); $alipayCreateOrderRequest->setPaymentRequestId($paymentRequestId); $alipayCreateOrderRequest->setPaymentAmount($paymentAmount); $alipayCreateOrderRequest->setOrder($order); $alipayCreateOrderRequest->setPaymentNotifyUrl($paymentNotifyUrl); $alipayCreateOrderRequest->setPaymentRedirectUrl($paymentRedirectUrl); $merchantPrivateKey = "your privateKey"; $alipayPublicKey = "your alipayPublicKey"; $alipayClient = new DefaultAlipayClient("https://open-sea.alipay.com", $merchantPrivateKey, $alipayPublicKey); $alipayResponse = $alipayClient->execute($alipayCreateOrderRequest);
执行方法包含对网关的HTTP请求。
如果您关注HTTP调用的性能,您可以自己实现HTTP调用。
class YourAlipayClient extends BaseAlipayClient{ function __construct($gatewayUrl, $merchantPrivateKey, $alipayPublicKey) { parent::__construct($gatewayUrl, $merchantPrivateKey, $alipayPublicKey); } protected function buildCustomHeader(){ return null; } protected function sendRequest($requestUrl, $httpMethod, $headers, $reqBody){ $httpRpcResult = new HttpRpcResult(); // TODO // $httpRpcResult->setRspBody($rspBody); // $httpRpcResult->setRspSign($rspSign); // $httpRpcResult->setRspTime($rspTime); return $httpRpcResult; } } $yourAlipayClient = new YourAlipayClient("https://open-sea.alipay.com", $merchantPrivateKey, $alipayPublicKey); $alipayPayResponse = $yourAlipayClient->execute($aliPayRequest);
3 如果您不关心HTTP调用,这里有签名和验证的示例
$signReqValue = SignatureTool::sign($httpMethod, $path, $clientId, $reqTime, $reqBody, $merchantPrivateKey);
$isVerifyPass = SignatureTool::verify($httpMethod, $path, $clientId, $rspTime, $rspBody, $rspSignValue, $alipayPublicKey);