upgrade_wechatpay_app.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. from apps.web.core.models import WechatPayApp
  13. mchid = '1488451642'
  14. sslcert_path = 'F:/downloads/WXCertUtil/cert/apiclient_cert.pem'
  15. sslkey_path = 'F:/downloads/WXCertUtil/cert/apiclient_key.pem'
  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. app = WechatPayApp.objects(mchid = mchid).first()
  23. print('app id is: {}'.format(str(app.id)))
  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. app.sslCert = content
  29. else:
  30. print('ssl cert is not valid.')
  31. else:
  32. print('ssl cert path is not exist.')
  33. if os.path.isfile(sslkey_path):
  34. with open(sslkey_path) as f:
  35. content = str(f.read())
  36. if is_valid_string(content):
  37. app.sslKey = content
  38. else:
  39. print('ssl key is not valid.')
  40. else:
  41. print('ssl key path is not exist.')
  42. app.dateTimeUpdated = datetime.datetime.now()
  43. print app.sslCert
  44. print app.sslKey
  45. app.save()