mopybird 2 سال پیش
والد
کامیت
7267e21183
2فایلهای تغییر یافته به همراه173 افزوده شده و 57 حذف شده
  1. 66 0
      script/utils/mount_withdraw_apps.py
  2. 107 57
      script/utils/upgrade_alipay_app.py

+ 66 - 0
script/utils/mount_withdraw_apps.py

@@ -0,0 +1,66 @@
+# -*- coding: utf-8 -*-
+# !/usr/bin/env python
+
+import os
+import sys
+
+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, WechatPayApp
+from apps.web.agent.models import Agent
+
+agentId = '6417d4456f29257125ebf705'
+
+alipay_withdraw_app_id = '2021003183632080'
+
+new_alipay_pay_app_id = ''  # 新支付宝支付APP
+new_wechat_pay_mchid = ''  # 新微信支付APP
+
+agent = Agent.objects(id = agentId).first()
+print agent.username, agent.nickname, agent.productName, agent.withdraw_source_key()
+
+if new_alipay_pay_app_id:
+    agent.payAppAli = AliApp.objects(appid = new_alipay_pay_app_id).first()
+    agent.save()
+
+if new_wechat_pay_mchid:
+    old_source_key = agent.withdraw_source_key()
+    if not agent.withdrawApps or old_source_key not in agent.withdrawApps:
+        entity = WithdrawEntity()  # type: WithdrawEntity
+
+        entity.wechatWithdrawApp = agent.payAppWechat.fetch()
+
+        agent.withdrawApps = {
+            old_source_key: entity
+        }
+        agent.save()
+
+    agent.payAppWechat = WechatPayApp.objects(mchid = new_wechat_pay_mchid).first()
+    new_source_key = agent.withdraw_source_key()
+
+    entity = WithdrawEntity()  # type: WithdrawEntity
+
+    entity.alipayWithdrawApp = agent.payAppAli.fetch()
+    entity.wechatWithdrawApp = agent.payAppWechat.fetch()
+
+    agent.withdrawApps = {
+        new_source_key: entity
+    }
+    agent.save()
+else:
+    entity = WithdrawEntity()  # type: WithdrawEntity
+
+    entity.alipayWithdrawApp = AliApp.objects(appid = alipay_withdraw_app_id).first()
+    entity.wechatWithdrawApp = agent.payAppWechat.fetch()
+
+    agent.withdrawApps = {
+        agent.withdraw_source_key(): entity
+    }
+    agent.save()

+ 107 - 57
script/utils/upgrade_alipay_app.py

@@ -1,12 +1,12 @@
 # -*- coding: utf-8 -*-
 # -*- coding: utf-8 -*-
 # !/usr/bin/env python
 # !/usr/bin/env python
+
 import datetime
 import datetime
 import os
 import os
 import sys
 import sys
 
 
 import bson
 import bson
 
 
-
 PROJECT_ROOT = os.path.join(os.path.abspath(os.path.split(os.path.realpath(__file__))[0] + "/.."), '..')
 PROJECT_ROOT = os.path.join(os.path.abspath(os.path.split(os.path.realpath(__file__))[0] + "/.."), '..')
 sys.path.insert(0, PROJECT_ROOT)
 sys.path.insert(0, PROJECT_ROOT)
 
 
@@ -16,12 +16,18 @@ logger = get_logger(__name__)
 
 
 init_env(interactive = True)
 init_env(interactive = True)
 
 
-from apps.web.core.models import WechatPayApp, AliApp
+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 = ''
 
 
-# mchid = '1480791292'
-# sslcert_path = 'E:/cert/1480791292_20210528_cert/apiclient_cert.pem'
-# sslkey_path = 'E:/cert/1480791292_20210528_cert/apiclient_key.pem'
 
 
 def is_valid_string(str):
 def is_valid_string(str):
     try:
     try:
@@ -30,62 +36,106 @@ def is_valid_string(str):
     except Exception as e:
     except Exception as e:
         return False
         return False
 
 
-#
-# apps = AliApp.objects().all()
-#
-# for app in apps:  # type: AliApp
-#     print('app id is: {}'.format(str(app.id)))
-#
-#     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('ssl cert is not valid.')
-#
-#     else:
-#         print('ssl cert path is not exist.')
-#
-#     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('ssl key is not valid.')
-#     else:
-#         print('ssl key path is not exist.')
-#
-#     app.dateTimeUpdated = datetime.datetime.now()
-#
-#     print app.appPrivateKey
-#     print app.alipayPublicKey
-#
-#     app.save()
-
-# app = AliApp.objects(id='5fa9010ec3631dd06e35c709').first()
-# if app.signKeyType != 'cert':
-#     print 'not valid'
-# else:
-    # with open('F:\\publish\\alitransfer\\alipayCertPublicKey_RSA2.crt') as f:
-    #     content = str(f.read())
-    #     if is_valid_string(content):
-    #         app.publicKeyCert = content
-    #         app.dateTimeUpdated = datetime.datetime.now()
-    #         app.inhouse = True
-    #         app.save()
-    #     else:
-    #         print 'error'
 
 
-    # with open('F:\\publish\\alitransfer\\appCertPublicKey_2021001191645419.crt') as f:
+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 = str(f.read())
+    #
+    #     content = '-----BEGIN PUBLIC KEY-----\n{}\n-----END PUBLIC KEY-----'.format(content)
     #     if is_valid_string(content):
     #     if is_valid_string(content):
-    #         app.appPublicKeyCert = content
-    #         app.dateTimeUpdated = datetime.datetime.now()
-    #         # app.inhouse = True
-    #         app.save()
+    #         app.alipayPublicKey = content
     #     else:
     #     else:
     #         print 'error'
     #         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)