No Description

market_code.py 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # -*- coding: utf-8 -*-
  2. from django.conf import settings
  3. from pywe_marketcode import applycodedownload
  4. from pywe_storage import RedisStorage
  5. from marketcode.models import MarketCodeInfo
  6. from utils.redis.connect import r
  7. WECHAT = settings.WECHAT
  8. def marketcodedownload(application_id, code_start, code_end, isv_application_id='', iv=''):
  9. wxcfg = WECHAT.get('JSAPI', {})
  10. appid = wxcfg.get('appID')
  11. secret = wxcfg.get('appsecret')
  12. codes = applycodedownload(application_id=application_id, code_start=code_start, code_end=code_end, appid=appid, secret=secret, token=None, storage=RedisStorage(r), iv=iv)
  13. lattice, code, code_index, code_url = ''
  14. for idx, item in enumerate(codes):
  15. if idx % 4 == 0:
  16. lattice = item
  17. if idx % 4 == 1:
  18. code = item
  19. if idx % 4 == 2:
  20. code_index = item
  21. if idx % 4 == 3:
  22. code_url = item
  23. MarketCodeInfo.objects.create(
  24. isv_application_id=isv_application_id,
  25. application_id=application_id,
  26. lattice=lattice,
  27. code=code,
  28. code_index=code_index,
  29. code_url=code_url
  30. )