| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 | 
							- # -*- encoding: utf-8 -*-
 
- """
 
- @File    : UserSubscriptionController.py
 
- @Time    : 2024/5/21 16:31
 
- @Author  : stephen
 
- @Email   : zhangdongming@asj6.wecom.work
 
- @Software: PyCharm
 
- """
 
- from django.http import QueryDict
 
- from django.views import View
 
- from Model.models import Device_User
 
- from Object.ResponseObject import ResponseObject
 
- from Object.YotpoCoreObject import YotpoCoreObject
 
- from Ansjer.config import LOGGER
 
- class UserSubscriptionControllerView(View):
 
-     def get(self, request, *args, **kwargs):
 
-         request.encoding = 'utf-8'
 
-         operation = kwargs.get('operation')
 
-         return self.validation(request.GET, request, operation)
 
-     def post(self, request, *args, **kwargs):
 
-         request.encoding = 'utf-8'
 
-         operation = kwargs.get('operation')
 
-         return self.validation(request.POST, request, operation)
 
-     def delete(self, request, *args, **kwargs):
 
-         request.encoding = 'utf-8'
 
-         operation = kwargs.get('operation')
 
-         delete = QueryDict(request.body)
 
-         if not delete:
 
-             delete = request.GET
 
-         return self.validation(delete, request, operation)
 
-     def put(self, request, *args, **kwargs):
 
-         request.encoding = 'utf-8'
 
-         operation = kwargs.get('operation')
 
-         put = QueryDict(request.body)
 
-         return self.validation(put, request, operation)
 
-     def validation(self, request_dict, request, operation):
 
-         response = ResponseObject('cn')
 
-         if operation == 'subscription':
 
-             return self.subscription(request_dict, response)
 
-     @staticmethod
 
-     def subscription(request_dict, response):
 
-         user_id = request_dict.get('userId', '')
 
-         if not user_id:
 
-             return response.json(444)
 
-         user_qs = Device_User.objects.filter(userID=user_id).values('username', 'userEmail')
 
-         if not user_qs.exists():
 
-             return response.json(703)
 
-         yotpo = YotpoCoreObject()
 
-         email = '1920098158@qq.com'
 
-         customer = {
 
-             "email": email, "first_name": "test", "last_name": "22",
 
-             'address': {
 
-                 "country_code": 'GB',
 
-             }
 
-         }
 
-         result = yotpo.creat_and_update_customers(customer)
 
-         list_id = 8589406
 
-         subscribers_result = yotpo.create_subscribers(customer, list_id)
 
-         print()
 
-         LOGGER.info(f'创建客户:{result},订阅:{subscribers_result}')
 
 
  |