瀏覽代碼

上传文件至 'dgp/tests'

cary 4 年之前
父節點
當前提交
e2399c459f
共有 1 個文件被更改,包括 115 次插入39 次删除
  1. 115 39
      dgp/tests/get_order_dairly_wending.py

+ 115 - 39
dgp/tests/get_order_dairly_wending.py

@@ -75,7 +75,13 @@ def get_wending_order(st,et):
     total_order_list = ()
     start_exec_seconds = date_util.getCurrentSecondTime()
     account_list = get_wending_account_list()
-
+    '''
+    ## 2个账户测试看看
+    account_list = [ 
+      ['68442881','RFygHhX16LEYYe8i','1014108','趣程20期','qucheng20qi@163.com'],
+      ['77257999','86nPtJdYLe1k81gE','1021116','趣程21期','qucheng21qi@163.com']
+    ]
+    '''
     executor = ProcessPoolExecutor(max_workers=5)
 
     futures = []
@@ -94,7 +100,65 @@ def get_wending_order(st,et):
     return total_order_list
 
 
-## 获取json对象
+## 获取文鼎账号的站点list
+def get_wd_account_siteid_list(account):
+  url = 'https://bi.reading.163.com/dist-api/siteList'
+
+  consumerkey = account[0] 
+  secretkey = account[1] 
+  stage = account[3]
+  timestamp = int(time.time()*1000)
+  
+  judge = True
+  while judge:
+    siteid_params = {
+        "consumerkey":consumerkey,
+        'secretkey':secretkey,
+        'timestamp':timestamp,
+    }
+    sorted_data = sorted(siteid_params.items(),reverse = False) 
+    s=""
+    for k,v in sorted_data:
+        s = s+str(k)+"="+str(v)
+    sign = md5(s).lower()
+    siteid_params['sign'] = sign
+
+    consumerkey = siteid_params['consumerkey']
+    timestamp = siteid_params['timestamp']
+    #secretkey = siteid_params['secretkey'] 
+    parameter = 'consumerkey='+str(consumerkey)+'&timestamp='+str(timestamp)+'&sign='+str(sign)
+    get_url = url+"?"+parameter
+    response_result_json = requests.get(url=get_url).json()
+    '''
+    站点json返回格式如下
+    {'code': 200, 'data': [
+        {'mpId': 1023064, 'mpName': '流云书楼', 'siteList': [{'id': 1023064, 'domain': 'lysl1.reading.163.com', 'name': '流云书楼', 'fileKey': 'Pld5F38EmbmeD1pV'}]}, 
+        {'mpId': 1025058, 'mpName': '骁骑文选', 'siteList': [{'id': 1025058, 'domain': 'xqwx.reading.163.com', 'name': '骁骑文选', 'fileKey': 'ODUXIVk3Y5vKM59d'}]}
+    ], 'message': 'success'}
+    '''
+    code = response_result_json['code']
+    if code != 200:
+      print( stage,'文鼎siteid站点接口异常:',response_result_json,'传入参数', siteid_params,"请求url",get_url)
+      break
+
+    #print('返回结果:',response_result_json)
+    id_key_list = response_result_json['data']
+
+    mpid_list = []
+    try:
+      for id_key_val in id_key_list:
+          mpid = dict(id_key_val)["mpId"]
+          mpid_list.append(mpid)
+    except Exception as e:
+        print(stage,'站点查询返回结果:',response_result_json)
+
+    judge = False
+
+  print(stage,'文鼎siteid列表:',mpid_list)
+  return mpid_list
+
+
+## 根据url,传入params获取json对象
 def get_wending_json_object(url,params):
   params['timestamp'] = int(time.time()*1000)
 
@@ -126,26 +190,33 @@ def get_wending_json_object(url,params):
   return response_result_json
 
 
-## 具体文鼎任务task
+## 具体文鼎任务
 def get_wending_order_task(st,et,account):
-    order_list = ()
-    url = 'https://bi.reading.163.com/dist-api/rechargeList'
-    ## 接口鉴权参数
-    consumerkey = account[0] 
-    secretkey = account[1]
-    ## 订单参数
-    siteid = account[2]
-    pageSize = 1000
-    page = 1
-    paystatus = 1
-    ## 期数自定义保存到记录中
-    stage = account[3]
-
-    while True:
-      if st >= et:
-          break
-      starttime = getSelfDateStr(st,'%Y%m%d%H%M')
-      endtime = getSelfDateStr(et,'%Y%m%d%H%M') 
+  order_list = ()
+  url = 'https://bi.reading.163.com/dist-api/rechargeList'
+  ## 接口鉴权参数
+  consumerkey = account[0] 
+  secretkey = account[1]
+  ## 订单参数
+  siteid = account[2]
+  pageSize = 1000 
+  page = 1
+  paystatus = 1 
+  ## 需要保存到订单的标签期数
+  stage = account[3]
+
+  jud = True
+  while jud:
+    if st >= et:
+        break
+    starttime = getSelfDateStr(st,'%Y%m%d%H%M')
+    endtime = getSelfDateStr(et,'%Y%m%d%H%M') 
+
+    siteid_list = get_wd_account_siteid_list(account)
+    if len(siteid_list) == 0:
+      break
+
+    for siteid in siteid_list:
       params = {
         'consumerkey': consumerkey,
         'secretkey':secretkey,
@@ -183,32 +254,34 @@ def get_wending_order_task(st,et,account):
           , 'updateTime': 1601565288057, 'payStatus': 1
         }]
         '''
+        ## 获取该页数据
         for x in order_item_list:
             y={}
             y['date'] = (int(x['payTime']//1000)+ 8 * 3600) // 86400 * 86400 - 8 * 3600    ## 网易的是13位时间戳
             y['platform'] = '文鼎'
-            y['channel'] = x['wx_mpName']
-            y['channel_id'] = x['wx_originalId']
-            y['from_novel'] = x['bookTitle']
-            y['user_id'] = x['userId']
-            y['stage'] = stage
-            createTime = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(x['createTime']//1000))
-            y['order_time']= createTime
+            y['channel'] = x['wx_mpName']            ## 公众号名称
+            y['channel_id'] = x['wx_originalId']     ## 公众号id
+            y['from_novel'] = x['bookTitle']         ## 小说名称
+            y['user_id'] = x['userId']               ## 付费用户uid 
+            y['stage'] = stage                       ## 期数
+            createTime = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(x['createTime']//1000))  ## 时间戳 》struct_time 》标准时间
+            y['order_time']= createTime              ## 订单生成时间
             y['amount']=x['money']/100               ## 原数据单位:分 
-            uid_reg_time = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(x['userRegisterTime']//1000))
-            y['reg_time']= uid_reg_time
-            y['order_id']= x['rechargeUuid']
+            uid_reg_time = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(x['userRegisterTime']//1000))     ## 13位时间戳 》标准时间
+            y['reg_time']= uid_reg_time              ## 用户注册时间
+            y['order_id']= x['ewTradeId']            ## 订单id
 
             y = sorted(y.items(), key=lambda item:item[0])
             y = dict(y)
             y = tuple(y.values())
             order_list = order_list+((y),)
 
-      if totalPag==params['page']:
-        break
+        if totalPag==params['page']:
+          break
 
-    print(f"文鼎数据日期-{starttime}到{endtime}-期数-{stage}-获取数据-{len(order_list)}条,例如》{order_list[0:1]}")
-    return order_list     
+    jud = False
+  print(f"文鼎数据日期-{starttime}到{endtime}-期数-{stage}-获取数据-{len(order_list)}条,例如》{order_list[0:1]}")
+  return order_list     
 
 
 def batch_save_order(data):
@@ -242,7 +315,6 @@ def start_order_job():
     print('订单同步执行时间(秒):', date_util.getCurrentSecondTime() - start_exec_seconds)
 
 
-start_order_job()
 '''
 start_job_time = '2020-11-06 10:04:00'
 if __name__ == '__main__':
@@ -252,12 +324,16 @@ if __name__ == '__main__':
     #线上是24h执行一次
     scheduler.start()     
 '''
-
 '''
+if __name__ == '__main__':
+  start_order_job()
+
+
 account_list = [ 
-  ['68442881','RFygHhX16LEYYe8i','1014108','趣程20期','qucheng20qi@163.com'],
+  ['11790115','VjVIGRX5YgJCGQjC','1023064','趣程15期','qucheng15qi@163.com'],
+  ['50465587','E5D1qzGtmhbx5EAS','1025020','趣程24期','qucheng24qi@163.com'],
   ['77257999','86nPtJdYLe1k81gE','1021116','趣程21期','qucheng21qi@163.com']
 ]
 for account in account_list:
-  get_wending_order_task(st=int(1601481600),et=int(1601568000),account=account)
+  get_wending_order_task(st=int(1604505600),et=int(1604592000),account=account)
 '''