{"action":"created","comment":{"url":"https://api.github.com/repos/jxtech/wechatpy/pulls/comments/39369730","id":39369730,"diff_hunk":"@@ -53,3 +54,51 @@ def fetch_access_token(self):\n                 'secret': self.secret\n             }\n         )\n+\n+\n+class WeChatComponentClient(WeChatClient):\n+\n+    \"\"\"\n+    开放平台代公众号调用客户端\n+    \"\"\"\n+\n+    def __init__(\n+            self, appid, access_token, refresh_token, component, session=None):\n+        # 未用到secret，所以这里没有\n+        super(WeChatComponentClient, self).__init__(\n+            appid, '', access_token, session)\n+        self.appid = appid\n+        self.component = component\n+        self.session.set('refresh_token', refresh_token)\n+\n+    @property\n+    def access_token(self):\n+        access_token = self.session.get('access_token')\n+        if not access_token:\n+            self.fetch_access_token()\n+            access_token = self.session.get('access_token')\n+        return access_token\n+\n+    @property\n+    def refresh_token(self):\n+        return self.session.get('refresh_token')\n+\n+    def fetch_access_token(self):\n+        \"\"\"\n+        获取 access token\n+        详情请参考 https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list\\\n+        &t=resource/res_list&verify=1&id=open1419318587&token=&lang=zh_CN\n+\n+        :return: 返回的 JSON 数据包\n+        \"\"\"\n+        expires_in = 7200\n+        result = self.component.refresh_authorizer_token(\n+            self.appid, self.refresh_token)\n+        if 'expires_in' in result:\n+            expires_in = result['expires_in']\n+        self.session.set(\n+            'access_token', result['authorizer_access_token'], expires_in)","path":"wechatpy/client/__init__.py","position":61,"original_position":61,"commit_id":"fd9686d5959ddbac98463b171efdf952b087008f","original_commit_id":"fd9686d5959ddbac98463b171efdf952b087008f","user":{"login":"messense","id":1556054,"avatar_url":"https://avatars.githubusercontent.com/u/1556054?v=3","gravatar_id":"","url":"https://api.github.com/users/messense","html_url":"https://github.com/messense","followers_url":"https://api.github.com/users/messense/followers","following_url":"https://api.github.com/users/messense/following{/other_user}","gists_url":"https://api.github.com/users/messense/gists{/gist_id}","starred_url":"https://api.github.com/users/messense/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/messense/subscriptions","organizations_url":"https://api.github.com/users/messense/orgs","repos_url":"https://api.github.com/users/messense/repos","events_url":"https://api.github.com/users/messense/events{/privacy}","received_events_url":"https://api.github.com/users/messense/received_events","type":"User","site_admin":false},"body":"这里 session 里存的名字最好加个 component_ 前缀避免使用同一个 session storage 导致和普通 client 重名覆盖？","created_at":"2015-09-14T08:19:54Z","updated_at":"2015-09-14T08:19:54Z","html_url":"https://github.com/jxtech/wechatpy/pull/85#discussion_r39369730","pull_request_url":"https://api.github.com/repos/jxtech/wechatpy/pulls/85","_links":{"self":{"href":"https://api.github.com/repos/jxtech/wechatpy/pulls/comments/39369730"},"html":{"href":"https://github.com/jxtech/wechatpy/pull/85#discussion_r39369730"},"pull_request":{"href":"https://api.github.com/repos/jxtech/wechatpy/pulls/85"}}},"pull_request":{"url":"https://api.github.com/repos/jxtech/wechatpy/pulls/85","id":44896875,"html_url":"https://github.com/jxtech/wechatpy/pull/85","diff_url":"https://github.com/jxtech/wechatpy/pull/85.diff","patch_url":"https://github.com/jxtech/wechatpy/pull/85.patch","issue_url":"https://api.github.com/repos/jxtech/wechatpy/issues/85","number":85,"state":"open","locked":false,"title":"Add WeChatComponentAPI and WeChatComponentClient","user":{"login":"hunter007","id":2544362,"avatar_url":"https://avatars.githubusercontent.com/u/2544362?v=3","gravatar_id":"","url":"https://api.github.com/users/hunter007","html_url":"https://github.com/hunter007","followers_url":"https://api.github.com/users/hunter007/followers","following_url":"https://api.github.com/users/hunter007/following{/other_user}","gists_url":"https://api.github.com/users/hunter007/gists{/gist_id}","starred_url":"https://api.github.com/users/hunter007/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hunter007/subscriptions","organizations_url":"https://api.github.com/users/hunter007/orgs","repos_url":"https://api.github.com/users/hunter007/repos","events_url":"https://api.github.com/users/hunter007/events{/privacy}","received_events_url":"https://api.github.com/users/hunter007/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-09-14T06:32:45Z","updated_at":"2015-09-14T08:19:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7bcd308b4dff0de31f39d01acca973f70f05748b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/jxtech/wechatpy/pulls/85/commits","review_comments_url":"https://api.github.com/repos/jxtech/wechatpy/pulls/85/comments","review_comment_url":"https://api.github.com/repos/jxtech/wechatpy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/jxtech/wechatpy/issues/85/comments","statuses_url":"https://api.github.com/repos/jxtech/wechatpy/statuses/fd9686d5959ddbac98463b171efdf952b087008f","head":{"label":"hunter007:master","ref":"master","sha":"fd9686d5959ddbac98463b171efdf952b087008f","user":{"login":"hunter007","id":2544362,"avatar_url":"https://avatars.githubusercontent.com/u/2544362?v=3","gravatar_id":"","url":"https://api.github.com/users/hunter007","html_url":"https://github.com/hunter007","followers_url":"https://api.github.com/users/hunter007/followers","following_url":"https://api.github.com/users/hunter007/following{/other_user}","gists_url":"https://api.github.com/users/hunter007/gists{/gist_id}","starred_url":"https://api.github.com/users/hunter007/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hunter007/subscriptions","organizations_url":"https://api.github.com/users/hunter007/orgs","repos_url":"https://api.github.com/users/hunter007/repos","events_url":"https://api.github.com/users/hunter007/events{/privacy}","received_events_url":"https://api.github.com/users/hunter007/received_events","type":"User","site_admin":false},"repo":{"id":42430583,"name":"wechatpy","full_name":"hunter007/wechatpy","owner":{"login":"hunter007","id":2544362,"avatar_url":"https://avatars.githubusercontent.com/u/2544362?v=3","gravatar_id":"","url":"https://api.github.com/users/hunter007","html_url":"https://github.com/hunter007","followers_url":"https://api.github.com/users/hunter007/followers","following_url":"https://api.github.com/users/hunter007/following{/other_user}","gists_url":"https://api.github.com/users/hunter007/gists{/gist_id}","starred_url":"https://api.github.com/users/hunter007/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hunter007/subscriptions","organizations_url":"https://api.github.com/users/hunter007/orgs","repos_url":"https://api.github.com/users/hunter007/repos","events_url":"https://api.github.com/users/hunter007/events{/privacy}","received_events_url":"https://api.github.com/users/hunter007/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/hunter007/wechatpy","description":"WeChat SDK for Python","fork":true,"url":"https://api.github.com/repos/hunter007/wechatpy","forks_url":"https://api.github.com/repos/hunter007/wechatpy/forks","keys_url":"https://api.github.com/repos/hunter007/wechatpy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hunter007/wechatpy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hunter007/wechatpy/teams","hooks_url":"https://api.github.com/repos/hunter007/wechatpy/hooks","issue_events_url":"https://api.github.com/repos/hunter007/wechatpy/issues/events{/number}","events_url":"https://api.github.com/repos/hunter007/wechatpy/events","assignees_url":"https://api.github.com/repos/hunter007/wechatpy/assignees{/user}","branches_url":"https://api.github.com/repos/hunter007/wechatpy/branches{/branch}","tags_url":"https://api.github.com/repos/hunter007/wechatpy/tags","blobs_url":"https://api.github.com/repos/hunter007/wechatpy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hunter007/wechatpy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hunter007/wechatpy/git/refs{/sha}","trees_url":"https://api.github.com/repos/hunter007/wechatpy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hunter007/wechatpy/statuses/{sha}","languages_url":"https://api.github.com/repos/hunter007/wechatpy/languages","stargazers_url":"https://api.github.com/repos/hunter007/wechatpy/stargazers","contributors_url":"https://api.github.com/repos/hunter007/wechatpy/contributors","subscribers_url":"https://api.github.com/repos/hunter007/wechatpy/subscribers","subscription_url":"https://api.github.com/repos/hunter007/wechatpy/subscription","commits_url":"https://api.github.com/repos/hunter007/wechatpy/commits{/sha}","git_commits_url":"https://api.github.com/repos/hunter007/wechatpy/git/commits{/sha}","comments_url":"https://api.github.com/repos/hunter007/wechatpy/comments{/number}","issue_comment_url":"https://api.github.com/repos/hunter007/wechatpy/issues/comments{/number}","contents_url":"https://api.github.com/repos/hunter007/wechatpy/contents/{+path}","compare_url":"https://api.github.com/repos/hunter007/wechatpy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hunter007/wechatpy/merges","archive_url":"https://api.github.com/repos/hunter007/wechatpy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hunter007/wechatpy/downloads","issues_url":"https://api.github.com/repos/hunter007/wechatpy/issues{/number}","pulls_url":"https://api.github.com/repos/hunter007/wechatpy/pulls{/number}","milestones_url":"https://api.github.com/repos/hunter007/wechatpy/milestones{/number}","notifications_url":"https://api.github.com/repos/hunter007/wechatpy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hunter007/wechatpy/labels{/name}","releases_url":"https://api.github.com/repos/hunter007/wechatpy/releases{/id}","created_at":"2015-09-14T06:16:18Z","updated_at":"2015-09-14T06:16:18Z","pushed_at":"2015-09-14T06:28:47Z","git_url":"git://github.com/hunter007/wechatpy.git","ssh_url":"git@github.com:hunter007/wechatpy.git","clone_url":"https://github.com/hunter007/wechatpy.git","svn_url":"https://github.com/hunter007/wechatpy","homepage":"http://wechatpy.readthedocs.org/zh_CN/latest/","size":1755,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"jxtech:master","ref":"master","sha":"6e30b432c74c6f88e41cdd5dc9630aecb35b7f5b","user":{"login":"jxtech","id":12945147,"avatar_url":"https://avatars.githubusercontent.com/u/12945147?v=3","gravatar_id":"","url":"https://api.github.com/users/jxtech","html_url":"https://github.com/jxtech","followers_url":"https://api.github.com/users/jxtech/followers","following_url":"https://api.github.com/users/jxtech/following{/other_user}","gists_url":"https://api.github.com/users/jxtech/gists{/gist_id}","starred_url":"https://api.github.com/users/jxtech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jxtech/subscriptions","organizations_url":"https://api.github.com/users/jxtech/orgs","repos_url":"https://api.github.com/users/jxtech/repos","events_url":"https://api.github.com/users/jxtech/events{/privacy}","received_events_url":"https://api.github.com/users/jxtech/received_events","type":"Organization","site_admin":false},"repo":{"id":23960826,"name":"wechatpy","full_name":"jxtech/wechatpy","owner":{"login":"jxtech","id":12945147,"avatar_url":"https://avatars.githubusercontent.com/u/12945147?v=3","gravatar_id":"","url":"https://api.github.com/users/jxtech","html_url":"https://github.com/jxtech","followers_url":"https://api.github.com/users/jxtech/followers","following_url":"https://api.github.com/users/jxtech/following{/other_user}","gists_url":"https://api.github.com/users/jxtech/gists{/gist_id}","starred_url":"https://api.github.com/users/jxtech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jxtech/subscriptions","organizations_url":"https://api.github.com/users/jxtech/orgs","repos_url":"https://api.github.com/users/jxtech/repos","events_url":"https://api.github.com/users/jxtech/events{/privacy}","received_events_url":"https://api.github.com/users/jxtech/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/jxtech/wechatpy","description":"WeChat SDK for Python","fork":false,"url":"https://api.github.com/repos/jxtech/wechatpy","forks_url":"https://api.github.com/repos/jxtech/wechatpy/forks","keys_url":"https://api.github.com/repos/jxtech/wechatpy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jxtech/wechatpy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jxtech/wechatpy/teams","hooks_url":"https://api.github.com/repos/jxtech/wechatpy/hooks","issue_events_url":"https://api.github.com/repos/jxtech/wechatpy/issues/events{/number}","events_url":"https://api.github.com/repos/jxtech/wechatpy/events","assignees_url":"https://api.github.com/repos/jxtech/wechatpy/assignees{/user}","branches_url":"https://api.github.com/repos/jxtech/wechatpy/branches{/branch}","tags_url":"https://api.github.com/repos/jxtech/wechatpy/tags","blobs_url":"https://api.github.com/repos/jxtech/wechatpy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jxtech/wechatpy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jxtech/wechatpy/git/refs{/sha}","trees_url":"https://api.github.com/repos/jxtech/wechatpy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jxtech/wechatpy/statuses/{sha}","languages_url":"https://api.github.com/repos/jxtech/wechatpy/languages","stargazers_url":"https://api.github.com/repos/jxtech/wechatpy/stargazers","contributors_url":"https://api.github.com/repos/jxtech/wechatpy/contributors","subscribers_url":"https://api.github.com/repos/jxtech/wechatpy/subscribers","subscription_url":"https://api.github.com/repos/jxtech/wechatpy/subscription","commits_url":"https://api.github.com/repos/jxtech/wechatpy/commits{/sha}","git_commits_url":"https://api.github.com/repos/jxtech/wechatpy/git/commits{/sha}","comments_url":"https://api.github.com/repos/jxtech/wechatpy/comments{/number}","issue_comment_url":"https://api.github.com/repos/jxtech/wechatpy/issues/comments{/number}","contents_url":"https://api.github.com/repos/jxtech/wechatpy/contents/{+path}","compare_url":"https://api.github.com/repos/jxtech/wechatpy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jxtech/wechatpy/merges","archive_url":"https://api.github.com/repos/jxtech/wechatpy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jxtech/wechatpy/downloads","issues_url":"https://api.github.com/repos/jxtech/wechatpy/issues{/number}","pulls_url":"https://api.github.com/repos/jxtech/wechatpy/pulls{/number}","milestones_url":"https://api.github.com/repos/jxtech/wechatpy/milestones{/number}","notifications_url":"https://api.github.com/repos/jxtech/wechatpy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jxtech/wechatpy/labels{/name}","releases_url":"https://api.github.com/repos/jxtech/wechatpy/releases{/id}","created_at":"2014-09-12T13:03:28Z","updated_at":"2015-09-08T02:54:31Z","pushed_at":"2015-09-14T06:32:46Z","git_url":"git://github.com/jxtech/wechatpy.git","ssh_url":"git@github.com:jxtech/wechatpy.git","clone_url":"https://github.com/jxtech/wechatpy.git","svn_url":"https://github.com/jxtech/wechatpy","homepage":"http://wechatpy.readthedocs.org/zh_CN/latest/","size":1755,"stargazers_count":129,"watchers_count":129,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":45,"mirror_url":null,"open_issues_count":3,"forks":45,"open_issues":3,"watchers":129,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/jxtech/wechatpy/pulls/85"},"html":{"href":"https://github.com/jxtech/wechatpy/pull/85"},"issue":{"href":"https://api.github.com/repos/jxtech/wechatpy/issues/85"},"comments":{"href":"https://api.github.com/repos/jxtech/wechatpy/issues/85/comments"},"review_comments":{"href":"https://api.github.com/repos/jxtech/wechatpy/pulls/85/comments"},"review_comment":{"href":"https://api.github.com/repos/jxtech/wechatpy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/jxtech/wechatpy/pulls/85/commits"},"statuses":{"href":"https://api.github.com/repos/jxtech/wechatpy/statuses/fd9686d5959ddbac98463b171efdf952b087008f"}}}}