PUGE 1 maand geleden
bovenliggende
commit
c40d62aca5
2 gewijzigde bestanden met toevoegingen van 28 en 27 verwijderingen
  1. 10 18
      test2.py
  2. 18 9
      天龙八部拍卖行.py

+ 10 - 18
test2.py

@@ -99,7 +99,7 @@ def spapi_request(method, path, query, body=None, access_token=None):
 # ==================== 主程序 ====================
 if __name__ == "__main__":
     print("=" * 60)
-    print("A+ Content 完整流程 - marketplaceId 修正版")
+    print("A+ Content 完整流程 - 响应解析修正版")
     print("=" * 60)
     
     # Step 0
@@ -129,7 +129,7 @@ if __name__ == "__main__":
     content_md5 = base64.b64encode(md5_hash).decode('utf-8')
     print(f"   图片大小: {len(image_binary)} bytes")
     
-    # Step 2: Uploads API 用 marketplaceIds(复数)✅
+    # Step 2
     print("\n📝 Step 2: 创建上传目标...")
     resource = "aplus/2020-11-01/contentDocuments"
     path = f"/uploads/2020-11-01/uploadDestinations/{quote(resource, safe='/')}"
@@ -164,7 +164,7 @@ if __name__ == "__main__":
     # 构建 contentDocument
     content_doc = {
         "name": "Product Image",
-        "contentType": "EMC",
+        "contentType": "EBC",
         "locale": "en-US",
         "contentModuleList": [
             {
@@ -207,19 +207,15 @@ if __name__ == "__main__":
         ]
     }
     
-    # Step 4: 验证 - A+ API 用 marketplaceId(单数)❌ 之前错了
+    # Step 4: 验证
     print("\n📝 Step 4: 验证内容文档...")
     validate_body = {"contentDocument": content_doc}
-    
-    # 关键修正:A+ Content API 用 marketplaceId(单数)
     resp = spapi_request("POST", "/aplus/2020-11-01/contentAsinValidations", f"marketplaceId={MARKETPLACE_ID}", body=validate_body, access_token=token)
     print(f"   验证状态码: {resp.status_code}")
     print(f"   验证响应: {resp.text[:800]}")
     
-    # Step 5: 创建文档 - A+ API 用 marketplaceId(单数)❌ 之前错了
+    # Step 5: 创建文档
     print("\n📝 Step 5: 创建 Content Document...")
-    
-    # 关键修正:A+ Content API 用 marketplaceId(单数)
     resp = spapi_request("POST", "/aplus/2020-11-01/contentDocuments", f"marketplaceId={MARKETPLACE_ID}", body={"contentDocument": content_doc}, access_token=token)
     print(f"   状态码: {resp.status_code}")
     print(f"   响应: {resp.text}")
@@ -228,21 +224,19 @@ if __name__ == "__main__":
         print("\n   ❌ 创建失败")
         exit(1)
     
+    # 关键修正:实际响应是 {"contentReferenceKey":"..."},不是 {"contentReference":{"key":"..."}}
     doc_data = resp.json()
-    content_ref = doc_data.get("contentReference", {})
-    content_key = content_ref.get("key")
+    content_key = doc_data.get("contentReferenceKey")  # ← 修正点
     
     if not content_key:
-        print("   ❌ 响应中缺少 contentReference.key")
+        print("   ❌ 响应中缺少 contentReferenceKey")
         exit(1)
     
     print(f"   ✅ 创建成功,Content Key: {content_key}")
     
-    # Step 6: 绑定 ASIN - A+ API 用 marketplaceId(单数)❌ 之前错了
+    # Step 6: 绑定 ASIN
     print("\n🔗 Step 6: 绑定 ASIN...")
     body = {"asinSet": [ASIN]}
-    
-    # 关键修正:A+ Content API 用 marketplaceId(单数)
     resp = spapi_request("POST", f"/aplus/2020-11-01/contentDocuments/{content_key}/asins", f"marketplaceId={MARKETPLACE_ID}", body=body, access_token=token)
     print(f"   状态码: {resp.status_code}")
     print(f"   响应: {resp.text[:500]}")
@@ -252,10 +246,8 @@ if __name__ == "__main__":
         exit(1)
     print("   ✅ ASIN 绑定成功")
     
-    # Step 7: 提交审核 - A+ API 用 marketplaceId(单数)❌ 之前错了
+    # Step 7: 提交审核
     print("\n📋 Step 7: 提交审核...")
-    
-    # 关键修正:A+ Content API 用 marketplaceId(单数)
     resp = spapi_request("POST", f"/aplus/2020-11-01/contentDocuments/{content_key}/approvalSubmissions", f"marketplaceId={MARKETPLACE_ID}", access_token=token)
     print(f"   状态码: {resp.status_code}")
     print(f"   响应: {resp.text[:500]}")

+ 18 - 9
天龙八部拍卖行.py

@@ -99,20 +99,29 @@ class AuctionBot:
 
     def ocr_price(self, image_bytes):
         try:
-            from PIL import Image
+            from PIL import Image, ImageEnhance
+            import io
             
             img = Image.open(io.BytesIO(image_bytes))
             
-            # 图片预处理:灰度化 + 放大(提升识别率)
-            img = img.convert('L')  # 转灰度
-            # 放大2倍,小字识别更准
+            # 1. 只做灰度(最基本)
+            img = img.convert('L')
+            
+            # 2. 只放大2倍(别用3倍,防止模糊)
             width, height = img.size
             img = img.resize((width * 2, height * 2), Image.Resampling.LANCZOS)
             
-            self.log("正在识别价格(本地Tesseract)...")
+            # 3. 轻微增强对比度(不要二值化!)
+            enhancer = ImageEnhance.Contrast(img)
+            img = enhancer.enhance(1.3)  # 只增强一点点
+
+            # 在识别前加这几行,看看图片到底长啥样
+            # img.save("debug_original.png")  # 保存原图
+            # print(f"图片尺寸: {img.size}")
+            # print(f"图片模式: {img.mode}")
             
-            # 只识别数字和小数点
-            custom_config = r'--psm 8 -c tessedit_char_whitelist=0123456789.'
+            # 4. 用Tesseract最宽容的模式
+            custom_config = r'--psm 6 -c tessedit_char_whitelist=0123456789.'
             text = pytesseract.image_to_string(img, config=custom_config)
             
             text = text.strip()
@@ -370,7 +379,7 @@ class AuctionBot:
         
         self.log(f"识别到价格: {price}, 目标价格: {target_price}")
         
-        if price <= target_price and price > 1:
+        if price <= target_price and price > 0.5:
             self.log(f"价格 {price} <= {target_price},执行购买!")
             
             # 选择购买项
@@ -412,7 +421,7 @@ class AuctionBot:
         
         # 查找窗口
         self.log("查找新天龙八部窗口...")
-        window_list = self.get_hwnds_by_title_contains("新天龙八部")
+        window_list = self.get_hwnds_by_title_contains("0.08.2611")
         
         if not window_list:
             self.log("未找到新天龙八部窗口!")