upgrade_wechatminipay_app.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # -*- coding: utf-8 -*-
  2. # !/usr/bin/env python
  3. import datetime
  4. import os
  5. import sys
  6. import bson
  7. PROJECT_ROOT = os.path.join(os.path.abspath(os.path.split(os.path.realpath(__file__))[0] + "/.."), '..')
  8. sys.path.insert(0, PROJECT_ROOT)
  9. from script.base import init_env, get_logger
  10. logger = get_logger(__name__)
  11. init_env(interactive = True)
  12. sslcert_path = 'F:/downloads/WXCertUtil/cert/apiclient_cert.pem'
  13. sslkey_path = 'F:/downloads/WXCertUtil/cert/apiclient_key.pem'
  14. from apps.web.agent.models import Agent
  15. from apps.web.core.models import WechatMiniApp
  16. def is_valid_string(str):
  17. try:
  18. bson._make_c_string(str)
  19. return True
  20. except Exception as e:
  21. return False
  22. agent = Agent.objects(id = '6417d4456f29257125ebf705').first() # type: Agent
  23. app = agent.wechatMiniApp # type: WechatMiniApp
  24. if os.path.isfile(sslcert_path):
  25. with open(sslcert_path) as f:
  26. content = str(f.read())
  27. if is_valid_string(content):
  28. print content
  29. app.sslCert = content
  30. else:
  31. print('ssl cert is not valid.')
  32. else:
  33. print('ssl cert path is not exist.')
  34. if os.path.isfile(sslkey_path):
  35. with open(sslkey_path) as f:
  36. content = str(f.read())
  37. if is_valid_string(content):
  38. print content
  39. app.sslKey = content
  40. else:
  41. print('ssl key is not valid.')
  42. else:
  43. print('ssl key path is not exist.')
  44. agent.save()