|
|
@@ -190,36 +190,136 @@ class OfpayHelper:
|
|
|
url = flow.request.url;
|
|
|
path = flow.request.path;
|
|
|
print("###[OfpayHelper]path=%s"%path);
|
|
|
- if path.startswith('/h5/union/api/interactiveIGoChoose/orderList'):
|
|
|
+ if path.startswith('/h5/union/api/interactiveIGoChoose/indexConfigRebuild'):
|
|
|
+ self.handle_activitylist(flow);
|
|
|
+ elif path.startswith('/h5/union/api/interactiveIGoChoose/orderList'):
|
|
|
self.handle_orderlist(flow);
|
|
|
|
|
|
- def handle_orderlist(self, flow: http.HTTPFlow):
|
|
|
- ctx.log.info('###handle_orderlist###');
|
|
|
+ def get_jwt_token_data(self, flow: http.HTTPFlow):
|
|
|
request = flow.request;
|
|
|
- response = flow.response;
|
|
|
- cookies = dict(request.cookies) # 转换cookies格式为dict
|
|
|
- if 'unionToken_interactiveIGoChoose' not in cookies:
|
|
|
- return;
|
|
|
- account = None;
|
|
|
+ headers = dict(request.headers);
|
|
|
+ jwt_data = None;
|
|
|
try:
|
|
|
- jwt_str = cookies['unionToken_interactiveIGoChoose'];
|
|
|
- # payload = jwt.decode(jwt_str, '', algorithms=['HS256'], verify=False, options={'verify_signature':False});
|
|
|
- # info_str = payload.get('customerInfo');
|
|
|
- # 不依赖库,简单方法解析
|
|
|
- jwt_data = Utils.parse_jwt(jwt_str);
|
|
|
- info_str = None;
|
|
|
- if jwt_data:
|
|
|
- payload = jwt_data['payload'];
|
|
|
- info_str = payload['customerInfo'];
|
|
|
- if info_str:
|
|
|
- customer_info = json.loads(info_str);
|
|
|
- account = customer_info['phone'];
|
|
|
+ jwt_str = None;
|
|
|
+ if 'Authorization' in headers:
|
|
|
+ jwt_str = headers['Authorization'];
|
|
|
+ else:
|
|
|
+ cookies = dict(request.cookies);
|
|
|
+ if 'unionToken_interactiveIGoChoose' in cookies:
|
|
|
+ jwt_str = cookies['unionToken_interactiveIGoChoose'];
|
|
|
+ if jwt_str:
|
|
|
+ jwt_data = Utils.parse_jwt(jwt_str);
|
|
|
except jwt.PyJWTError as e:
|
|
|
print('jwt token解析失败');
|
|
|
else:
|
|
|
pass
|
|
|
finally:
|
|
|
pass
|
|
|
+ if jwt_data:
|
|
|
+ payload = jwt_data['payload'];
|
|
|
+ if 'customerInfo' in payload:
|
|
|
+ info_str = payload['customerInfo'];
|
|
|
+ customer_info = json.loads(info_str);
|
|
|
+ payload['customerInfo'] = customer_info;
|
|
|
+ return jwt_data;
|
|
|
+
|
|
|
+ def handle_activitylist(self, flow: http.HTTPFlow):
|
|
|
+ ctx.log.info('###handle_activitylist###');
|
|
|
+ request = flow.request;
|
|
|
+ response = flow.response;
|
|
|
+
|
|
|
+ jwt_data = self.get_jwt_token_data(flow);
|
|
|
+ if not jwt_data:
|
|
|
+ return;
|
|
|
+ payload = jwt_data['payload'];
|
|
|
+ if 'customerInfo' not in payload:
|
|
|
+ return;
|
|
|
+ account = payload['customerInfo']['phone'];
|
|
|
+ if not account:
|
|
|
+ return;
|
|
|
+ if account != '13430389115':
|
|
|
+ return;
|
|
|
+ rsp_params = json.loads(response.get_text());
|
|
|
+ if rsp_params['code'] != 'success':
|
|
|
+ return;
|
|
|
+ rsp_data = rsp_params['data'];
|
|
|
+ sql_activity_query = f'''
|
|
|
+ CALL UpdateElifeActivities(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s);
|
|
|
+ ''';
|
|
|
+ sql_activity_params = [];
|
|
|
+
|
|
|
+ sql_award_query = f'''
|
|
|
+ CALL UpdateElifeActivityAwards(%s, %s, %s, %s, %s, %s, %s, %s, %d, %f, %s, %s, %s, %d, %d, %d, %d, %d, %s, %s, %s, %d, %d, %s, %s);
|
|
|
+ ''';
|
|
|
+ sql_award_params = [];
|
|
|
+ activity_list = rsp_params['data'];
|
|
|
+ for activity_info in activity_list:
|
|
|
+ sql_activity_params.append(('1',
|
|
|
+ activity_info['activityId'], activity_info['activityAlias'], activity_info['outActivityCode'],
|
|
|
+ activity_info['activityTitle'], activity_info['activityState'], activity_info['activityIcon'],
|
|
|
+ activity_info['activityLink'], activity_info['activityBanner'], activity_info['subLoginType'],
|
|
|
+ activity_info['subActivityId'] if 'subActivityId' in activity_info else '', activity_info['activityDesc']));
|
|
|
+ award_list = activity_info['awardList'];
|
|
|
+ for award_info in award_list:
|
|
|
+ # print(award_info)
|
|
|
+ sql_award_params.append((
|
|
|
+ award_info['awardId'], award_info['prizeName'], award_info['activityId'],
|
|
|
+ award_info['prizeId'], award_info['prizeDesc'], award_info['prizeBannerUrl'],
|
|
|
+ award_info['prizeDescUrl'], award_info['imgUrl'], int(award_info['stockNum']),
|
|
|
+ float(award_info['price']), award_info['categoryType'], award_info['goodsScene'],
|
|
|
+ award_info['rechargeType'], int(award_info['useStock']), int(award_info['remainStock']),
|
|
|
+ int(award_info['cycleStock']), int(award_info['cycleRemainStock']), int(award_info['orderNum']),
|
|
|
+ award_info['payFlag'], award_info['thirdInfo'], award_info['awardType'],
|
|
|
+ int(award_info['firstSignAward']), int(award_info['renewSignAward']), award_info['prizeAlias'] if 'prizeAlias' in award_info else '',
|
|
|
+ award_info['parentAwardId'] if 'parentAwardId' in award_info else ''));
|
|
|
+ try:
|
|
|
+ self.check_mysql_connect();
|
|
|
+ cursor = self.db_conn.cursor();
|
|
|
+ print(sql_award_params[0]);
|
|
|
+
|
|
|
+ cursor.executemany(sql_activity_query, sql_activity_params);
|
|
|
+ cursor.executemany(sql_award_query, sql_award_params);
|
|
|
+
|
|
|
+ self.db_conn.commit();
|
|
|
+ cursor.close();
|
|
|
+ except pymysql.OperationalError as e:
|
|
|
+ print(e);
|
|
|
+
|
|
|
+ def handle_orderlist(self, flow: http.HTTPFlow):
|
|
|
+ ctx.log.info('###handle_orderlist###');
|
|
|
+ request = flow.request;
|
|
|
+ response = flow.response;
|
|
|
+
|
|
|
+ cookies = dict(request.cookies) # 转换cookies格式为dict
|
|
|
+
|
|
|
+ # if 'unionToken_interactiveIGoChoose' not in cookies:
|
|
|
+ # return;
|
|
|
+ # account = None;
|
|
|
+ # try:
|
|
|
+ # jwt_str = cookies['unionToken_interactiveIGoChoose'];
|
|
|
+ # # payload = jwt.decode(jwt_str, '', algorithms=['HS256'], verify=False, options={'verify_signature':False});
|
|
|
+ # # info_str = payload.get('customerInfo');
|
|
|
+ # # 不依赖库,简单方法解析
|
|
|
+ # jwt_data = Utils.parse_jwt(jwt_str);
|
|
|
+ # if jwt_data:
|
|
|
+ # payload = jwt_data['payload'];
|
|
|
+ # info_str = payload['customerInfo'];
|
|
|
+ # customer_info = json.loads(info_str);
|
|
|
+ # account = customer_info['phone'];
|
|
|
+ # except jwt.PyJWTError as e:
|
|
|
+ # print('jwt token解析失败');
|
|
|
+ # else:
|
|
|
+ # pass
|
|
|
+ # finally:
|
|
|
+ # pass
|
|
|
+
|
|
|
+ jwt_data = self.get_jwt_token_data(flow);
|
|
|
+ if not jwt_data:
|
|
|
+ return;
|
|
|
+ payload = jwt_data['payload'];
|
|
|
+ if 'customerInfo' not in payload:
|
|
|
+ return;
|
|
|
+ account = payload['customerInfo']['phone'];
|
|
|
if not account:
|
|
|
return;
|
|
|
headers = dict(request.headers);
|
|
|
@@ -258,4 +358,7 @@ class OfpayHelper:
|
|
|
self.db_conn.commit();
|
|
|
cursor.close();
|
|
|
except pymysql.OperationalError as e:
|
|
|
- print(e);
|
|
|
+ print(e);
|
|
|
+
|
|
|
+
|
|
|
+sql_activity_params = [('1', 'A923605206137307136', '活动1-首单', 'eCoffee', 'e起喝咖啡(首次)', '2', '', '', 'https://mstatic.ofpay.com/marketing/upload/e4fb2100868347c0bc39cb9ac08ad485.png', 'subChoose', 'A923613706510925824', ''), ('1', 'A923620157585358848', '活动1-首单', 'eTea', 'e起下午茶(首次)', '2', '', '', 'https://mstatic.ofpay.com/marketing/upload/0c9b274ba4ff4f2e81d18fb7db2b15b1.png', 'subChoose', 'A923622289227120640', ''), ('1', 'A1190335340494454784', '活动1-首单', 'eFood', 'e起享美 味', '2', '', '', '', 'subChoose', 'A1190350499677995008', ''), ('1', 'A1190947451528544256', '活动1-首单', 'eSupermarket', 'e起逛超市', '2', '', '', '', 'choose', '', ''), ('1', 'A1190954239447531520', '活动1-首单', 'eTravel', 'e起乐出行', '2', '', '', '', 'subChoose', 'A1190956349283106816', ''), ('1', 'A923939556410261504', '活动1-首单', 'eMovie', 'e起追 热剧', '2', '', '', 'https://mstatic.ofpay.com/marketing/upload/7254fbe94dd041d5b8c63ba4a9a5505e.png', 'choose', '', ''), ('1', 'A923939562252926976', '活动1-首单', 'eBicycle', 'e起骑单车(首次)', '2', '', '', 'https://mstatic.ofpay.com/marketing/upload/c8550391b1324e32b7b537d35523196c.png', 'choose', '', ''), ('1', 'A1091037106664636416', '活动1-首单', 'eOffice', 'e起长知识', '2', '', '', 'https://mstatic.ofpay.com/marketing/upload/1eed1bbb39044cf992a7cdb13d771538.png', 'choose', '', '')]
|