peng 10 hónapja
szülő
commit
acd8a495e7

+ 5 - 2
AdminController/ServeManagementController.py

@@ -169,10 +169,13 @@ class serveManagement(View):
         if not order_id:
             return response.json(444)
         order_qs = Order_Model.objects.filter(orderID=order_id)
-        order_qs = order_qs.filter(~Q(agreement_id='')).values("agreement_id")
+        order_qs = order_qs.filter(~Q(agreement_id='')).values("agreement_id", "app_type")
         if not order_qs.exists():
             return response.json(800)
-        paypalrestsdk.configure(PAYPAL_CRD)
+        if order_qs[0]['app_type'] == 1:
+            paypalrestsdk.configure(PAYPAL_CRD['Zosi'])
+        elif order_qs[0]['app_type'] == 2:
+            paypalrestsdk.configure(PAYPAL_CRD['Vsees'])
         agreement_id = order_qs[0]['agreement_id']
         try:
             now_time = int(time.time())

+ 12 - 8
Ansjer/cn_config/config_test.py

@@ -21,11 +21,11 @@ ACCESS_KEY_ID = 'AKIA2E67UIMD45Y3HL53'
 SECRET_ACCESS_KEY = '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'
 
 # 存储桶
-PUSH_BUCKET = 'foreignpush'                                # 推送存储桶
-PUSH_INACCURATE_BUCKET = 'push-inaccurate'          # 推送不准确存储桶
-AVATAR_BUCKET = 'avatar-us'                         # 头像存储桶
-LOG_BUCKET = 'ansjer-statres'                       # 日志存储桶
-PUSH_CLOUD_PHOTO = 'push-cloud-photo'               # 推送云相册存储桶
+PUSH_BUCKET = 'foreignpush'  # 推送存储桶
+PUSH_INACCURATE_BUCKET = 'push-inaccurate'  # 推送不准确存储桶
+AVATAR_BUCKET = 'avatar-us'  # 头像存储桶
+LOG_BUCKET = 'ansjer-statres'  # 日志存储桶
+PUSH_CLOUD_PHOTO = 'push-cloud-photo'  # 推送云相册存储桶
 
 # redis节点
 SERVER_HOST = '127.0.0.1'
@@ -49,10 +49,14 @@ OAUTH_REFRESH_TOKEN_SECRET = 'test_r+jbgnw%@1%zy^=@dn62%'
 
 # PayPal
 PAYPAL_CRD = {
-    "mode": "sandbox",  # sandbox or live
-    "client_id": "AVLoQVq3xHZ6FrF4mxHwlCPgVBAw4Fw5RtMkuxmYd23SkUTIY643n2g3KdK-Al8wV05I28lza5uoQbAA",
-    "client_secret": "EO8kRc8yioDk0i2Qq-QMcVFfwkmyMJorTvBSLDTnxDJJ_wb9VoM_0jkUY9iEng2Flp1ze8wQOGpH5nB2"
+    "Zosi": {"mode": "sandbox",  # sandbox or live
+             "client_id": "AVLoQVq3xHZ6FrF4mxHwlCPgVBAw4Fw5RtMkuxmYd23SkUTIY643n2g3KdK-Al8wV05I28lza5uoQbAA",
+             "client_secret": "EO8kRc8yioDk0i2Qq-QMcVFfwkmyMJorTvBSLDTnxDJJ_wb9VoM_0jkUY9iEng2Flp1ze8wQOGpH5nB2"},
+    "Vsees": {"mode": "sandbox",  # sandbox or live
+              "client_id": "AYjKR4XQ4sNBvOPjLXkfxb_WKBCX79N0pUgA9DyKw2hOPx_B3lZ60gaelK1Fmh_zny7XfWrD4U0sxBW_",
+              "client_secret": "EEN5x9VMRcAbDTW2afGqaG2BXigQUliJG4st2Q73vuj0Uq76ciTW5XyOHnM2AWYQEKnRacxJtlJ711F6"}
 }
+
 PAYPAL_WEB_HOOK_ID = '6TS30758D98835230'
 PAYPAL_WEB_HOOK_ID_TWO = '2BH56575UJ9324151'
 

+ 25 - 12
Controller/CloudStorage.py

@@ -244,10 +244,10 @@ class CloudStorageView(View):
                                "517J385BNUGP3CPP111A"] and CONFIG_INFO == CONFIG_TEST:
                     store_qs = store_qs.exclude(id=88)
                 elif uid not in ["VXJ267WU5NZ1S89H111A", "18SM4J9DYWB2AEG1111A",
-                               "517J385BNUGP3CPP111A"] and CONFIG_INFO == CONFIG_US:
+                                 "517J385BNUGP3CPP111A"] and CONFIG_INFO == CONFIG_US:
                     store_qs = store_qs.exclude(id=34)
                 elif uid not in ["VXJ267WU5NZ1S89H111A", "18SM4J9DYWB2AEG1111A",
-                               "517J385BNUGP3CPP111A"] and CONFIG_INFO == CONFIG_EUR:
+                                 "517J385BNUGP3CPP111A"] and CONFIG_INFO == CONFIG_EUR:
                     store_qs = store_qs.exclude(id=34)
             else:
                 is_ai = uid_set_qs[0]['is_ai']
@@ -1004,7 +1004,13 @@ class CloudStorageView(View):
                     red_url = red_url.replace('fail.html', 'en_fail.html')
                 return HttpResponseRedirect(red_url)
 
-            paypalrestsdk.configure(PAYPAL_CRD)
+            order_list = order_qs.values("UID", "channel", "commodity_code", "rank", "isSelectDiscounts",
+                                         "userID__userID", "userID__username", "coupon_id", "app_type")
+            app_type = order_list[0]['app_type']
+            if app_type == 1:
+                paypalrestsdk.configure(PAYPAL_CRD['Zosi'])
+            elif app_type == 2:
+                paypalrestsdk.configure(PAYPAL_CRD['Vsees'])
             payment = paypalrestsdk.Payment.find(payment_id)
 
             logger.info("payment------")
@@ -1018,9 +1024,6 @@ class CloudStorageView(View):
                     red_url = red_url.replace('fail.html', 'en_fail.html')
                 redis_obj.del_data(key=order_id + 'do_notify')
                 return HttpResponseRedirect(red_url)
-
-            order_list = order_qs.values("UID", "channel", "commodity_code", "rank", "isSelectDiscounts",
-                                         "userID__userID", "userID__username", "coupon_id")
             userid = order_list[0]['userID__userID']
             username = order_list[0]['userID__username']
             uid = order_list[0]['UID']
@@ -1484,6 +1487,7 @@ class CloudStorageView(View):
         is_select_discount = request_dict.get('is_select_discount', 0)
         coupon_id = request_dict.get('coupon_id', 0)
         lang = request_dict.get('lang', 'en')
+        app_type = request_dict.get('app_type', 1)
         if not all([uid, channel, pay_type, rank]):
             return response.json(444)
         pay_type = int(pay_type)
@@ -1550,10 +1554,11 @@ class CloudStorageView(View):
             # 订阅周期扣款
             if store_qs[0]['cycle_config_id']:
                 # 查询是否有订阅过,活跃状态
-                check_has_subscribe = Paypal.checkSubscriptions(user_id, uid, rank)
+                check_has_subscribe = Paypal.checkSubscriptions(user_id, uid, rank, app_type)
                 if not check_has_subscribe:
                     return response.json(10050)
-                sub_info = Paypal.subscriptions(store_info=store_qs[0], lang=lang, orderID=order_id, price=price)
+                sub_info = Paypal.subscriptions(store_info=store_qs[0], lang=lang, orderID=order_id, price=price,
+                                                app_type=app_type)
                 if not sub_info:
                     return response.json(10048)
                 Order_Model.objects.create(orderID=order_id, UID=uid, channel=channel, userID_id=user_id,
@@ -1572,8 +1577,12 @@ class CloudStorageView(View):
                 call_clc_url = call_clc_url.replace('fail.html', 'en_fail.html')
             call_sub_url = "{}cloudstorage/dopaypalcallback?orderID={}&lang={}".format(SERVER_DOMAIN_SSL, order_id,
                                                                                        lang)
-
-            paypalrestsdk.configure(PAYPAL_CRD)
+            if app_type == 1:
+                paypalrestsdk.configure(PAYPAL_CRD['Zosi'])
+            elif app_type == 2:
+                paypalrestsdk.configure(PAYPAL_CRD['Vsees'])
+            else:
+                return response.json(444)
             payment = paypalrestsdk.Payment({
                 "intent": "sale",
                 "payer": {"payment_method": "paypal"},
@@ -2405,7 +2414,7 @@ class CloudStorageView(View):
         try:
             order_qs = Order_Model.objects.filter(orderID=order_id) \
                 .values('status', 'payType', 'price', 'refunded_amount',
-                        'currency', 'paymentID', 'trade_no')
+                        'currency', 'paymentID', 'trade_no', "app_type")
             if not order_qs.exists():
                 return response.json(173)
 
@@ -2434,8 +2443,12 @@ class CloudStorageView(View):
             if pay_type == 1:  # PayPal
                 payment_id = order_qs[0]['paymentID']  # PayPal PAYMENT_ID
                 trade_no = order_qs[0]['trade_no']
+                app_type = order_qs[0]['app_type']
                 sale_id = ''
-                paypalrestsdk.configure(PAYPAL_CRD)
+                if app_type == 1:
+                    paypalrestsdk.configure(PAYPAL_CRD['Zosi'])
+                elif app_type == 2:
+                    paypalrestsdk.configure(PAYPAL_CRD['Vsees'])
                 if payment_id:
                     payment = paypalrestsdk.Payment.find(payment_id)
                     related_resources = payment['transactions'][0]['related_resources']

+ 13 - 7
Controller/CloudVod.py

@@ -405,17 +405,21 @@ class CloudVodView(View):
         if not paymentId or not PayerID or not orderID:
             red_url = "{SERVER_DOMAIN}cloudVod/payError".format(SERVER_DOMAIN=SERVER_DOMAIN)
             return HttpResponseRedirect(red_url)
-        paypalrestsdk.configure(PAYPAL_CRD)
+        order_qs = Order_Model.objects.filter(orderID=orderID)
+        nowTime = int(time.time())
+        order_qs.update(status=1, updTime=nowTime)
+        order_list = order_qs.values("UID", "rank_id", "channel", "app_type")
+        app_type = order_list[0]['app_type']
+        if app_type == 1:
+            paypalrestsdk.configure(PAYPAL_CRD['Zosi'])
+        elif app_type == 2:
+            paypalrestsdk.configure(PAYPAL_CRD['Vsees'])
         # ID of the payment. This ID is provided when creating payment.
         payment = paypalrestsdk.Payment.find(paymentId)
         payres = payment.execute({"payer_id": PayerID})
         if not payres:
             red_url = "{SERVER_DOMAIN}cloudVod/payError".format(SERVER_DOMAIN=SERVER_DOMAIN)
             return HttpResponseRedirect(red_url)
-        order_qs = Order_Model.objects.filter(orderID=orderID)
-        nowTime = int(time.time())
-        order_qs.update(status=1, updTime=nowTime)
-        order_list = order_qs.values("UID", "rank_id", "channel")
         rank_id = order_list[0]['rank_id']
         UID = order_list[0]['UID']
         channel = order_list[0]['channel']
@@ -726,8 +730,10 @@ class CloudVodView(View):
         refund_amount = float(refund_amount)
         if order.price < refund_amount:
             return response.json(801)
-
-        paypalrestsdk.configure(PAYPAL_CRD)
+        if order.app_type == 1:
+            paypalrestsdk.configure(PAYPAL_CRD['Zosi'])
+        elif order.app_type == 2:
+            paypalrestsdk.configure(PAYPAL_CRD['Vsees'])
         payment = paypalrestsdk.Payment.find(order.trade_no)
         transactions = payment['transactions']
         transaction = transactions[0]

+ 15 - 6
Controller/Cron/CronTaskController.py

@@ -1918,10 +1918,13 @@ class CronComparedDataView(View):
             start_date = datetime.datetime(start_date.year, start_date.month, start_date.day)
             end_date = start_date + datetime.timedelta(days=1)
         try:
-            paypal_api = paypalrestsdk.Api(PAYPAL_CRD)
+            zosi_paypal_api = paypalrestsdk.Api(PAYPAL_CRD['Zosi'])
+            vsees_paypal_api = paypalrestsdk.Api(PAYPAL_CRD['Vsees'])
             paypal_url = 'v1/reporting/transactions?start_date={}-{}-{}T08:00:00-0800&end_date={}-{}-{}T08:00:00-0800&fields=all&page_size=500&page=1&transaction_status=S'.format(
                 start_date.year, start_date.month, start_date.day, end_date.year, end_date.month, end_date.day)
-            order_list = paypal_api.get(paypal_url)
+            zosi_order_list = zosi_paypal_api.get(paypal_url)
+            vsees_order_list = vsees_paypal_api.get(paypal_url)
+            order_list = zosi_order_list['transaction_details'] + vsees_order_list['transaction_details']
             # data = (
             #     ('start_date', '{}-{}-{}T08:00:00-0800'.format(start_date.year, start_date.month, start_date.day)),
             #     ('end_date', '{}-{}-{}T08:00:00-0800'.format(end_date.year, end_date.month, end_date.day)),
@@ -1932,7 +1935,7 @@ class CronComparedDataView(View):
             # )
             # order_list = PayPalService(PAYPAL_CRD['client_id'], PAYPAL_CRD['client_secret']).get_transactions(data)
             thread = threading.Thread(target=CronComparedDataView.thread_compared_paypal_order,
-                                      args=(order_list['transaction_details'], end_date))
+                                      args=(order_list, end_date))
             thread.start()  # 启动线程
             return response.json(0)
         except Exception as e:
@@ -2141,7 +2144,7 @@ class CronComparedDataView(View):
                                                                                      'desc', 'payType',
                                                                                      'price', 'status',
                                                                                      'refunded_amount', 'addTime',
-                                                                                     'updTime')
+                                                                                     'updTime', 'app_type')
             if CONFIG_INFO == CONFIG_EUR:
                 return response.json(0, list(order_qs))
             thread = threading.Thread(target=CronComparedDataView.thread_compared_ansjer_order,
@@ -2172,7 +2175,8 @@ class CronComparedDataView(View):
             total = 0
             all_order_list = order_list + eur_order_list
             count = len(all_order_list)
-            paypal_api = paypalrestsdk.Api(PAYPAL_CRD)
+            zosi_paypal_api = paypalrestsdk.Api(PAYPAL_CRD['Zosi'])
+            vsees_paypal_api = paypalrestsdk.Api(PAYPAL_CRD['Vsees'])
             for index, order in enumerate(all_order_list):
                 total += float(order['price'])
                 if not order['trade_no']:
@@ -2184,7 +2188,12 @@ class CronComparedDataView(View):
                 paypal_url = 'v1/reporting/transactions?start_date={}-{}-{}T00:00:00-0000&end_date={}-{}-{}T00:00:00-0000&transaction_id={}&fields=all&page_size=100&page=1'.format(
                     begin_date.year, begin_date.month, begin_date.day, end_date.year, end_date.month, end_date.day,
                     order['trade_no'])
-                paypal_order_list = paypal_api.get(paypal_url)
+                if order['app_type'] == 1:
+                    paypal_order_list = zosi_paypal_api.get(paypal_url)
+                elif order['app_type'] == 2:
+                    paypal_order_list = vsees_paypal_api.get(paypal_url)
+                else:
+                    continue
                 if not paypal_order_list['transaction_details']:
                     more_order_list.append(order['orderID'])
             total = round(total, 2)

+ 43 - 14
Controller/PaymentCycle.py

@@ -25,18 +25,21 @@ PAY_LOGGER = logging.getLogger('pay')
 # 周期扣款相关
 class Paypal:
     # 检查是否有重复订阅
-    def checkSubscriptions(userID, uid, rank):
-        hasOrder = Order_Model.objects.filter(UID=uid)
+    def checkSubscriptions(userID, uid, rank, app_type):
+        hasOrder = Order_Model.objects.filter(UID=uid, app_type=app_type)
         hasOrder = hasOrder.filter(~Q(agreement_id='')).values('agreement_id', 'orderID').order_by('-addTime')[0:1]
         if not hasOrder.exists():
             return True
-        paypalrestsdk.configure(PAYPAL_CRD)
+        if app_type == 1:
+            paypalrestsdk.configure(PAYPAL_CRD['Zosi'])
+        elif app_type == 2:
+            paypalrestsdk.configure(PAYPAL_CRD['Vsees'])
         billing_agreement = paypalrestsdk.BillingAgreement.find(hasOrder[0]['agreement_id'])
         if billing_agreement.state == 'Active':
             return False
         return True
 
-    def subscriptions(store_info, lang, orderID, price):
+    def subscriptions(store_info, lang, orderID, price, app_type):
         logger = logging.getLogger('pay')
         cycle_config = PayCycleConfigModel.objects.filter(id=store_info['cycle_config_id']).values()
         if not cycle_config:
@@ -46,8 +49,8 @@ class Paypal:
         cal_url = "{SERVER_DOMAIN_SSL}web/paid2/fail.html".format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL)
         if lang != 'cn':
             cal_url = "{SERVER_DOMAIN_SSL}web/paid2/en_fail.html".format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL)
-        return_url = "{SERVER_DOMAIN_SSL}payCycle/paypalCycleReturn?lang={lang}". \
-            format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL, lang=lang)
+        return_url = "{SERVER_DOMAIN_SSL}payCycle/paypalCycleReturn?lang={lang}&app_type={app_type}". \
+            format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL, lang=lang, app_type=app_type)
         # call_sub_url = "http://binbin.uicp.vip/cloudstorage/dopaypalcallback?orderID={orderID}".format(
         # SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL, orderID=orderID)
         # exit(price)
@@ -90,7 +93,10 @@ class Paypal:
             ],
             "type": "INFINITE",
         }
-        paypalrestsdk.configure(PAYPAL_CRD)
+        if app_type == 1:
+            paypalrestsdk.configure(PAYPAL_CRD['Zosi'])
+        elif app_type == 2:
+            paypalrestsdk.configure(PAYPAL_CRD['Vsees'])
         billing_plan = paypalrestsdk.BillingPlan(BillingPlan)
         if billing_plan.create():
             billing_plan.activate()  # 激活
@@ -199,11 +205,15 @@ class PaypalCycleNotify(View):
     def do_paypal_cycle_return(self, request_dict, response):
         lang = request_dict.get('lang', 'en')
         token = request_dict.get('token', None)
+        app_type = request_dict.get('app_type', 1)
 
         logger = logging.getLogger('pay')
         logger.info('--------进入paypay首次订阅付款回调--------')
         logger.info(request_dict)
-        paypalrestsdk.configure(PAYPAL_CRD)
+        if app_type == 1:
+            paypalrestsdk.configure(PAYPAL_CRD['Zosi'])
+        elif app_type == 2:
+            paypalrestsdk.configure(PAYPAL_CRD['Vsees'])
         billing_agreement = paypalrestsdk.BillingAgreement()
         billing_agreement_response = billing_agreement.execute(token)
         if billing_agreement_response.error:
@@ -395,7 +405,15 @@ class PaypalCycleNotify(View):
                 PAY_LOGGER.info('----event_type异常:{}----'.format(event_type))
 
             if resource_type == 'sale' and paypal_body.get('state') == 'completed':
-                paypalrestsdk.configure(PAYPAL_CRD)
+                temp_order = Order_Model.objects.filter(trade_no=paypal_transaction_id).values('app_type')
+                if not temp_order.exists():
+                    PAY_LOGGER.info('PayPal周期扣款失败---根据trade_no查询订单数据不存在')
+                    return HttpResponse('Fail', status=500)
+                app_type = temp_order[0]['app_type']
+                if app_type == 1:
+                    paypalrestsdk.configure(PAYPAL_CRD['Zosi'])
+                elif app_type == 2:
+                    paypalrestsdk.configure(PAYPAL_CRD['Vsees'])
                 response = paypalrestsdk.WebhookEvent.verify(
                     transmission_id, transmission_time, PAYPAL_WEB_HOOK_ID, json_agreement_str, cert_url,
                     transmission_sig, auth_algo)
@@ -663,7 +681,8 @@ class PaypalCycleNotify(View):
         # 不确定用户地区信息,默认美洲
         if not country_qs.exists():
             if CONFIG_INFO == CONFIG_EUR:
-                PAY_LOGGER.info('PayPal周期扣款失败---不确定地区的用户请求欧洲服,uid:{},country_id:{}'.format(uid, country_id))
+                PAY_LOGGER.info(
+                    'PayPal周期扣款失败---不确定地区的用户请求欧洲服,uid:{},country_id:{}'.format(uid, country_id))
                 return False
             else:
                 return True
@@ -699,7 +718,14 @@ class PaypalCycleNotify(View):
             amount = paypal_body.get('amount')
 
             # self.get_plan_desc('P-4CG284532S612303METMEINY')
-            paypalrestsdk.configure(PAYPAL_CRD)
+            temp_order = Order_Model.objects.filter(trade_no=paypal_transaction_id).values('app_type')
+            if not temp_order.exists():
+                return HttpResponse('Fail', status=500)
+            app_type = temp_order[0]['app_type']
+            if app_type == 1:
+                paypalrestsdk.configure(PAYPAL_CRD['Zosi'])
+            elif app_type == 2:
+                paypalrestsdk.configure(PAYPAL_CRD['Vseees'])
             response = paypalrestsdk.WebhookEvent.verify(
                 transmission_id, transmission_time, PAYPAL_WEB_HOOK_ID_TWO, json_agreement_str, cert_url,
                 transmission_sig, auth_algo)
@@ -820,11 +846,14 @@ class payCycle(View):
     def do_cancel_pay_cycle(self, request_dict, userID, response):
         orderID = request_dict.get('orderID', 'None')
         orderObject = Order_Model.objects.filter(orderID=orderID)
-        orderObject = orderObject.filter(~Q(agreement_id='')).values("agreement_id")
+        orderObject = orderObject.filter(~Q(agreement_id='')).values("agreement_id", "app_type")
         if not orderObject.exists():
             return response.json(800)
-
-        paypalrestsdk.configure(PAYPAL_CRD)
+        app_type = orderObject[0]['app_type']
+        if app_type == 1:
+            paypalrestsdk.configure(PAYPAL_CRD['Zosi'])
+        elif app_type == 2:
+            paypalrestsdk.configure(PAYPAL_CRD['Vsees'])
         BILLING_AGREEMENT_ID = orderObject[0]['agreement_id']
         try:
             billing_agreement = paypalrestsdk.BillingAgreement.find(BILLING_AGREEMENT_ID)

+ 3 - 2
Controller/TestApi.py

@@ -1177,7 +1177,8 @@ class testView(View):
                 ('page_size', '20'),
                 ('page', '1'),
             )
-            result = PayPalService(PAYPAL_CRD['client_id'], PAYPAL_CRD['client_secret']).get_transactions(params)
+            result = PayPalService(PAYPAL_CRD['Vsees']['client_id'],
+                                   PAYPAL_CRD['Vsees']['client_secret']).get_transactions(params)
             return response.json(0, result)
         except Exception as e:
             LOGGER.info('UnicomManageControllerView.transfer_device_package, errLine:{}, errMsg:{}'.format(
@@ -1406,7 +1407,7 @@ class testView(View):
         try:
             language_id = int(request_dict.get('language_id'))
             now_time = int(time.time())
-            country_language_qs = CountryLanguageModel.objects.filter(language_id=1).\
+            country_language_qs = CountryLanguageModel.objects.filter(language_id=1). \
                 order_by('-id').values('country_id')
             country_list = []
             with open('国家.txt', 'r') as file: