From d567b804e83a389514214d4ec2c9b5ea86a72e09 Mon Sep 17 00:00:00 2001 From: sunxiaolong Date: Sat, 29 Mar 2025 14:01:29 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9A=82=E5=AD=98=E5=88=86=E6=94=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/misc.xml | 5 ++- .idea/walmart_bind.iml | 2 +- spiders.py | 89 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 93 insertions(+), 3 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 83744f6..ff2bc2c 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,7 +1,10 @@ + + - + \ No newline at end of file diff --git a/.idea/walmart_bind.iml b/.idea/walmart_bind.iml index ff5c231..a24b992 100644 --- a/.idea/walmart_bind.iml +++ b/.idea/walmart_bind.iml @@ -5,7 +5,7 @@ - + diff --git a/spiders.py b/spiders.py index b2945e4..da2da59 100644 --- a/spiders.py +++ b/spiders.py @@ -62,7 +62,7 @@ class WalMartCardSpider: self.order_num = order_num # 请求超时 self.timeout = 3 - self.bind_timeout = 60 + self.bind_timeout = 10 self.user_agent = random.choice(ANDROID_USER_AGENT) # 初始化开始滑块验证时间 self.start_timestamp = int(time.time() * 1000) @@ -84,6 +84,64 @@ class WalMartCardSpider: number = float(number) formatted_number = "{:.2f}".format(number) return formatted_number + def get_walmart_code(self, res): + """ + /* 绑定成功 {"logId":"qZXePbHl","status":true,"error":{"errorcode":1,"message":null,"redirect":null,"validators":null},"data":"59519706"} + * 错误密码 {"logId":"IQwPkfLT","status":false,"error":{"errorcode":19000,"message":"校验密码失败,密码错误次数:1","redirect":null,"validators":null},"data":null} + * 重复绑定 {"logId":"Dj6nJ4OM","status":false,"error":{"errorcode":10131,"message":"该电子卡已被其他用户绑定","redirect":null,"validators":null},"data":null} + * 错误卡号/卡密 {"logId":"hX6Ju6lD","status":false,"error":{"errorcode":19000,"message":"无权操作该卡","redirect":null,"validators":null},"data":null} + * 登录失效 {"logId":"V0Sw4Q2f","status":false,"error":{"errorcode":203,"message":"请先去登录","redirect":null,"validators":null},"data":null} + * 错误密码 {"logId":"Aavc0ch1","status":false,"error":{"errorcode":201,"message":"密码输入有误","redirect":null,"validators":null},"data":null} + * 密码输入错误次数过多 {"logId":"bchMZcyv","status":false,"error":{"errorcode":110136,"message":"密码输入错误次数过多","redirect":null,"validators":null},"data":null} + * 校验密码失败,密码错误次数:2 {"logId":"MDN05jVd","status":false,"error":{"errorcode":19000,"message":"校验密码失败,密码错误次数:2","redirect":null,"validators":null},"data":null} + * {"logId":"tP0TWGY8","status":false,"error":{"errorcode":110224,"message":"您绑卡已超过单日20张限制,请明天再试","redirect":null,"validators":null},"data":null} + * {'logId': 'Ff4eK7Bu', 'status': False, 'error': {'errorcode': 110134, 'message': '错误次数过多,请稍后再试', 'redirect': None, 'validators': None}, 'data': None} + * {'logId': 'LnyEeDcj', 'status': False, 'error': {'errorcode': 2, 'message': None, 'redirect': 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx47085439d65e5fbc&redirect_uri=https%3A%2F%2Fcard.swiftpass.cn%2Fwechat%2Fopen%2Foauth%2F100530000004%3Fredirect%3Dhttps%253A%252F%252Fwalmart-card.swiftpass.cn%252Fcard%252F100530000004%253Fa%253D1%2523bind&response_type=code&scope=snsapi_userinfo&state=bf6a200e39220cf7ce1f9d930e92ce20&component_appid=wxf770fc8d016ff6a8#wechat_redirect', 'validators': None}, 'data': None} + */ + :return: + """ + if res.get("error").get("errorcode") == 1: + self.set_record(f"绑定成功") + return 100 + elif res.get("error").get("errorcode") == 203: + self.set_record(f"ck失效") + return 113 + elif res.get("error").get("errorcode") == 5041: + self.set_record(f"请重新获取ck,开放平台迁移小程序跳转公众号同步unionid") + return 113 + elif res.get("error").get("errorcode") == 10131: + self.set_record(f"该电子卡已被其他用户绑定") + return 104 + elif res.get("error").get("errorcode") == 110400: + self.set_record("操作频繁,请稍后重试") + return 115 + elif res.get("error").get("errorcode") == 19000 and "校验密码失败" in res.get("error").get("message"): + self.set_record(f"校验密码失败") + return 105 + elif res.get("error").get("errorcode") == 19000 and "无权操作该卡" in res.get("error").get("message"): + self.set_record(f"无权操作该卡") + return 105 + elif res.get("error").get("errorcode") == 19000 and "该卡已被绑定" in res.get("error").get("message"): + self.set_record(f"同一张实体卡只允许绑定到一个微信账户或山姆APP礼品卡账户,该卡已被绑定") + return 104 + elif res.get("error").get("errorcode") == 19000 and "重复提交" in res.get("error").get("message"): + self.set_record(f"重复提交") + return 110 + elif res.get("error").get("errorcode") == 201: + self.set_record(f"密码输入有误") + return 105 + elif res.get("error").get("errorcode") == 110136: + self.set_record(f"密码输入错误次数过多") + return 105 + elif res.get("error").get("errorcode") == 110224: + self.set_record(f"您绑卡已超过单日20张限制,请明天再试") + return 116 + elif res.get("error").get("errorcode") == 110134: + self.set_record(f"错误次数过多,请稍后再试") + return 115 + else: + self.set_record(f"存在未知状态") + return 111 def md5_encrypt(self, data): # 创建 MD5 哈希对象 @@ -199,6 +257,35 @@ class WalMartCardSpider: self.log_list.append(f"订单ID: {self.order_num},绑卡异常报错:{str(e)}") return 111 + def walmart_invoice_bind_card(self): + headers = { + "Accept": "application/json, text/javascript, */*; q=0.01", + "Accept-Language": "zh-CN,zh;q=0.9", + "Connection": "keep-alive", + "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", + "Origin": "https://walmart-card.swiftpass.cn", + "Referer": "https://walmart-card.swiftpass.cn/card/100530000004?a=1", + "Sec-Fetch-Dest": "empty", + "Sec-Fetch-Mode": "cors", + "Sec-Fetch-Site": "same-origin", + "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 12_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.2(0x18000239) NetType/4G Language/zh_CN", + "X-Requested-With": "XMLHttpRequest", + "group": "100530000004", + "page-from": "https://walmart-card.swiftpass.cn/card/100530000004?a=1#bind", + "Cookie": self.cookies + } + url = "https://walmart-card.swiftpass.cn/card/member/bind" + data = { + "cardNo": self.card_num, + "cardPwd": self.card_pwd + } + response = requests.post(url, headers=headers, data=data) + res = response.json() + logger.info(f"订单ID: {self.order_num},请求绑卡返回:{res}") + self.remarks = res.get("error", {}).get("message", "") + code = self.get_walmart_code(res) + return code + def get_params(self): headers = { "language": "CN",