Nav apraksta

views.py 906B

12345678910111213141516171819202122232425262728293031323334
  1. # -*- coding: utf-8 -*-
  2. from django.conf import settings
  3. from django_redis_connector import connector
  4. from pywe_storage import RedisStorage
  5. from pywe_user import get_all_users
  6. from utils.redis.rkeys import SUBSCRIBE_USERINFO_LIST
  7. r1 = connector(settings.REDIS.get('db1', {}))
  8. WECHAT = settings.WECHAT
  9. def fetch_users_func(authorizer_appid, infos):
  10. print authorizer_appid, infos
  11. openids = infos.get('data', {}).get('openid', [])
  12. for openid in openids:
  13. r1.rpushjson(SUBSCRIBE_USERINFO_LIST % authorizer_appid, {
  14. 'brand_id': authorizer_appid,
  15. 'openid': openid
  16. })
  17. def fetch_all_users(brand_id):
  18. wxcfg = WECHAT.get('{}:JSAPI'.format(brand_id), {})
  19. appid = wxcfg.get('appID')
  20. secret = wxcfg.get('appsecret')
  21. get_all_users(appid=appid, secret=secret, storage=RedisStorage(r1), authorizer_appid=brand_id, users_func=fetch_users_func)