|
@@ -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')
|