ck 4 سال پیش
والد
کامیت
571352d512
4فایلهای تغییر یافته به همراه193 افزوده شده و 5 حذف شده
  1. 148 5
      app/api_data/get_order.py
  2. 19 0
      app/api_data/order_hourly.py
  3. 21 0
      model/ComUtils.py
  4. 5 0
      model/DateUtils.py

+ 148 - 5
app/api_data/get_order.py

@@ -1,7 +1,150 @@
-from requests import request
+import requests
+import time
+import hashlib
+import json
+from model.ComUtils import ComUtils
+from model.DataBaseUtils import MysqlUtils
+from model.DateUtils import DateUtils
+db=MysqlUtils()
+class OrderAccount():
 
-def yang_guang():
-    url = 'https://api.yifengaf.cn:443/api/channeldata/data/account/list'
+    def get_account(self,plactform):
+        data = db.quchen_text.getData(f"select text from order_account_text where platform='{plactform}'")
+        new_data = []
+        for i in data:
+            new_data.append(i[0].replace('\n', '').split(","))
+        return new_data
 
-    data={'vip_id':'qucheng17qi'}
-   ''
+    def get_yg_acccount(self):
+        return self.get_account("阳光")
+
+    def get_wd_account(self):
+        return self.get_account("文鼎")
+
+
+class GetOrderData(ComUtils,OrderAccount):
+    def yg(self,start,end):
+        client_id = 10008097
+        token = '2xa1d55tTPBjeEA8Ho'
+        for i in self.get_yg_acccount():
+            stage = i[0]
+            vip_id = i[1]
+            print(vip_id)
+            self.get_yg_vip_channel(stage,vip_id,client_id,token)
+            self.get_yg_data(stage, vip_id, client_id, token,start,end)
+        self.yg_prase()
+
+    def yg_prase(self):
+
+        while True:
+
+            a = db.quchen_text.getOne("select count(1) from yangguang_path where update_time is null")
+            print(a)
+            if a==0:
+                break
+            time.sleep(60)
+
+
+        for i in self.get_yg_acccount():
+            vip_id = i[1]
+            self.parse_yg_data(vip_id)
+
+
+    def get_yg_data(self,stage,vip_id,client_id,token,start,end):
+
+        url = 'https://data.yifengaf.cn:443/channeldata/data/orders/list'
+        nonce=self.get_random_str()
+        timestamp=int(time.time())
+        signaure =self.sha1(str(token) + str(timestamp) + str(client_id) + str(nonce))
+        params = {
+            "client_id": client_id,
+            "token": token,
+            "nonce": nonce,
+            "timestamp": timestamp,
+            "signaure": signaure,
+            "vip_id": vip_id,
+            "start_time":start,   # %Y-%m-%d %H:%i:%s:
+            "end_time":end
+        }
+
+        headers={"Content-Type":"application/json"}
+        r=requests.post(url=url,data=json.dumps(params),headers=headers)
+        print(r.text)
+        task_id = json.loads(r.text).get("data").get("task_id")
+        db.quchen_text.execute(f"replace into yangguang_path(vip_id,task_id,stage,type) values ('{vip_id}','{task_id}','{stage}','order')")
+
+
+    def get_yg_vip_channel(self,stage,vip_id,client_id,token):
+        url='https://data.yifengaf.cn:443/channeldata/data/account/list'
+        nonce = self.get_random_str()
+        timestamp = int(time.time())
+        signaure = self.sha1(str(token) + str(timestamp) + str(client_id) + str(nonce))
+        params = {
+            "client_id": client_id,
+            "token": token,
+            "nonce": nonce,
+            "timestamp": timestamp,
+            "signaure": signaure,
+            "vip_id": vip_id,
+        }
+        headers = {"Content-Type": "application/json"}
+        r=requests.post(url=url,data=json.dumps(params),headers=headers)
+        print(r.text)
+        task_id= json.loads(r.text).get("data").get("task_id")
+        db.quchen_text.execute(f"replace into yangguang_path(vip_id,task_id,stage,type) values ('{vip_id}','{task_id}','{stage}','channel')")
+
+    def parse_yg_data(self,vip_id):
+        url=db.quchen_text.getOne(f"select path from yangguang_path where type='channel' and vip_id={vip_id} ")
+        r= requests.get(url).text
+        channel_di={}
+        a = r.split('}')
+        for i in a[:-1]:
+            if i[-1] != '}':
+                b=json.loads(i + "}", strict=False)
+
+            else:
+                b=json.loads(i, strict=False)
+            channel_di[b["channel_id"]]=b["wx_nickname"]
+        print(channel_di)
+
+        info=db.quchen_text.getData(f"select stage,path from yangguang_path where type='order' and vip_id={vip_id}")
+        stage=info[0][0]
+        path=info[0][1]
+        text=requests.get(path).text.replace('"referral_url":,','')
+
+        insert_data=[]
+        for j in text.split("}")[:-1]:
+            if j[-1] != '}':
+                j=j+'}'
+            try:
+                di=json.loads(j, strict=False)
+            except Exception as e:
+                print(j)
+                print(e)
+
+            if di["state"] == "未完成":
+                continue
+            platform = "阳光"
+            channel_id = di["channel_id"]
+            channel=channel_di[channel_id]
+
+            user_id = di["openid"]
+            order_time = di["create_time"]
+            reg_time = di["user_createtime"]
+            from_novel = di["book_name"]
+            amount = di["money"]
+            order_id = di["transaction_id"]
+            date = DateUtils.str_to_stamp(order_time[:10])
+            insert_data.append((date,stage,platform,channel,channel_id,user_id,order_time,reg_time,amount,from_novel,order_id))
+        # print(insert_data)
+        db.quchen_text.executeMany("replace into `order`(date,stage,platform,channel,channel_id,"
+                               "user_id,order_time,reg_time,amount,from_novel,order_id) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",tuple(insert_data))
+
+
+if __name__ == '__main__':
+    a=GetOrderData()
+    a.yg_prase()
+    # a.parse_yg_data(17382)
+
+    # a.get_yg_data('趣程15期','17382','10008097','2xa1d55tTPBjeEA8Ho','2020-11-27','2020-12-28')
+    # a.get_yg_vip_channel('趣程15期','17382','10008097','2xa1d55tTPBjeEA8Ho')

+ 19 - 0
app/api_data/order_hourly.py

@@ -0,0 +1,19 @@
+from app.api_data.get_order import GetOrderData
+from model.DateUtils import DateUtils
+import time
+du=DateUtils()
+
+"""每小时5分跑"""
+
+if __name__ == '__main__':
+    start=du.get_n_days(0)+ ' 00:00:00'
+    end=du.get_n_hours_ago(0)
+    print(start,end)
+
+    a=GetOrderData()
+    a.yg(start,end)
+
+
+
+
+

+ 21 - 0
model/ComUtils.py

@@ -0,0 +1,21 @@
+import hashlib
+import random
+
+class ComUtils:
+    def md5(self,s):
+        md5 = hashlib.md5()
+        md5.update(s.encode("utf-8"))
+        return md5.hexdigest()
+
+    def sha1(self,s):
+        sha1 = hashlib.sha1()
+        sha1.update(s.encode("utf-8"))
+        return sha1.hexdigest()
+
+    def get_random_str(self,num=5):
+        H = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
+        salt = ''
+        for i in range(num):
+            salt += random.choice(H)
+        return salt
+

+ 5 - 0
model/DateUtils.py

@@ -264,6 +264,11 @@ class DateUtils:
         x = r.replace(day=num)
         return x if flag else x.strftime("%Y-%m-%d")
 
+    @staticmethod
+    def str_to_stamp(str):
+        return int(time.mktime(time.strptime(str,'%Y-%m-%d')))
+
+
 if __name__ == "__main__":
     ut = DateUtils()
     end = ut.now.strftime('%Y-%m') + '-01 00:00:00'