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 | 80 | public function __construct(AccessToken $accessToken) |
|
66 | |||
67 | /** |
||
68 | * Return the http instance. |
||
69 | * |
||
70 | * @return \EasyWeChat\Core\Http |
||
71 | */ |
||
72 | 80 | public function getHttp() |
|
76 | |||
77 | /** |
||
78 | * Set the http instance. |
||
79 | * |
||
80 | * @param \EasyWeChat\Core\Http $http |
||
81 | * |
||
82 | * @return $this |
||
83 | */ |
||
84 | 9 | public function setHttp(Http $http) |
|
90 | |||
91 | /** |
||
92 | * Return the current accessToken. |
||
93 | * |
||
94 | * @return \EasyWeChat\Core\AccessToken |
||
95 | */ |
||
96 | 5 | public function getAccessToken() |
|
100 | |||
101 | /** |
||
102 | * Set the request token. |
||
103 | * |
||
104 | * @param \EasyWeChat\Core\AccessToken $accessToken |
||
105 | * |
||
106 | * @return $this |
||
107 | */ |
||
108 | 80 | public function setAccessToken(AccessToken $accessToken) |
|
114 | |||
115 | /** |
||
116 | * Parse JSON from response and check error. |
||
117 | * |
||
118 | * @param string $method |
||
119 | * @param array $args |
||
120 | * |
||
121 | * @return \EasyWeChat\Support\Collection |
||
122 | */ |
||
123 | 5 | public function parseJSON($method, array $args) |
|
133 | |||
134 | /** |
||
135 | * Set request access_token query. |
||
136 | */ |
||
137 | 80 | protected function registerHttpMiddleware() |
|
146 | |||
147 | /** |
||
148 | * Attache access token to request query. |
||
149 | * |
||
150 | * @return \Closure |
||
151 | */ |
||
152 | 80 | public function accessTokenMiddleware() |
|
169 | |||
170 | /** |
||
171 | * Log the request. |
||
172 | * |
||
173 | * @return \Closure |
||
174 | */ |
||
175 | 80 | public function logMiddleware() |
|
182 | |||
183 | /** |
||
184 | * Return retry middleware. |
||
185 | * |
||
186 | * @return \Closure |
||
187 | */ |
||
188 | protected function retryMiddleware() |
||
214 | |||
215 | /** |
||
216 | * Check the array data erros, and Throw expcetion when the contents cotnains error. |
||
217 | * |
||
218 | * @param array $contents |
||
219 | * |
||
220 | * @throws \EasyWeChat\Core\Exceptions\HttpException |
||
221 | */ |
||
222 | 6 | protected function checkAndThrow(array $contents) |
|
232 | } |
||
233 |