Example #1
0
def get_web_auth_access_token(code):
    return json.loads(
        HTTP.get(WX_URL_WEB_AUTH_ACCESS_TOKEN,
                 appid=APP_ID,
                 secret=APP_SECRET,
                 code=code,
                 grant_type='authorization_code'))
Example #2
0
def get_access_token():
    if _access_token[
            'token'] is None or _access_token['timestamp'] + 7000 <= now_sec():
        _access_token['token'] = json.loads(
            HTTP.get(WX_URL_GET_ACCESS_TOKEN,
                     grant_type='client_credential',
                     appid=APP_ID,
                     secret=APP_SECRET))['access_token']
        _access_token['timestamp'] = now_sec()
        logger.info('access_token is: %s', _access_token['token'])
    return _access_token['token']
Example #3
0
def get_jsapi_sign(url):
    if _jsapi_ticket['ticket'] is None or _jsapi_ticket[
            'timestamp'] + 7000 <= now_sec():
        access_token = get_access_token()
        _jsapi_ticket['ticket'] = json.loads(
            HTTP.get(WX_URL_GET_JSAPI_TICKET,
                     access_token=access_token,
                     type='jsapi'))['ticket']
        _jsapi_ticket['timestamp'] = now_sec()

    noncestr = randstr()
    timestamp = now_sec()
    sign = _build_jsapi_sign(_jsapi_ticket['ticket'], noncestr, timestamp, url)
    return {
        'noncestr': noncestr,
        'sign': sign,
        'timestamp': timestamp,
        'appid': APP_ID
    }