1.首先要知道小程序的appid和app_secret
2.通过js_code获取需要的参数
from weixin import WXAPPAPI
appid=''
app_secret=''
code=''
api=WXAPPAPI(appid=appid,app_secret=app_secret)
session_info=api.exchange_code_for_session_key(code)
session_key=session_info['session_key']
openid = session_info['openid']