#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ 测试微信登录GraphQL接口 """ import requests import json def test_wechat_login(): """测试微信登录接口""" # GraphQL端点 url = "http://localhost:8080/api/graphql" # 测试查询 query = """ mutation { wxLogin(input: { code: "test_code_123" loginIp: "127.0.0.1" deviceInfo: "Test Device" phoneAuthorized: false }) { token userInfo { userId name userType } isNewUser loginRecordId } } """ # 请求数据 data = { "query": query } # 发送请求 headers = { "Content-Type": "application/json" } try: print("=== 测试微信登录接口 ===") print(f"请求URL: {url}") print(f"请求数据: {json.dumps(data, indent=2, ensure_ascii=False)}") response = requests.post(url, json=data, headers=headers) print(f"响应状态码: {response.status_code}") print(f"响应内容: {json.dumps(response.json(), indent=2, ensure_ascii=False)}") if response.status_code == 200: result = response.json() if "errors" in result: print("❌ GraphQL错误:") for error in result["errors"]: print(f" - {error.get('message', '未知错误')}") if "extensions" in error: print(f" 分类: {error['extensions'].get('classification', '未知')}") else: print("✅ 请求成功") else: print(f"❌ HTTP错误: {response.status_code}") except Exception as e: print(f"❌ 请求异常: {e}") if __name__ == "__main__": test_wechat_login()