# -*- coding: utf-8 -*- # !/usr/bin/env python 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) def is_valid_string(str): try: bson._make_c_string(str) return True except Exception as e: return False from apps.web.core.models import AliApp apps = AliApp.objects.all() for app in apps: if app.public_key_path: if os.path.isfile(app.public_key_path): with open(app.public_key_path) as f: content = str(f.read()) if is_valid_string(content): app.alipayPublicKey = content else: print('public_key_path is not exist.') if app.app_private_key_path: if os.path.isfile(app.app_private_key_path): with open(app.app_private_key_path) as f: content = str(f.read()) if is_valid_string(content): app.appPrivateKey = content else: print('app_private_key_path is not exist.') if app.app_publickey_cert_path: if os.path.isfile(app.app_publickey_cert_path): with open(app.app_publickey_cert_path) as f: content = str(f.read()) if is_valid_string(content): app.appPublicKeyCert = content else: print('app_publickey_cert_path is not exist.') if app.publickey_cert_path: if os.path.isfile(app.publickey_cert_path): with open(app.publickey_cert_path) as f: content = str(f.read()) if is_valid_string(content): app.publicKeyCert = content else: print('publickey_cert_path is not exist.') if app.root_cert_path: if os.path.isfile(app.root_cert_path): with open(app.root_cert_path) as f: content = str(f.read()) if is_valid_string(content): app.rootCert = content else: print('root_cert_path is not exist.') app.save()