import requests
import json
import time

def test_douyin_sync():
    # 用户提供的 Cookie
    cookie = "zsgw_business_data=%7B%22uuid%22%3A%2286276357-089d-4844-93c9-bdf1b1e65ee6%22%2C%22platform%22%3A%22pc%22%2C%22source%22%3A%22bd.pcpz.30%22%7D; source=bd.pcpz.30; x-web-secsdk-uid=09481e47-b8cf-4757-81e0-af505a39d0aa; Hm_lvt_b6520b076191ab4b36812da4c90f7a5e=1768049462; HMACCOUNT=7DD25A4453689E0B; passport_csrf_token=77c40059afcea4fc1706178e96bacfaa; passport_csrf_token_default=77c40059afcea4fc1706178e96bacfaa; ttcid=aa179f0f1c514923b6b7d7e853ce373737; tt_scid=mHXrvwiVzL6PDC4sh38F8CI6aSw5GAAubYwmtKSTljHim8X5v3lMpai6cQ8asHkc4337; odin_tt=da3f1dde2546c094ba6a800e6f3117975c0dbd2162b8bd5478ac08aca51302144994ec271048d05b02f5a5c5744e175a2a071a31db8ed24d7eeb5be0bd7d8967; passport_auth_status=ce4c2cd652aff0df69f57a3a27d28284%2C; passport_auth_status_ss=ce4c2cd652aff0df69f57a3a27d28284%2C; uid_tt=73e8562f3280861db5ec3669ea4d06c2; uid_tt_ss=73e8562f3280861db5ec3669ea4d06c2; sid_tt=1d3b3b3c38d3f42f40dc2b28191e5039; sessionid=1d3b3b3c38d3f42f40dc2b28191e5039; sessionid_ss=1d3b3b3c38d3f42f40dc2b28191e5039; is_staff_user=false; PHPSESSID=4e4e0f987481cbd3f8a98dbb1fce5901; PHPSESSID_SS=4e4e0f987481cbd3f8a98dbb1fce5901; ucas_c0=CkEKBTEuMC4wEKOIjriN6ZKxaRjmJiD61rDnqc2DBCiwITCb1oDYuM3aB0DRlonLBkjRysXNBlC_vL6Ekt3t1GdYbhIUwSNcefkX8KzDmEbEw61q_XBD2c4; ucas_c0_ss=CkEKBTEuMC4wEKOIjriN6ZKxaRjmJiD61rDnqc2DBCiwITCb1oDYuM3aB0DRlonLBkjRysXNBlC_vL6Ekt3t1GdYbhIUwSNcefkX8KzDmEbEw61q_XBD2c4; csrf_session_id=3e3be9049498206e97df3a6d41696fe9; s_v_web_id=verify_mk8b0ntk_qptpzrvX_hjTu_4WCq_9zwq_FXtbbba6u272; COMPASS_LUOPAN_DT=session_7593712980437549363; Hm_lpvt_b6520b076191ab4b36812da4c90f7a5e=1768379293; ttwid=1%7CS_Ap3Z1--fOYmwY3vpxK8a2XoNu3eVhAT5kqA5mLGv4%7C1768379293%7C0eeb178b9757c52e917b36207bd87835b0efc4989e8f4c12cd4059bf88c8e885; gfkadpd=4272,23756; ecom_gray_shop_id=156231010; sid_guard=1d3b3b3c38d3f42f40dc2b28191e5039%7C1768379311%7C5184000%7CSun%2C+15-Mar-2026+08%3A28%3A31+GMT; session_tlb_tag=sttt%7C18%7CHTs7PDjT9C9A3CsoGR5QOf_________O-D0GAd06qWfkOVxj-KjALh7_D9vaVt0zdqsst9p2yRQ%3D; sid_ucp_v1=1.0.0-KGQ5OWQyNzI1NmJiYWU2OWJkZWE3YmZjZmJmNmFhMzRiMmJjYjZkMWUKGQib1oDYuM3aBxCvp53LBhiwISAMOAZA9AcaAmhsIiAxZDNiM2IzYzM4ZDNmNDJmNDBkYzJiMjgxOTFlNTAzOQ; ssid_ucp_v1=1.0.0-KGQ5OWQyNzI1NmJiYWU2OWJkZWE3YmZjZmJmNmFhMzRiMmJjYjZkMWUKGQib1oDYuM3aBxCvp53LBhiwISAMOAZA9AcaAmhsIiAxZDNiM2IzYzM4ZDNmNDJmNDBkYzJiMjgxOTFlNTAzOQ; BUYIN_SASID=SID2_7595130123662917930"
    
    url = "https://fxg.jinritemai.com/api/order/searchlist"
    
    headers = {
        "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36",
        "Accept": "application/json, text/plain, */*",
        "Cookie": cookie,
        "Referer": "https://fxg.jinritemai.com/ffa/morder/order/list"
    }
    
    params = {
        "page": "0",
        "pageSize": "10",
        "order_by": "create_time",
        "order": "desc",
        "tab": "all",
        "appid": "1",
        "_bid": "ffa_order",
        "aid": "4272"
    }

    print(f"正在请求: {url}")
    print(f"参数: {json.dumps(params, indent=2, ensure_ascii=False)}")
    
    try:
        response = requests.get(url, headers=headers, params=params, timeout=30)
        print(f"状态码: {response.status_code}")
        
        try:
            data = response.json()
            if data.get("st") == 0 or data.get("code") == 0:
                print("\n✅ 测试成功")
                orders = data.get("data", [])
                if orders:
                    first_order = orders[0]
                    print(f"订单字段: {list(first_order.keys())}")
                    if "sku_order_list" in first_order:
                        print(f"SKU 列表第一个子项字段: {list(first_order['sku_order_list'][0].keys())}")
                        print(f"Product ID 示例: {first_order['sku_order_list'][0].get('product_id')}")
            else:
                print(f"\n❌ 测试失败: {data.get('msg')}")
                
        except json.JSONDecodeError:
            print(f"\n❌ 解析 JSON 失败")
            print(f"原始响应内容: {response.text[:500]}")
            
    except Exception as e:
        print(f"\n❌ 发送请求失败: {str(e)}")

if __name__ == "__main__":
    test_douyin_sync()
