antom/global-open-sdk-php
Composer 安装命令:
composer require antom/global-open-sdk-php
包简介
global-open-sdk-php
README 文档
README
Language:PHP
PHP version:7.1+
Releass ^1.4.34
Copyright:Ant financial services group
Composer
You can install the bindings via Composer. Run the following command:
composer require antom/global-open-sdk-php
To use the bindings, use Composer's autoload:
require_once 'vendor/autoload.php';
Manual Installation
If you do not wish to use Composer, you can download the latest release. Then, to use the bindings, include the init.php file.
require_once '/path/to/global-open-sdk-php/init.php';
Requirements
PHP 7.1 or higher
Legacy version support
If using PHP versions 7.1 or lower, download our library version 1.4.13.
1 Important note
The SDK mainly shows how to access the alipay gateway, which cannot guarantee the performance and stability.
2 The demo code for create payment
use Request\pay\AlipayPayRequest;
use Client\DefaultAlipayClient;
use Model\Amount;
use Model\Buyer;
use Model\Env;
use Model\Merchant;
use Model\Order;
use Model\OsType;
use Model\PaymentFactor;
use Model\PaymentMethod;
use Model\PresentmentMode;
use Model\ProductCodeType;
use Model\SettlementStrategy;
use Model\Store;
use Model\TerminalType;
use Model\WalletPaymentMethodType;
$request = new AlipayPayRequest();
$paymentRequestId = 'PR_' . round(microtime(true) * 1000);
$order = new Order();
$order->setOrderDescription("test order desc");
$order->setReferenceOrderId("102775745075668");
$orderAmount = new Amount();
$orderAmount->setCurrency("HKD");
$orderAmount->setValue("100");
$order->setOrderAmount($orderAmount);
$merchant = new Merchant();
$merchant->setReferenceMerchantId('seller2322174590001');
$merchant->setMerchantMCC('7011');
$merchant->setMerchantName('Some_Mer');
$store = new Store();
$store->setStoreMCC('7011');
$store->setReferenceStoreId('store232217459000021');
$store->setStoreName('Some_Store');
$merchant->setStore($store);
$order->setMerchant($merchant);
$env = new Env();
$env->setUserAgent('"Mozilla/5.0 (iPhone; CPU iPhone OS 11_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15G77 NebulaSDK/1.8.100112 Nebula PSDType(1) AlipayDefined(nt:4G,ws:320|504|2.0) AliApp(AP/10.1.32.600) AlipayClient/10.1.32.600 Alipay Language/zh-Hans AlipayConnect"');
$env->setOsType(OsType::ANDROID);
$env->setTerminalType(TerminalType::WEB);
$order->setEnv($env);
$request->setOrder($order);
$paymentAmount = new Amount();
$paymentAmount->setCurrency("HKD");
$paymentAmount->setValue("100");
$request->setPaymentAmount($paymentAmount);
$paymentNotifyUrl = "https://www.alipay.com/notify";
$paymentRedirectUrl = "https://www.alipay.com";
$request->setPaymentNotifyUrl($paymentNotifyUrl);
$request->setPaymentRedirectUrl($paymentRedirectUrl);
$paymentMethod = new PaymentMethod();
$paymentMethod->setPaymentMethodType(WalletPaymentMethodType::ALIPAY_HK);
$request->setPaymentMethod($paymentMethod);
$request->setProductCode(ProductCodeType::CASHIER_PAYMENT);
$request->setClientId(clientId);
$request->setPaymentRequestId($paymentRequestId);
$settlementStrategy = new SettlementStrategy();
$settlementStrategy->setSettlementCurrency("USD");
$request->setSettlementStrategy($settlementStrategy);
$alipayClient = new DefaultAlipayClient("https://open-sea-global.alipay.com", merchantPrivateKey, alipayPublicKey);
$alipayResponse = $alipayClient->execute($request);
The execute method contains the HTTP request to the gateway.
If you're concerned about HTTP invocation performance, you can implement HTTP invocation yourself.
class YourAlipayClient extends \Client\BaseAlipayClient{
function __construct()
{
$a = func_get_args();
$i = func_num_args() - 2;
if (method_exists($this, $f = '__construct' . $i)) {
call_user_func_array(array($this, $f), $a);
}
}
function __construct1($gatewayUrl, $merchantPrivateKey, $alipayPublicKey)
{
parent::__construct($gatewayUrl, $merchantPrivateKey, $alipayPublicKey);
}
function __construct2($gatewayUrl, $merchantPrivateKey, $alipayPublicKey, $clientId)
{
parent::__construct($gatewayUrl, $merchantPrivateKey, $alipayPublicKey, $clientId);
}
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 If you don't care about HTTP calls,the sample for sign and verify
$signReqValue = SignatureTool::sign($httpMethod, $path, $clientId, $reqTime, $reqBody, $merchantPrivateKey);
$isVerifyPass = SignatureTool::verify($httpMethod, $path, $clientId, $rspTime, $rspBody, $rspSignValue, $alipayPublicKey);
antom/global-open-sdk-php 适用场景与选型建议
antom/global-open-sdk-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 28.63k 次下载、GitHub Stars 达 24, 最近一次更新时间为 2024 年 08 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 antom/global-open-sdk-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 antom/global-open-sdk-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 28.63k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 24
- 点击次数: 13
- 依赖项目数: 5
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-08-27