コード例 #1
0
ファイル: wx_utils.py プロジェクト: husonchen/ProjectWxAdmin
def get_encrypt_xml(reply_xml, nonce):
    APPID = getSetting('admin', 'app_id')
    encodingAESKey = getSetting('admin', 'encodingAESKey')
    encrypt = WXBizMsgCrypt(TOKEN, encodingAESKey, APPID)
    ret_encrypt, encrypt_xml = encrypt.EncryptMsg(reply_xml, nonce)
    if ret_encrypt == 0:
        return encrypt_xml
    else:
        return ''
コード例 #2
0
ファイル: wx_utils.py プロジェクト: husonchen/ProjectWxAdmin
def get_pre_auth_code():
    component_access_token = getSetting('admin', 'component_access_token')
    appid = getSetting('admin', 'app_id')
    target = r'https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?component_access_token=%s' % component_access_token
    data = {'component_appid': appid}
    payload = json.dumps(data)
    s = http.request('POST', target, body=payload)
    res = json.loads(s.data)
    if 'pre_auth_code' not in res:
        logger.error('get_pre_auth_code return : %s' % s.data)
    return res['pre_auth_code']
コード例 #3
0
ファイル: wx_utils.py プロジェクト: husonchen/ProjectWxAdmin
def get_decrypt_xml(encrypt_xml, msg_signature, timestamp, nonce):
    APPID = getSetting('admin', 'app_id')
    encodingAESKey = getSetting('admin', 'encodingAESKey')
    if 'ToUserName' not in encrypt_xml:
        encrypt_xml = encrypt_xml.replace('AppId', 'ToUserName')
    decrypt = WXBizMsgCrypt(TOKEN, encodingAESKey, APPID)
    ret_decrypt, decrypt_xml = decrypt.DecryptMsg(encrypt_xml, msg_signature,
                                                  timestamp, nonce)
    if ret_decrypt == 0:
        return decrypt_xml
    else:
        return ''
コード例 #4
0
ファイル: wx_utils.py プロジェクト: husonchen/ProjectWxAdmin
def get_basic_info(auth_appid_value):
    component_access_token = getSetting('admin', 'component_access_token')
    appid = getSetting('admin', 'app_id')
    target = r'https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info?component_access_token=%s' % component_access_token
    data = {'component_appid': appid, 'authorizer_appid': auth_appid_value}
    payload = json.dumps(data)
    s = http.request('POST', target, body=payload)
    res = json.loads(s.data)
    if 'authorizer_info' not in res:
        logger.error('get_basic_info return : %s' % s.data)
    res = res['authorizer_info']
    return res
コード例 #5
0
ファイル: wx_utils.py プロジェクト: husonchen/ProjectWxAdmin
def flush_authorization_token(authorizer_appid, authorizer_refresh_token):
    component_access_token = getSetting('admin', 'component_access_token')
    appid = getSetting('admin', 'app_id')
    target = r'https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token?component_access_token=%s' % component_access_token
    data = {
        'component_appid': appid,
        'authorizer_appid': authorizer_appid,
        'authorizer_refresh_token': authorizer_refresh_token
    }
    payload = json.dumps(data)
    s = http.request('POST', target, body=payload)
    res = json.loads(s.data)
    if 'authorizer_access_token' not in res:
        logger.error('flush_authorization_token return : %s' % s.data)
    return res['authorizer_access_token'], res['authorizer_refresh_token']
コード例 #6
0
    def handle(self, *args, **options):
        client = mc.Client(['127.0.0.1:11211'])
        self.stdout.write('start flush')
        appId = getSetting('admin', 'app_id')
        appSecret = getSetting('admin', 'app_secret')
        component_verify_ticket = getSetting('admin',
                                             'component_verify_ticket')
        postUrl = (
            "https://api.weixin.qq.com/cgi-bin/component/api_component_token")
        data = '''{
        "component_appid":"%s" ,
        "component_appsecret": "%s", 
        "component_verify_ticket": "%s" 
        }''' % (appId, appSecret, component_verify_ticket)

        resp = urllib.urlopen(postUrl, data).read()
        urlResp = json.loads(resp)
        logger.info('flush cron: urlResp %s' % urlResp)
        if 'component_access_token' not in urlResp:
            print resp
        accessToken = urlResp['component_access_token']
        saveSetting('admin', 'component_access_token', accessToken)
        client.delete('xunhui__admin_config_admin_component_access_token')
コード例 #7
0
ファイル: wx_utils.py プロジェクト: husonchen/ProjectWxAdmin
def wx_auth_page(pre_auth_code, redirect_uri):
    appid = getSetting('admin', 'app_id')
    url = 'https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid=%s&pre_auth_code=%s' \
          '&redirect_uri=%s' %(appid,pre_auth_code,redirect_uri)
    return HttpResponseRedirect(url)