@@ 252-288 (lines=37) @@ | ||
249 | }) |
|
250 | ) |
|
251 | ||
252 | def _fetch_access_token(self, url, data): |
|
253 | """ The real fetch access token """ |
|
254 | logger.info('Fetching component access token') |
|
255 | res = self._http.post( |
|
256 | url=url, |
|
257 | data=data |
|
258 | ) |
|
259 | try: |
|
260 | res.raise_for_status() |
|
261 | except requests.RequestException as reqe: |
|
262 | raise WeChatClientException( |
|
263 | errcode=None, |
|
264 | errmsg=None, |
|
265 | client=self, |
|
266 | request=reqe.request, |
|
267 | response=reqe.response |
|
268 | ) |
|
269 | result = res.json() |
|
270 | if 'errcode' in result and result['errcode'] != 0: |
|
271 | raise WeChatClientException( |
|
272 | result['errcode'], |
|
273 | result['errmsg'], |
|
274 | client=self, |
|
275 | request=res.request, |
|
276 | response=res |
|
277 | ) |
|
278 | ||
279 | expires_in = 7200 |
|
280 | if 'expires_in' in result: |
|
281 | expires_in = result['expires_in'] |
|
282 | self.session.set( |
|
283 | 'component_access_token', |
|
284 | result['component_access_token'], |
|
285 | expires_in |
|
286 | ) |
|
287 | self.expires_at = int(time.time()) + expires_in |
|
288 | return result |
|
289 | ||
290 | @property |
|
291 | def access_token(self): |
@@ 194-230 (lines=37) @@ | ||
191 | DeprecationWarning, stacklevel=2) |
|
192 | return self.post(url, **kwargs) |
|
193 | ||
194 | def _fetch_access_token(self, url, params): |
|
195 | """ The real fetch access token """ |
|
196 | logger.info('Fetching access token') |
|
197 | res = self._http.get( |
|
198 | url=url, |
|
199 | params=params |
|
200 | ) |
|
201 | try: |
|
202 | res.raise_for_status() |
|
203 | except requests.RequestException as reqe: |
|
204 | raise WeChatClientException( |
|
205 | errcode=None, |
|
206 | errmsg=None, |
|
207 | client=self, |
|
208 | request=reqe.request, |
|
209 | response=reqe.response |
|
210 | ) |
|
211 | result = res.json() |
|
212 | if 'errcode' in result and result['errcode'] != 0: |
|
213 | raise WeChatClientException( |
|
214 | result['errcode'], |
|
215 | result['errmsg'], |
|
216 | client=self, |
|
217 | request=res.request, |
|
218 | response=res |
|
219 | ) |
|
220 | ||
221 | expires_in = 7200 |
|
222 | if 'expires_in' in result: |
|
223 | expires_in = result['expires_in'] |
|
224 | self.session.set( |
|
225 | self.access_token_key, |
|
226 | result['access_token'], |
|
227 | expires_in |
|
228 | ) |
|
229 | self.expires_at = int(time.time()) + expires_in |
|
230 | return result |
|
231 | ||
232 | def fetch_access_token(self): |
|
233 | raise NotImplementedError() |