Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
meibuyu-micro
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
without authentication
meibuyu-micro
Commits
54f5d43f
Commit
54f5d43f
authored
Apr 12, 2021
by
赵鹏
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/develop' into pull_fulfillmentOrders
parents
b7d052df
dd86c54d
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
306 additions
and
87 deletions
+306
-87
ExceptionLogProducer.php
src/Amqp/Producer/ExceptionLogProducer.php
+27
-14
FileServiceInterface.php
src/Service/Interfaces/File/FileServiceInterface.php
+15
-0
ShopifyServiceInterface.php
src/Service/Interfaces/Product/ShopifyServiceInterface.php
+9
-0
PurchaseDoneServiceInterface.php
...vice/Interfaces/Purchase/PurchaseDoneServiceInterface.php
+8
-0
AbstractShopify.php
src/Shopify/lib/AbstractShopify.php
+24
-48
Graphql.php
src/Shopify/lib/Graphql.php
+1
-1
InventoryItem.php
src/Shopify/lib/InventoryItem.php
+1
-1
InventoryLevel.php
src/Shopify/lib/InventoryLevel.php
+1
-1
CurlHttpRequestJson.php
src/Shopify/tools/CurlHttpRequestJson.php
+86
-0
CurlRequest.php
src/Shopify/tools/CurlRequest.php
+43
-7
CurlResponse.php
src/Shopify/tools/CurlResponse.php
+7
-7
HttpRequestGraphQL.php
src/Shopify/tools/HttpRequestGraphQL.php
+20
-4
HttpRequestJson.php
src/Shopify/tools/HttpRequestJson.php
+21
-4
Cacher.php
src/Tools/Cacher.php
+43
-0
No files found.
src/Amqp/Producer/ExceptionLogProducer.php
View file @
54f5d43f
...
...
@@ -23,22 +23,35 @@ class ExceptionLogProducer extends ProducerMessage
}
catch
(
HttpResponseException
$e
)
{
put_log
(
'获取操作人失败; '
.
$e
->
getMessage
(),
'ExceptionLogProducer.log'
);
}
// 排除依赖包文件和运行缓存文件
put_log
(
"file:
{
$data
[
'file'
]
}
"
,
'ExceptionLogProducerEcho.log'
);
if
(
strpos
(
$data
[
'file'
],
'/vendor/'
)
===
false
&&
strpos
(
$data
[
'file'
],
'/runtime/'
)
===
false
)
{
try
{
put_log
(
"git: git blame -L
{
$data
[
'line'
]
}
,
{
$data
[
'line'
]
}
{
$data
[
'file'
]
}
"
,
'ExceptionLogProducerEcho.log'
);
exec
(
"git blame -L
{
$data
[
'line'
]
}
,
{
$data
[
'line'
]
}
{
$data
[
'file'
]
}
"
,
$output
);
put_log
(
"output:
$output
"
,
'ExceptionLogProducerEcho.log'
);
if
(
!
empty
(
$output
[
0
])
&&
is_string
(
$output
[
0
]))
{
preg_match
(
'/(?<=\()[^ ]+/'
,
$output
[
0
],
$matches
);
put_log
(
"matches:
$matches
"
,
'ExceptionLogProducerEcho.log'
);
if
(
!
empty
(
$matches
[
0
]))
{
$data
[
'coder'
]
=
$matches
[
0
];
// 获取trace中真实文件和行数
if
(
!
empty
(
$data
[
'trace'
]))
{
preg_match
(
'/(\/var\/www\/html\/.+?\/app\/.+?\.php)(?=\()/'
,
$data
[
'trace'
],
$matchFiles
);
if
(
!
empty
(
$matchFiles
[
0
]))
{
$data
[
'file'
]
=
$matchFiles
[
0
];
$file
=
str_replace
(
'/'
,
'\/'
,
$matchFiles
[
0
]);
$file
=
str_replace
(
'.'
,
'\.'
,
$file
);
$pattern
=
'/(?<='
.
$file
.
'\()[0-9]+(?=\))/'
;
preg_match
(
$pattern
,
$data
[
'trace'
],
$matchLines
);
if
(
!
empty
(
$matchLines
[
0
]))
{
$data
[
'line'
]
=
$matchLines
[
0
];
}
}
}
if
(
!
empty
(
$data
[
'file'
]))
{
// 只对项目app文件夹下的错误获取编码人
preg_match
(
'/(\/var\/www\/html\/.+?\/app\/)/'
,
$data
[
'file'
],
$matchPaths
);
if
(
!
empty
(
$matchPaths
[
0
]))
{
try
{
exec
(
"cd
{
$matchPaths
[
0
]
}
&& git blame -L
{
$data
[
'line'
]
}
,
{
$data
[
'line'
]
}
{
$data
[
'file'
]
}
"
,
$output
);
if
(
!
empty
(
$output
[
0
])
&&
is_string
(
$output
[
0
]))
{
preg_match
(
'/(?<=\()[^ ]+/'
,
$output
[
0
],
$matchCoders
);
if
(
!
empty
(
$matchCoders
[
0
]))
{
$data
[
'coder'
]
=
$matchCoders
[
0
];
}
}
}
catch
(
Exception
$e
)
{
put_log
(
'获取编码人失败; '
.
$e
->
getMessage
(),
'ExceptionLogProducer.log'
);
}
}
catch
(
Exception
$e
)
{
put_log
(
'获取编码人失败; '
.
$e
->
getMessage
(),
'ExceptionLogProducer.log'
);
}
}
$this
->
payload
=
$data
;
...
...
src/Service/Interfaces/File/FileServiceInterface.php
0 → 100644
View file @
54f5d43f
<?php
namespace
Meibuyu\Micro\Service\Interfaces\File
;
interface
FileServiceInterface
{
/**
* @param string $type 类型编码 0001
* @param integer $number 生成条形码数量 100
* @return mixed
*/
public
function
generateBarCode
(
$type
,
$number
);
}
\ No newline at end of file
src/Service/Interfaces/Product/ShopifyServiceInterface.php
View file @
54f5d43f
...
...
@@ -86,4 +86,13 @@ interface ShopifyServiceInterface
*/
public
function
updateFulfillmentTracking
(
$fulfillmentId
,
$params
,
$shopifySiteId
);
/**
* 通过id数组获取shopify的location数据
* @param $ids
* @param string[] $columns
* @return array 默认keyBy('id')
* @author zero
*/
public
function
getLocationsByIds
(
$ids
,
$columns
=
[
'*'
]);
}
src/Service/Interfaces/Purchase/PurchaseDoneServiceInterface.php
View file @
54f5d43f
...
...
@@ -26,4 +26,12 @@ interface PurchaseDoneServiceInterface
* @return mixed
*/
public
function
productStandard
(
$data
);
/**
* 通过子订单编号查询状态
* @param array $orderIds 子订单编号 ['3333444','12222']
* @return mixed
*/
public
function
getOrderStatus
(
$orderIds
);
}
\ No newline at end of file
src/Shopify/lib/AbstractShopify.php
View file @
54f5d43f
...
...
@@ -9,7 +9,8 @@
namespace
Meibuyu\Micro\Shopify\lib
;
use
Exception
;
use
Meibuyu\Micro\Shopify\Tools\HttpRequestJson
;
use
Meibuyu\Micro\Shopify\tools\CurlHttpRequestJson
;
use
Meibuyu\Micro\Shopify\tools\HttpRequestJson
;
use
Psr\Http\Message\ResponseInterface
;
abstract
class
AbstractShopify
...
...
@@ -45,7 +46,7 @@ abstract class AbstractShopify
private
$config
;
/**
* @var HttpRequestJson
* @var HttpRequestJson
|CurlHttpRequestJson
*/
private
$httpRequestJson
;
...
...
@@ -62,7 +63,7 @@ abstract class AbstractShopify
$this
->
id
=
$id
;
$this
->
pluralizeKey
=
$this
->
pluralizeKey
?:
$this
->
resourceKey
.
's'
;
$this
->
resourceUrl
=
(
$parentResourceUrl
?
"
$parentResourceUrl
/"
:
$config
[
'api_url'
])
.
$this
->
pluralizeKey
.
(
$this
->
id
?
"/
{
$this
->
id
}
"
:
''
);
$this
->
httpRequestJson
=
make
(
HttpRequestJson
::
class
);
$this
->
httpRequestJson
=
make
(
Curl
HttpRequestJson
::
class
);
if
(
isset
(
$config
[
'api_password'
]))
{
$this
->
httpHeaders
[
'X-Shopify-Access-Token'
]
=
$config
[
'api_password'
];
}
elseif
(
!
isset
(
$config
[
'api_password'
]))
{
...
...
@@ -158,20 +159,20 @@ abstract class AbstractShopify
return
$resourceUrl
.
(
$customAction
?
"/
$customAction
"
:
''
)
.
'.json'
.
(
!
empty
(
$urlParams
)
?
'?'
.
http_build_query
(
$urlParams
)
:
''
);
}
//
/**
//
* 获取数量
//
* @param array $urlParams
//
* @return mixed
//
* @throws Exception
//
*/
//
public function count($urlParams = [])
//
{
//
if (!$this->countEnabled) {
//
throw new Exception("当前类{$this->getResourceName()}不支持count()方法");
//
}
//
$url = $this->generateUrl($urlParams, null, 'count');
//
return $this->get([], $url, 'count');
//
}
/**
* 获取数量
* @param array $urlParams
* @return mixed
* @throws Exception
*/
public
function
count
(
$urlParams
=
[])
{
if
(
!
$this
->
countEnabled
)
{
throw
new
Exception
(
"当前类
{
$this
->
getResourceName
()
}
不支持count()方法"
);
}
$url
=
$this
->
generateUrl
(
$urlParams
,
null
,
'count'
);
return
$this
->
get
([],
$url
,
'count'
);
}
/**
* @param array $urlParams
...
...
@@ -282,15 +283,14 @@ abstract class AbstractShopify
/**
* 处理响应
* @param
ResponseInterface
$response
* @param
array
$response
* @param null $dataKey
* @return mixed
* @throws Exception
*/
public
function
processResponse
(
$response
,
$dataKey
=
null
)
{
$code
=
$response
->
getStatusCode
();
$content
=
$response
->
getBody
()
->
getContents
();
[
$code
,
,
$content
]
=
$response
;
$content
=
json_decode
(
$content
,
true
);
if
(
isset
(
$content
[
'errors'
]))
{
throw
new
Exception
(
$this
->
castString
(
$content
[
'errors'
]),
$code
);
...
...
@@ -302,28 +302,6 @@ abstract class AbstractShopify
}
}
/**
* 处理响应
* @param array $response
* @param null $dataKey
* @return mixed
* @throws Exception
*/
public
function
processResponseOld
(
$response
,
$dataKey
=
null
)
{
[
$code
,
$header
,
$body
]
=
$response
;
$content
=
json_decode
(
$body
,
true
);
if
(
isset
(
$content
[
'errors'
]))
{
throw
new
Exception
(
$this
->
castString
(
$content
[
'errors'
]),
$code
);
}
if
(
$dataKey
&&
isset
(
$content
[
$dataKey
]))
{
return
$content
[
$dataKey
];
}
else
{
return
$content
;
}
}
/**
* 处理响应
* @param ResponseInterface $response
...
...
@@ -333,9 +311,7 @@ abstract class AbstractShopify
*/
public
function
processPageResponse
(
$response
,
$dataKey
=
null
)
{
$code
=
$response
->
getStatusCode
();
$headers
=
$response
->
getHeaders
();
$content
=
$response
->
getBody
()
->
getContents
();
[
$code
,
$headers
,
$content
]
=
$response
;
$content
=
json_decode
(
$content
,
true
);
$link
=
$this
->
getLink
(
$headers
);
if
(
isset
(
$content
[
'errors'
]))
{
...
...
@@ -351,11 +327,11 @@ abstract class AbstractShopify
public
function
getLink
(
$header
,
$type
=
'next'
)
{
if
(
!
empty
(
$header
[
'
X-Shopify-API-Version'
][
0
])
&&
$header
[
'X-Shopify-API-V
ersion'
][
0
]
<
'2019-07'
)
{
if
(
!
empty
(
$header
[
'
x-shopify-api-version'
][
0
])
&&
$header
[
'x-shopify-api-v
ersion'
][
0
]
<
'2019-07'
)
{
return
null
;
}
if
(
!
empty
(
$header
[
'
L
ink'
][
0
]))
{
$headerLinks
=
$header
[
'
L
ink'
][
0
];
if
(
!
empty
(
$header
[
'
l
ink'
][
0
]))
{
$headerLinks
=
$header
[
'
l
ink'
][
0
];
if
(
stristr
(
$headerLinks
,
'; rel="'
.
$type
.
'"'
)
>
-
1
)
{
$headerLinks
=
explode
(
','
,
$headerLinks
);
foreach
(
$headerLinks
as
$headerLink
)
{
...
...
src/Shopify/lib/Graphql.php
View file @
54f5d43f
...
...
@@ -26,7 +26,7 @@ class Graphql extends AbstractShopify
{
if
(
!
$url
)
$url
=
$this
->
generateUrl
();
$response
=
HttpRequestGraphQL
::
post
(
$url
,
$graphQL
,
$this
->
httpHeaders
,
$variables
);
return
$this
->
processResponse
Old
(
$response
);
return
$this
->
processResponse
(
$response
);
}
public
function
get
(
$urlParams
=
array
(),
$url
=
null
,
$dataKey
=
null
)
...
...
src/Shopify/lib/InventoryItem.php
View file @
54f5d43f
...
...
@@ -11,6 +11,6 @@ namespace Meibuyu\Micro\Shopify\lib;
class
InventoryItem
extends
AbstractShopify
{
protected
$resourceKey
=
'inventory_item'
;
protected
$resourceKey
=
'inventory_item
_123
'
;
}
src/Shopify/lib/InventoryLevel.php
View file @
54f5d43f
...
...
@@ -19,7 +19,7 @@ namespace Meibuyu\Micro\Shopify\lib;
class
InventoryLevel
extends
AbstractShopify
{
protected
$resourceKey
=
'inventory_level'
;
protected
$resourceKey
=
'inventory_level
_123
'
;
protected
$customPostActions
=
[
'adjust'
,
...
...
src/
Tools/
HttpRequestJson.php
→
src/
Shopify/tools/Curl
HttpRequestJson.php
View file @
54f5d43f
...
...
@@ -6,20 +6,19 @@
* Time: 9:06
*/
namespace
Meibuyu\Micro\
T
ools
;
namespace
Meibuyu\Micro\
Shopify\t
ools
;
//use GuzzleHttp\Client;
//use Psr\Http\Message\ResponseInterface;
use
Exception
;
/**
*
json格式请求(非协程)
*
Curl的json格式请求
* Class HttpRequestJson
* @package Meibuyu\Micro\Tools
*/
class
HttpRequestJson
class
Curl
HttpRequestJson
{
protected
static
function
prepareRequest
(
$headers
,
$data
=
[])
protected
function
prepareRequest
(
$headers
,
$data
=
[])
{
$data
=
json_encode
(
$data
);
if
(
!
empty
(
$data
))
{
...
...
@@ -29,63 +28,14 @@ class HttpRequestJson
return
[
$headers
,
$data
];
}
// /**
// * get请求
// * @param $url
// * @param array $httpHeaders
// * @return ResponseInterface
// */
// public static function get($url, $httpHeaders = [])
// {
// $client = new Client(['timeout' => 30]);
// return $client->get($url, ['headers' => $httpHeaders]);
// }
//
// /**
// * post请求
// * @param $url
// * @param $data
// * @param array $httpHeaders
// * @return ResponseInterface
// */
// public static function post($url, $data, $httpHeaders = [])
// {
// $client = new Client(['timeout' => 30]);
// return $client->post($url, ['headers' => $httpHeaders, 'json' => $data]);
// }
//
// /**
// * put请求
// * @param $url
// * @param $data
// * @param array $httpHeaders
// * @return ResponseInterface
// */
// public static function put($url, $data, $httpHeaders = [])
// {
// $client = new Client(['timeout' => 30]);
// return $client->put($url, ['headers' => $httpHeaders, 'json' => $data]);
// }
//
// /**
// * delete请求
// * @param $url
// * @param array $httpHeaders
// * @return ResponseInterface
// */
// public static function delete($url, $httpHeaders = [])
// {
// $client = new Client(['timeout' => 30]);
// return $client->delete($url, ['headers' => $httpHeaders]);
// }
/**
* get请求
* @param $url
* @param array $headers
* @return array
* @throws Exception
* @author zero
*/
public
static
function
get
(
$url
,
$headers
=
[])
public
function
get
(
$url
,
$headers
=
[])
{
return
CurlRequest
::
get
(
$url
,
$headers
);
}
...
...
@@ -96,8 +46,10 @@ class HttpRequestJson
* @param $data
* @param array $headers
* @return array
* @throws Exception
* @author zero
*/
public
static
function
post
(
$url
,
$data
,
$headers
=
[])
public
function
post
(
$url
,
$data
,
$headers
=
[])
{
[
$headers
,
$data
]
=
self
::
prepareRequest
(
$headers
,
$data
);
return
CurlRequest
::
post
(
$url
,
$data
,
$headers
);
...
...
@@ -109,8 +61,10 @@ class HttpRequestJson
* @param $data
* @param array $headers
* @return array
* @throws Exception
* @author zero
*/
public
static
function
put
(
$url
,
$data
,
$headers
=
[])
public
function
put
(
$url
,
$data
,
$headers
=
[])
{
[
$headers
,
$data
]
=
self
::
prepareRequest
(
$headers
,
$data
);
return
CurlRequest
::
put
(
$url
,
$data
,
$headers
);
...
...
@@ -121,8 +75,10 @@ class HttpRequestJson
* @param $url
* @param array $headers
* @return array
* @throws Exception
* @author zero
*/
public
static
function
delete
(
$url
,
$headers
=
[])
public
function
delete
(
$url
,
$headers
=
[])
{
return
CurlRequest
::
delete
(
$url
,
$headers
);
}
...
...
src/
T
ools/CurlRequest.php
→
src/
Shopify/t
ools/CurlRequest.php
View file @
54f5d43f
<?php
namespace
Meibuyu\Micro\
T
ools
;
namespace
Meibuyu\Micro\
Shopify\t
ools
;
use
Exception
;
...
...
@@ -22,12 +22,27 @@ class CurlRequest
return
$ch
;
}
/**
* @param $url
* @param array $httpHeaders
* @return array
* @throws Exception
* @author zero
*/
public
static
function
get
(
$url
,
$httpHeaders
=
[])
{
$ch
=
self
::
init
(
$url
,
$httpHeaders
);
return
self
::
processRequest
(
$ch
);
}
/**
* @param $url
* @param $data
* @param array $httpHeaders
* @return array
* @throws Exception
* @author zero
*/
public
static
function
post
(
$url
,
$data
,
$httpHeaders
=
[])
{
$ch
=
self
::
init
(
$url
,
$httpHeaders
);
...
...
@@ -36,6 +51,14 @@ class CurlRequest
return
self
::
processRequest
(
$ch
);
}
/**
* @param $url
* @param $data
* @param array $httpHeaders
* @return array
* @throws Exception
* @author zero
*/
public
static
function
put
(
$url
,
$data
,
$httpHeaders
=
[])
{
$ch
=
self
::
init
(
$url
,
$httpHeaders
);
...
...
@@ -44,6 +67,13 @@ class CurlRequest
return
self
::
processRequest
(
$ch
);
}
/**
* @param $url
* @param array $httpHeaders
* @return array
* @throws Exception
* @author zero
*/
public
static
function
delete
(
$url
,
$httpHeaders
=
[])
{
$ch
=
self
::
init
(
$url
,
$httpHeaders
);
...
...
@@ -51,17 +81,23 @@ class CurlRequest
return
self
::
processRequest
(
$ch
);
}
/**
* @param $ch
* @return array
* @throws Exception
* @author zero
*/
protected
static
function
processRequest
(
$ch
)
{
$output
=
curl_exec
(
$ch
);
$response
=
new
CurlResponse
(
$output
);
$httpCode
=
curl_getinfo
(
$ch
,
CURLINFO_HTTP_CODE
);
if
(
$httpCode
==
429
)
{
$limitHeader
=
explode
(
'/'
,
$response
->
getHeader
(
'X-Shopify-Shop-Api-Call-Limit'
)
,
2
);
if
(
isset
(
$limitHeader
[
1
])
&&
$limitHeader
[
0
]
<
$limitHeader
[
1
])
{
throw
new
Exception
(
$response
->
getBody
());
}
}
//
if ($httpCode == 429) {
// $limitHeader = explode('/', $response->getHeader('X-Shopify-Shop-Api-Call-Limit')[0]
, 2);
//
if (isset($limitHeader[1]) && $limitHeader[0] < $limitHeader[1]) {
//
throw new Exception($response->getBody());
//
}
//
}
if
(
curl_errno
(
$ch
))
{
throw
new
Exception
(
curl_errno
(
$ch
)
.
' : '
.
curl_error
(
$ch
));
}
...
...
src/
T
ools/CurlResponse.php
→
src/
Shopify/t
ools/CurlResponse.php
View file @
54f5d43f
<?php
namespace
Meibuyu\Micro\
T
ools
;
namespace
Meibuyu\Micro\
Shopify\t
ools
;
class
CurlResponse
{
...
...
@@ -21,16 +21,16 @@ class CurlResponse
*/
private
function
parse
(
$response
)
{
$response
=
\
explode
(
"
\r\n\r\n
"
,
$response
);
if
(
\
count
(
$response
)
>
1
)
{
$response
=
explode
(
"
\r\n\r\n
"
,
$response
);
if
(
count
(
$response
)
>
1
)
{
// We want the last two parts
$response
=
\
array_slice
(
$response
,
-
2
,
2
);
$response
=
array_slice
(
$response
,
-
2
,
2
);
list
(
$headers
,
$body
)
=
$response
;
foreach
(
\
explode
(
"
\r\n
"
,
$headers
)
as
$header
)
{
$pair
=
\
explode
(
': '
,
$header
,
2
);
foreach
(
explode
(
"
\r\n
"
,
$headers
)
as
$header
)
{
$pair
=
explode
(
': '
,
$header
,
2
);
if
(
isset
(
$pair
[
1
]))
{
$headerKey
=
strtolower
(
$pair
[
0
]);
$this
->
headers
[
$headerKey
]
=
$pair
[
1
];
$this
->
headers
[
$headerKey
]
[]
=
$pair
[
1
];
}
}
}
else
{
...
...
src/Shopify/tools/HttpRequestGraphQL.php
View file @
54f5d43f
...
...
@@ -7,18 +7,25 @@
namespace
Meibuyu\Micro\Shopify\tools
;
use
Meibuyu\Micro\Tools\CurlRequest
;
use
Meibuyu\Micro\Tools\HttpRequestJson
;
use
Exception
;
class
HttpRequestGraphQL
extends
HttpRequestJson
class
HttpRequestGraphQL
{
/**
* @param array $headers
* @param array $data
* @param null $variables
* @return array
* @throws Exception
* @author zero
*/
protected
static
function
prepareRequest
(
$headers
=
[],
$data
=
[],
$variables
=
null
)
{
if
(
is_string
(
$data
))
{
$postDataGraphQL
=
$data
;
}
else
{
throw
new
\
Exception
(
"Only GraphQL string is allowed!"
);
throw
new
Exception
(
"Only GraphQL string is allowed!"
);
}
if
(
is_array
(
$variables
))
{
$postDataGraphQL
=
json_encode
([
'query'
=>
$data
,
'variables'
=>
$variables
]);
...
...
@@ -29,6 +36,15 @@ class HttpRequestGraphQL extends HttpRequestJson
return
[
$headers
,
$postDataGraphQL
];
}
/**
* @param $url
* @param $data
* @param array $headers
* @param null $variables
* @return array
* @throws Exception
* @author zero
*/
public
static
function
post
(
$url
,
$data
,
$headers
=
[],
$variables
=
null
)
{
[
$headers
,
$postDataGraphQL
]
=
self
::
prepareRequest
(
$headers
,
$data
,
$variables
);
...
...
src/Shopify/tools/HttpRequestJson.php
View file @
54f5d43f
...
...
@@ -47,7 +47,8 @@ class HttpRequestJson
public
function
get
(
$url
,
$httpHeaders
=
[])
{
$client
=
$this
->
clientFactory
->
create
([
'timeout'
=>
60
,
'handler'
=>
$this
->
stack
,]);
return
$client
->
get
(
$url
,
[
'headers'
=>
$httpHeaders
]);
$res
=
$client
->
get
(
$url
,
[
'headers'
=>
$httpHeaders
]);
return
$this
->
processResponse
(
$res
);
}
/**
...
...
@@ -60,7 +61,8 @@ class HttpRequestJson
public
function
post
(
$url
,
$data
,
$httpHeaders
=
[])
{
$client
=
$this
->
clientFactory
->
create
([
'timeout'
=>
60
,
'handler'
=>
$this
->
stack
,]);
return
$client
->
post
(
$url
,
[
'headers'
=>
$httpHeaders
,
'json'
=>
$data
]);
$res
=
$client
->
post
(
$url
,
[
'headers'
=>
$httpHeaders
,
'json'
=>
$data
]);
return
$this
->
processResponse
(
$res
);
}
/**
...
...
@@ -73,7 +75,8 @@ class HttpRequestJson
public
function
put
(
$url
,
$data
,
$httpHeaders
=
[])
{
$client
=
$this
->
clientFactory
->
create
([
'timeout'
=>
60
,
'handler'
=>
$this
->
stack
,]);
return
$client
->
put
(
$url
,
[
'headers'
=>
$httpHeaders
,
'json'
=>
$data
]);
$res
=
$client
->
put
(
$url
,
[
'headers'
=>
$httpHeaders
,
'json'
=>
$data
]);
return
$this
->
processResponse
(
$res
);
}
/**
...
...
@@ -85,7 +88,21 @@ class HttpRequestJson
public
function
delete
(
$url
,
$httpHeaders
=
[])
{
$client
=
$this
->
clientFactory
->
create
([
'timeout'
=>
60
,
'handler'
=>
$this
->
stack
,]);
return
$client
->
delete
(
$url
,
[
'headers'
=>
$httpHeaders
]);
$res
=
$client
->
delete
(
$url
,
[
'headers'
=>
$httpHeaders
]);
return
$this
->
processResponse
(
$res
);
}
/**
* 处理响应
* @param ResponseInterface $response
* @return mixed
*/
public
function
processResponse
(
$response
)
{
$code
=
$response
->
getStatusCode
();
$headers
=
$response
->
getHeaders
();
$content
=
$response
->
getBody
()
->
getContents
();
return
[
$code
,
$headers
,
$content
];
}
}
src/Tools/Cacher.php
0 → 100644
View file @
54f5d43f
<?php
namespace
Meibuyu\Micro\Tools
;
use
Psr\SimpleCache\CacheInterface
;
/**
* Class Cache
* @package Meibuyu\Micro\Tools
* @method static get($key, $default = null)
* @method static set($key, $value, $ttl = null)
* @method static delete($key)
* @method static clear()
* @method static getMultiple($keys, $default = null)
* @method static setMultiple($values, $ttl = null)
* @method static deleteMultiple($keys)
* @method static has($key)
*/
class
Cacher
{
/**
* @var CacheInterface
*/
protected
static
$driver
;
/**
* @return CacheInterface
*/
public
static
function
driver
()
{
if
(
!
self
::
$driver
)
{
self
::
$driver
=
container
(
CacheInterface
::
class
);
}
return
self
::
$driver
;
}
public
static
function
__callStatic
(
$name
,
$arguments
)
{
return
static
::
driver
()
->
{
$name
}(
...
$arguments
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment