Skip to content

Commit 90819ba

Browse files
committed
add test
1 parent f58d772 commit 90819ba

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ venv
1717
weixin/.ropeproject/
1818

1919
# test
20-
test_example.py
20+
# test_example.py
2121
test_settings.py

tests/test_example.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from weixin.client import WeixinAPI
4+
from weixin.oauth2 import OAuth2AuthExchangeError
5+
6+
APP_ID = "your app id"
7+
APP_SECRET = "your secret"
8+
REDIRECT_URI = "http://www.exmple.com"
9+
10+
11+
code = "0418f2c46cd26e4f9eee5bf03320662M"
12+
13+
api = WeixinAPI(appid=APP_ID, app_secret=APP_SECRET, redirect_uri=REDIRECT_URI)
14+
15+
try:
16+
pass
17+
# print api.get_authorize_login_url(scope=("snsapi_login",))
18+
# print api.exchange_code_for_access_token(code=code)
19+
except OAuth2AuthExchangeError as e:
20+
print(e)
21+
22+
23+
auth_info = {
24+
"access_token": "OezXcEiiBSKSxW0eoylIeGXVgVFIUy2pK5I7TVatC5MGtVqTIWjtyV5Pax8ZLiWw-NdEN9dPkEX8Yewsve2AktmzS0gmbvzRKO49l6sxHRfhXg1no5ObdGufYhRIubP2m3FUdv-Cop3t3S_xwMbBWQ",
25+
"refresh_token": "OezXcEiiBSKSxW0eoylIeGXVgVFIUy2pK5I7TVatC5MGtVqTIWjtyV5Pax8ZLiWw44bjXRXdmPsclqGIjWs777H3p00QI9a3hzX265Uq9fPJZttNQApdCRPbySXDfofbjniiwsVJiT7fTv7j5jCAxg",
26+
"openid": u"oV02tuA8Wt6Kk7S0pVydThYvmSJA",
27+
"expires_in": 7200,
28+
"scope": u"snsapi_login",
29+
}
30+
31+
try:
32+
api.exchange_refresh_token_for_access_token(
33+
refresh_token=auth_info["refresh_token"]
34+
)
35+
except OAuth2AuthExchangeError:
36+
pass
37+
api = WeixinAPI(access_token=auth_info["access_token"])
38+
r = api.user(openid=auth_info["openid"])
39+
print(r)
40+
v = api.validate_token(openid=auth_info["openid"])
41+
print(v)

0 commit comments

Comments
 (0)