Skip to content

Commit 1eb9ac8

Browse files
authored
Merge pull request #9 from alipay/feature_align_doc_fields
覆盖:支付+代扣+报关+订阅支付以及对应测试项
2 parents a1d86ad + b2b1cc1 commit 1eb9ac8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+7320
-32
lines changed

.gitignore

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Composer 依赖目录
2+
/vendor/
3+
/composer.lock
4+
5+
# Node.js 依赖目录
6+
/node_modules/
7+
/package-lock.json
8+
9+
# Laravel 或 Symfony 等框架的缓存和日志目录
10+
/storage/logs/
11+
/storage/framework/cache/
12+
/storage/framework/sessions/
13+
/storage/framework/views/
14+
/bootstrap/cache/
15+
16+
# 环境配置文件
17+
.env
18+
.env.*.local
19+
.phpunit.result.cache
20+
21+
# IDE 和编辑器配置文件
22+
/.idea/
23+
/.vscode/
24+
/nbproject/
25+
/*.iml
26+
27+
# 操作系统生成的文件
28+
.DS_Store
29+
Thumbs.db
30+
desktop.ini
31+
32+
# 缓存文件
33+
/.sass-cache/
34+
/.htaccess
35+
36+
# 日志文件
37+
*.log
38+
*.log.*
39+
*.txt
40+
41+
# PHPStorm 目录
42+
.idea/

BaseAlipayClient.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,35 @@ abstract class BaseAlipayClient{
1010
private $merchantPrivateKey;
1111
private $alipayPublicKey;
1212

13-
function __construct($gatewayUrl, $merchantPrivateKey, $alipayPublicKey) {
13+
private $clientId;
14+
15+
function __construct(){
16+
$a=func_get_args();
17+
$i=func_num_args();
18+
if(method_exists($this,$f='__construct'.$i)){
19+
call_user_func_array(array($this,$f),$a);
20+
}
21+
}
22+
23+
function __construct3($gatewayUrl, $merchantPrivateKey, $alipayPublicKey) {
1424
$this->gatewayUrl = $gatewayUrl;
1525
$this->merchantPrivateKey = $merchantPrivateKey;
1626
$this->alipayPublicKey = $alipayPublicKey;
1727
}
1828

29+
function __construct4($gatewayUrl, $merchantPrivateKey, $alipayPublicKey,$clientId) {
30+
$this->gatewayUrl = $gatewayUrl;
31+
$this->merchantPrivateKey = $merchantPrivateKey;
32+
$this->alipayPublicKey = $alipayPublicKey;
33+
$this->clientId = $clientId;
34+
}
35+
1936
public function execute($request){
2037

38+
if (!$request->getClientId() === null || trim($request->getClientId()) === ""){
39+
$request->setClientId($this->clientId);
40+
}
41+
2142
$this->checkRequestParam($request);
2243

2344
$clientId = $request->getClientId();

DefaultAlipayClient.php

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,34 @@
33
require_once 'BaseAlipayClient.php';
44
require_once 'model/HttpRpcResult.php';
55

6-
class DefaultAlipayClient extends BaseAlipayClient{
6+
class DefaultAlipayClient extends BaseAlipayClient
7+
{
8+
9+
function __construct(){
10+
$a=func_get_args();
11+
$i=func_num_args() - 2;
12+
if(method_exists($this,$f='__construct'.$i)){
13+
call_user_func_array(array($this,$f),$a);
14+
}
15+
}
716

8-
function __construct($gatewayUrl, $merchantPrivateKey, $alipayPublicKey) {
17+
function __construct1($gatewayUrl, $merchantPrivateKey, $alipayPublicKey)
18+
{
919
parent::__construct($gatewayUrl, $merchantPrivateKey, $alipayPublicKey);
1020
}
1121

12-
protected function buildCustomHeader(){
22+
function __construct2($gatewayUrl, $merchantPrivateKey, $alipayPublicKey, $clientId)
23+
{
24+
parent::__construct($gatewayUrl, $merchantPrivateKey, $alipayPublicKey, $clientId);
25+
}
26+
27+
protected function buildCustomHeader()
28+
{
1329
return null;
1430
}
1531

16-
protected function sendRequest($requestUrl, $httpMethod, $headers, $reqBody){
32+
protected function sendRequest($requestUrl, $httpMethod, $headers, $reqBody)
33+
{
1734
$curl = curl_init();
1835
curl_setopt($curl, CURLOPT_URL, $requestUrl);
1936
curl_setopt($curl, CURLOPT_FAILONERROR, false);
@@ -30,22 +47,22 @@ protected function sendRequest($requestUrl, $httpMethod, $headers, $reqBody){
3047
return null;
3148
}
3249

33-
$headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
50+
$headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
3451
$headerContent = substr($rspContent, 0, $headerSize);
35-
$rspBody = substr($rspContent, $headerSize);
52+
$rspBody = substr($rspContent, $headerSize);
3653

3754
$httpRpcResult = new HttpRpcResult();
3855
$httpRpcResult->setRspBody($rspBody);
3956

4057
$headArr = explode("\r\n", $headerContent);
4158
foreach ($headArr as $headerItem) {
42-
if(strstr($headerItem, "response-time") || strstr($headerItem, "signature")){
59+
if (strstr($headerItem, "response-time") || strstr($headerItem, "signature")) {
4360
$responseTime = $this->getResponseTime($headerItem);
44-
if(isset($responseTime) && $responseTime != null){
61+
if (isset($responseTime) && $responseTime != null) {
4562
$httpRpcResult->setRspTime(trim($responseTime));
4663
} else {
4764
$signatureValue = $this->getResponseSignature($headerItem);
48-
if(isset($signatureValue) && $signatureValue != null){
65+
if (isset($signatureValue) && $signatureValue != null) {
4966
$httpRpcResult->setRspSign($signatureValue);
5067
}
5168
}
@@ -58,17 +75,19 @@ protected function sendRequest($requestUrl, $httpMethod, $headers, $reqBody){
5875
}
5976

6077

61-
private function getResponseTime($headerItem){
62-
if(strstr($headerItem, "response-time")){
78+
private function getResponseTime($headerItem)
79+
{
80+
if (strstr($headerItem, "response-time")) {
6381
$startIndex = strpos($headerItem, ":") + 1;
6482
$responseTime = substr($headerItem, $startIndex);
6583
return $responseTime;
6684
}
6785
return null;
6886
}
6987

70-
private function getResponseSignature($headerItem){
71-
if(strstr($headerItem, "signature")){
88+
private function getResponseSignature($headerItem)
89+
{
90+
if (strstr($headerItem, "signature")) {
7291
$startIndex = strrpos($headerItem, "=") + 1;
7392
$signatureValue = substr($headerItem, $startIndex);
7493
return $signatureValue;

example/AuthTest.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
set_include_path(__DIR__ . '/..');
4+
5+
require_once 'request/auth/AlipayAuthConsultRequest.php';
6+
require_once 'model/CustomerBelongsTo.php';
7+
require_once 'model/OsType.php';
8+
require_once 'model/ScopeType.php';
9+
require_once 'model/TerminalType.php';
10+
require_once 'DefaultAlipayClient.php';
11+
require_once 'request/auth/AlipayAuthApplyTokenRequest.php';
12+
require_once 'model/GrantType.php';
13+
require_once 'request/auth/AlipayAuthQueryTokenRequest.php';
14+
require_once 'request/auth/AlipayAuthRevokeTokenRequest.php';
15+
16+
17+
const clientId = "";
18+
const merchantPrivateKey = "";
19+
const alipayPublicKey = "";
20+
const gatewayUrl = "";
21+
22+
function applyToken($authCode)
23+
{
24+
$request = new AlipayAuthApplyTokenRequest();
25+
$request->setGrantType(GrantType::AUTHORIZATION_CODE);
26+
$request->setCustomerBelongsTo(CustomerBelongsTo::ALIPAY_CN);
27+
$request->setAuthCode($authCode);
28+
29+
$alipayClient = new DefaultAlipayClient(gatewayUrl, merchantPrivateKey, alipayPublicKey, clientId);
30+
$alipayResponse = $alipayClient->execute($request);
31+
32+
print(json_encode($alipayResponse));
33+
34+
}
35+
36+
function authConsult()
37+
{
38+
$request = new AlipayAuthConsultRequest();
39+
$request->setAuthRedirectUrl("https://www.taobao.com/?param1=567&param2=123");
40+
$request->setAuthState("dd1F6F6811f989DC7");
41+
$request->setCustomerBelongsTo(CustomerBelongsTo::ALIPAY_CN);
42+
$request->setOsType(OsType::ANDROID);
43+
$request->setOsVersion("6.6.6.6");
44+
$request->setScopes([ScopeType::AGREEMENT_PAY]);
45+
$request->setTerminalType(TerminalType::APP);
46+
47+
$alipayClient = new DefaultAlipayClient(gatewayUrl, merchantPrivateKey, alipayPublicKey, clientId);
48+
$alipayResponse = $alipayClient->execute($request);
49+
50+
print(json_encode($alipayResponse));
51+
}
52+
53+
function queryToken($accessToken)
54+
{
55+
$request = new AlipayAuthQueryTokenRequest();
56+
$request->setAccessToken($accessToken);
57+
58+
$alipayClient = new DefaultAlipayClient(gatewayUrl, merchantPrivateKey, alipayPublicKey, clientId);
59+
$alipayResponse = $alipayClient->execute($request);
60+
61+
print(json_encode($alipayResponse));
62+
63+
}
64+
65+
66+
function revoke_token($accessToken)
67+
{
68+
$request = new AlipayAuthRevokeTokenRequest();
69+
$request->setAccessToken($accessToken);
70+
71+
$alipayClient = new DefaultAlipayClient(gatewayUrl, merchantPrivateKey, alipayPublicKey, clientId);
72+
$alipayResponse = $alipayClient->execute($request);
73+
74+
print(json_encode($alipayResponse));
75+
}
76+
77+
78+
//authConsult();
79+
//applyToken("281001133029700579331362");
80+
revoke_token("28288803001247281723530452000N6krsDm8J8171000589");

example/CustomsTest.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
set_include_path(__DIR__ . '/..');
3+
4+
require_once 'request/customs/AlipayCustomsDeclareRequest.php';
5+
require_once 'DefaultAlipayClient.php';
6+
require_once 'model/Amount.php';
7+
require_once 'model/MerchantCustomsInfo.php';
8+
require_once 'model/CustomsInfo.php';
9+
require_once 'model/Certificate.php';
10+
require_once 'model/UserName.php';
11+
require_once 'model/CertificateType.php';
12+
13+
const clientId = "";
14+
const merchantPrivateKey = "";
15+
const alipayPublicKey = "";
16+
const gatewayUrl = "";
17+
18+
function declares($paymentId)
19+
{
20+
21+
$request = new AlipayCustomsDeclareRequest();
22+
$requestId = 'declare_' . round(microtime(true) * 1000);
23+
$request->setDeclarationRequestId($requestId);
24+
$request->setPaymentId($paymentId);
25+
$amount = new Amount();
26+
$amount->setValue(100);
27+
$amount->setCurrency("CNY");
28+
$request->setDeclarationAmount($amount);
29+
$merchantCustomsInfo = new MerchantCustomsInfo();
30+
$merchantCustomsInfo->setMerchantCustomsName("wafdwasfewa");
31+
$merchantCustomsInfo->setMerchantCustomsCode("sdfsfd");
32+
$request->setMerchantCustomsInfo($merchantCustomsInfo);
33+
$request->setSplitOrder(false);
34+
$customsInfo = new CustomsInfo();
35+
$customsInfo->setRegion("CN");
36+
$customsInfo->setCustomsCode("ZHENGZHOU");
37+
$request->setCustoms($customsInfo);
38+
$certificate = new Certificate();
39+
$certificate->setCertificateNo("12345677");
40+
$certificate->setCertificateType(CertificateType::ID_CARD);
41+
$userName = new UserName();
42+
$userName->setFirstName("f");
43+
$userName->setFullName("f");
44+
$certificate->setHolderName($userName);
45+
$request->setBuyerCertificate($certificate);
46+
47+
$alipayClient = new DefaultAlipayClient(gatewayUrl, merchantPrivateKey, alipayPublicKey, clientId);
48+
$alipayResponse = $alipayClient->execute($request);
49+
50+
print(json_encode($alipayResponse));
51+
print("\n".$requestId);
52+
53+
}
54+
55+
function inquiryDeclaration($declareRequestId)
56+
{
57+
58+
$request = new AlipayCustomsQueryRequest();
59+
$request->setDeclarationRequestIds([$declareRequestId]);
60+
61+
$alipayClient = new DefaultAlipayClient(gatewayUrl, merchantPrivateKey, alipayPublicKey, clientId);
62+
$alipayResponse = $alipayClient->execute($request);
63+
64+
print(json_encode($alipayResponse));
65+
66+
67+
}
68+
69+
70+
declares("202407311940108001001887A0209760494");
71+
//inquiryDeclaration();

0 commit comments

Comments
 (0)