123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- # -*- coding: utf-8 -*-
- # !/usr/bin/env python
- import datetime
- import os
- import sys
- import bson
- PROJECT_ROOT = os.path.join(os.path.abspath(os.path.split(os.path.realpath(__file__))[0] + "/.."), '..')
- sys.path.insert(0, PROJECT_ROOT)
- from script.base import init_env, get_logger
- logger = get_logger(__name__)
- init_env(interactive = True)
- sslcert_path = 'F:/downloads/WXCertUtil/cert/apiclient_cert.pem'
- sslkey_path = 'F:/downloads/WXCertUtil/cert/apiclient_key.pem'
- from apps.web.agent.models import Agent
- from apps.web.core.models import WechatMiniApp
- def is_valid_string(str):
- try:
- bson._make_c_string(str)
- return True
- except Exception as e:
- return False
- agent = Agent.objects(id = '6417d4456f29257125ebf705').first() # type: Agent
- app = agent.wechatMiniApp # type: WechatMiniApp
- if os.path.isfile(sslcert_path):
- with open(sslcert_path) as f:
- content = str(f.read())
- if is_valid_string(content):
- print content
- app.sslCert = content
- else:
- print('ssl cert is not valid.')
- else:
- print('ssl cert path is not exist.')
- if os.path.isfile(sslkey_path):
- with open(sslkey_path) as f:
- content = str(f.read())
- if is_valid_string(content):
- print content
- app.sslKey = content
- else:
- print('ssl key is not valid.')
- else:
- print('ssl key path is not exist.')
- agent.save()
|