lrj
2 天以前 9f8395fab13ca4b230a0f7d62636e209745c91d4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/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()