Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into JohnnyZhao-master

Conflicts:
	README.rst
	setup.py
  • Loading branch information
doraemonext committed Mar 21, 2015
2 parents 6e87dc8 + 3df240b commit 52b1df5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
8 changes: 7 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
微信公众平台 Python 开发包
===========================

当前最新版本:v0.5.3
当前最新版本:v0.5.4

非官方微信公众平台 Python 开发包,包括官方接口和非官方接口。

Expand Down Expand Up @@ -59,7 +59,13 @@
ChangeLog
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

v0.5.4
~~~~~~~~~~~~~~~~~~~~~~~~~~~

* 在 grant_token 函数调用之后,顺带着覆盖本地的 access_token (感谢 `JohnnyZhao <https://github.com/JohnnyZhao>`_)

v0.5.3
~~~~~~~~~~~~~~~~~~~~~~~~~~~

* 修复 hashlib.sha1 无法 decode unicode 字符串问题 (感谢 `JohnnyZhao <https://github.com/JohnnyZhao>`_)

Expand Down
14 changes: 7 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
from setuptools import setup, find_packages

setup(
name='wechat-sdk',
version='0.5.3',
keywords=('wechat', 'sdk', 'wechat sdk'),
description=u'微信公众平台Python开发包',
long_description=open("README.rst").read(),
license='BSD License',
name = 'wechat-sdk',
version = '0.5.4',
keywords = ('wechat', 'sdk', 'wechat sdk'),
description = u'微信公众平台Python开发包',
long_description = open("README.rst").read(),
license = 'BSD License',

url='https://github.com/doraemonext/wechat-python-sdk',
author='doraemonext',
Expand All @@ -19,4 +19,4 @@
include_package_data=True,
platforms='any',
install_requires=open("requirements.txt").readlines(),
)
)
14 changes: 9 additions & 5 deletions wechat_sdk/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def response_news(self, articles):
news.add_article(article)
return news.render()

def grant_token(self):
def grant_token(self, override=True):
"""
获取 Access Token
详情请参考 http://mp.weixin.qq.com/wiki/11/0e4b294685f817b95cbed85ba5e82b8f.html
Expand All @@ -258,14 +258,20 @@ def grant_token(self):
"""
self._check_appid_appsecret()

return self._get(
response_json = self._get(
url="https://api.weixin.qq.com/cgi-bin/token",
params={
"grant_type": "client_credential",
"appid": self.__appid,
"secret": self.__appsecret,
}
)
if override:
self.__access_token = response_json['access_token']
self.__access_token_expires_at = int(time.time()) + response_json['expires_in']
return response_json



def grant_jsapi_ticket(self):
"""
Expand Down Expand Up @@ -741,9 +747,7 @@ def access_token(self):
now = time.time()
if self.__access_token_expires_at - now > 60:
return self.__access_token
response_json = self.grant_token()
self.__access_token = response_json['access_token']
self.__access_token_expires_at = int(time.time()) + response_json['expires_in']
self.grant_token()
return self.__access_token

@property
Expand Down

0 comments on commit 52b1df5

Please sign in to comment.