1 | <?php |
||
35 | abstract class AbstractAPI |
||
36 | { |
||
37 | /** |
||
38 | * Http instance. |
||
39 | * |
||
40 | * @var \EasyWeChat\Core\Http |
||
41 | */ |
||
42 | protected $http; |
||
43 | |||
44 | /** |
||
45 | * The reqeust token. |
||
46 | * |
||
47 | * @var \EasyWeChat\Core\AccessToken |
||
48 | */ |
||
49 | protected $accessToken; |
||
50 | |||
51 | const GET = 'get'; |
||
52 | const POST = 'post'; |
||
53 | const JSON = 'json'; |
||
54 | |||
55 | /** |
||
56 | * Constructor. |
||
57 | * |
||
58 | * @param \EasyWeChat\Core\AccessToken $accessToken |
||
59 | */ |
||
60 | 84 | public function __construct(AccessToken $accessToken) |
|
64 | |||
65 | /** |
||
66 | * Return the http instance. |
||
67 | * |
||
68 | * @return \EasyWeChat\Core\Http |
||
69 | */ |
||
70 | 8 | public function getHttp() |
|
82 | |||
83 | /** |
||
84 | * Set the http instance. |
||
85 | * |
||
86 | * @param \EasyWeChat\Core\Http $http |
||
87 | * |
||
88 | * @return $this |
||
89 | */ |
||
90 | 11 | public function setHttp(Http $http) |
|
96 | |||
97 | /** |
||
98 | * Return the current accessToken. |
||
99 | * |
||
100 | * @return \EasyWeChat\Core\AccessToken |
||
101 | */ |
||
102 | 6 | public function getAccessToken() |
|
106 | |||
107 | /** |
||
108 | * Set the request token. |
||
109 | * |
||
110 | * @param \EasyWeChat\Core\AccessToken $accessToken |
||
111 | * |
||
112 | * @return $this |
||
113 | */ |
||
114 | 84 | public function setAccessToken(AccessToken $accessToken) |
|
120 | |||
121 | /** |
||
122 | * Parse JSON from response and check error. |
||
123 | * |
||
124 | * @param string $method |
||
125 | * @param array $args |
||
126 | * |
||
127 | * @return \EasyWeChat\Support\Collection |
||
128 | */ |
||
129 | 6 | public function parseJSON($method, array $args) |
|
139 | |||
140 | /** |
||
141 | * Set request access_token query. |
||
142 | */ |
||
143 | 7 | protected function registerHttpMiddlewares() |
|
152 | |||
153 | /** |
||
154 | * Attache access token to request query. |
||
155 | * |
||
156 | * @return \Closure |
||
157 | */ |
||
158 | 7 | protected function accessTokenMiddleware() |
|
175 | |||
176 | /** |
||
177 | * Log the request. |
||
178 | * |
||
179 | * @return \Closure |
||
180 | */ |
||
181 | 7 | protected function logMiddleware() |
|
188 | |||
189 | /** |
||
190 | * Return retry middleware. |
||
191 | * |
||
192 | * @return \Closure |
||
193 | */ |
||
194 | protected function retryMiddleware() |
||
220 | |||
221 | /** |
||
222 | * Check the array data erros, and Throw expcetion when the contents cotnains error. |
||
223 | * |
||
224 | * @param array $contents |
||
225 | * |
||
226 | * @throws \EasyWeChat\Core\Exceptions\HttpException |
||
227 | */ |
||
228 | 7 | protected function checkAndThrow(array $contents) |
|
238 | } |
||
239 |