# -*- 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) from apps.web.core.models import WechatPayApp mchid = '1488451642' sslcert_path = 'F:/downloads/WXCertUtil/cert/apiclient_cert.pem' sslkey_path = 'F:/downloads/WXCertUtil/cert/apiclient_key.pem' def is_valid_string(str): try: bson._make_c_string(str) return True except Exception as e: return False app = WechatPayApp.objects(mchid = mchid).first() print('app id is: {}'.format(str(app.id))) if os.path.isfile(sslcert_path): with open(sslcert_path) as f: content = str(f.read()) if is_valid_string(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): app.sslKey = content else: print('ssl key is not valid.') else: print('ssl key path is not exist.') app.dateTimeUpdated = datetime.datetime.now() print app.sslCert print app.sslKey app.save()