brief description of the problem
django
is the backend. The process of getting openid < / openid > and
session_key
from the code sent by wx.login ()
to the Wechat server is too long ( 15s or so), but it is faster to access it directly through the browser.
Development environment
Ubuntu18.04 LTS
, Django2.0.8
, Python3.6.5
related codes
here is a simple program I built to get openid:
class WeChatApi():
def __init__(self, appid, secret):
self.appid = appid
self.secret = secret
def get_openid_and_session_key(self, code):
import time
start = time.perf_counter()
parmas = {
"appid": self.appid,
"secret": self.secret,
"js_code": code,
"grant_type": "authorization_code"
}
url = "https://api.weixin.qq.com/sns/jscode2session"
r = requests.get(url, params=parmas)
openid = r.json().get("openid", "")
end = time.perf_counter()
print("openid:", end-start, "")
return openid
result
result: the program returns normally, but it takes too long, about 15s (has been tested repeatedly). When testing with postman
, it takes about 15 seconds. But paste the interface url directly into the browser and you will get the result quickly.