123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- # -*- 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 AliApp, WithdrawEntity
- from apps.web.agent.models import Agent
- companyName = u'陕西满溢科技有限公司'
- appPrefix = u'陕西满溢科技有限公司'
- certPath = u'/var/backups/{}/支付宝'.format(companyName, appPrefix)
- withdraw_app_id = '2021003183632080'
- pay_app_id = ''
- def is_valid_string(str):
- try:
- bson._make_c_string(str)
- return True
- except Exception as e:
- return False
- def new_withdraw_app(withdraw_app_id, companyName, appPrefix, certPath):
- # app = AliApp.objects(appid = withdraw_app_id).first()
- # return app
- app = AliApp(
- appid = withdraw_app_id,
- companyName = companyName,
- appName = u'{}转账'.format(appPrefix),
- supportWithdraw = False,
- supportWithdrawBank = False,
- signKeyType = 'cert')
- with open(u'{}/提现/alipayCertPublicKey_RSA2.crt'.format(certPath)) as f:
- content = str(f.read())
- if is_valid_string(content):
- app.publicKeyCert = content
- app.dateTimeUpdated = datetime.datetime.now()
- else:
- print 'error'
- with open(u'{}/提现/appCertPublicKey_{}.crt'.format(certPath, withdraw_app_id)) as f:
- content = str(f.read())
- if is_valid_string(content):
- app.appPublicKeyCert = content
- app.dateTimeUpdated = datetime.datetime.now()
- else:
- print 'error'
- with open(u'{}/提现/alipayRootCert.crt'.format(certPath)) as f:
- content = str(f.read())
- if is_valid_string(content):
- app.rootCert = content
- else:
- print 'error'
- with open(u'{}/提现/应用公钥RSA2048.txt'.format(certPath)) as f:
- content = str(f.read())
- content = '-----BEGIN PUBLIC KEY-----\n{}\n-----END PUBLIC KEY-----'.format(content)
- if is_valid_string(content):
- app.alipayPublicKey = content
- else:
- print 'error'
- with open(u'{}/提现/应用私钥RSA2048-敏感数据,请妥善保管.txt'.format(certPath)) as f:
- content = str(f.read())
- content = '-----BEGIN RSA PRIVATE KEY-----\n{}\n-----END RSA PRIVATE KEY-----'.format(content)
- if is_valid_string(content):
- app.appPrivateKey = content
- else:
- print 'error'
- app.dateTimeUpdated = datetime.datetime.now()
- app.save()
- return app
- def new_pay_app(pay_app_id, companyName, appPrefix, certPath):
- app = AliApp(appid = pay_app_id,
- companyName = companyName,
- appName = u'{}支付'.format(appPrefix)) # type: AliApp
- with open(u'{}/支付/支付宝公钥.txt'.format(certPath)) as f:
- content = str(f.read())
- if is_valid_string(content):
- content = '-----BEGIN PUBLIC KEY-----\n{}\n-----END PUBLIC KEY-----'.format(content)
- app.alipayPublicKey = content
- else:
- print 'error'
- # with open(u'{}/支付/应用公钥RSA2048-敏感数据,请妥善保管.txt'.format(certPath)) as f:
- # content = str(f.read())
- #
- # content = '-----BEGIN PUBLIC KEY-----\n{}\n-----END PUBLIC KEY-----'.format(content)
- # if is_valid_string(content):
- # app.alipayPublicKey = content
- # else:
- # print 'error'
- with open(u'{}/支付/应用私钥RSA2048-敏感数据,请妥善保管.txt'.format(certPath)) as f:
- content = str(f.read())
- content = '-----BEGIN RSA PRIVATE KEY-----\n{}\n-----END RSA PRIVATE KEY-----'.format(content)
- if is_valid_string(content):
- app.appPrivateKey = content
- else:
- print 'error'
- app.dateTimeUpdated = datetime.datetime.now()
- app.save()
- return app
- new_withdraw_app(withdraw_app_id, companyName, appPrefix, certPath)
- if pay_app_id:
- new_pay_app(pay_app_id, companyName, appPrefix, certPath)
|