@@ 668-689 (lines=22) @@ | ||
665 | self.scope = res['scope'] |
|
666 | return res |
|
667 | ||
668 | def refresh_access_token(self, refresh_token): |
|
669 | """刷新 access token |
|
670 | ||
671 | :param refresh_token: OAuth2 refresh token |
|
672 | :return: JSON 数据包 |
|
673 | """ |
|
674 | res = self._get( |
|
675 | 'sns/oauth2/component/refresh_token', |
|
676 | params={ |
|
677 | 'appid': self.app_id, |
|
678 | 'grant_type': 'refresh_token', |
|
679 | 'refresh_token': refresh_token, |
|
680 | 'component_appid': self.component.component_appid, |
|
681 | 'component_access_token': self.component.access_token, |
|
682 | } |
|
683 | ) |
|
684 | self.access_token = res['access_token'] |
|
685 | self.open_id = res['openid'] |
|
686 | self.refresh_token = res['refresh_token'] |
|
687 | self.expires_in = res['expires_in'] |
|
688 | self.scope = res['scope'] |
|
689 | return res |
|
690 | ||
691 | def get_user_info(self, openid=None, access_token=None, lang='zh_CN'): |
|
692 | """ 获取用户基本信息(需授权作用域为snsapi_userinfo) |
|
@@ 645-666 (lines=22) @@ | ||
642 | url_list.append('#wechat_redirect') |
|
643 | return ''.join(url_list) |
|
644 | ||
645 | def fetch_access_token(self, code): |
|
646 | """获取 access_token |
|
647 | ||
648 | :param code: 授权完成跳转回来后 URL 中的 code 参数 |
|
649 | :return: JSON 数据包 |
|
650 | """ |
|
651 | res = self._get( |
|
652 | 'sns/oauth2/component/access_token', |
|
653 | params={ |
|
654 | 'appid': self.app_id, |
|
655 | 'component_appid': self.component.component_appid, |
|
656 | 'component_access_token': self.component.access_token, |
|
657 | 'code': code, |
|
658 | 'grant_type': 'authorization_code', |
|
659 | } |
|
660 | ) |
|
661 | self.access_token = res['access_token'] |
|
662 | self.open_id = res['openid'] |
|
663 | self.refresh_token = res['refresh_token'] |
|
664 | self.expires_in = res['expires_in'] |
|
665 | self.scope = res['scope'] |
|
666 | return res |
|
667 | ||
668 | def refresh_access_token(self, refresh_token): |
|
669 | """刷新 access token |