cccb7cfc
tangwang
init
|
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
import requests
from flask import Blueprint, jsonify, request, current_app
from config import Config
# 创建API蓝图
api_bp = Blueprint('api', __name__, url_prefix='/api')
@api_bp.route('/customers/<shop>')
def get_customers(shop):
"""
获取客户列表
"""
if shop not in Config.ACCESS_TOKENS:
return jsonify({'error': 'Shop not authorized'}), 401
token_data = Config.ACCESS_TOKENS[shop]
access_token = token_data.get('access_token')
if not access_token:
return jsonify({'error': 'No access token available'}), 401
try:
# 调用Shoplazza API获取客户列表
api_url = f"https://{shop}/openapi/2022-01/customers"
headers = {
'Access-Token': access_token,
'Content-Type': 'application/json'
}
response = requests.get(api_url, headers=headers)
response.raise_for_status()
return jsonify({
'shop': shop,
'customers': response.json()
})
except Exception as e:
current_app.logger.error(f"获取客户列表失败: {str(e)}")
return jsonify({'error': 'Failed to fetch customers'}), 500
@api_bp.route('/products/<shop>')
def get_products(shop):
"""
获取产品列表
"""
if shop not in Config.ACCESS_TOKENS:
return jsonify({'error': 'Shop not authorized'}), 401
token_data = Config.ACCESS_TOKENS[shop]
access_token = token_data.get('access_token')
if not access_token:
return jsonify({'error': 'No access token available'}), 401
try:
# 调用Shoplazza API获取产品列表
api_url = f"https://{shop}/openapi/2020-01/products"
headers = {
'Access-Token': access_token,
'Content-Type': 'application/json'
}
response = requests.get(api_url, headers=headers)
response.raise_for_status()
return jsonify({
'shop': shop,
'products': response.json()
})
except Exception as e:
current_app.logger.error(f"获取产品列表失败: {str(e)}")
return jsonify({'error': 'Failed to fetch products'}), 500
@api_bp.route('/orders/<shop>')
def get_orders(shop):
"""
获取订单列表
"""
if shop not in Config.ACCESS_TOKENS:
return jsonify({'error': 'Shop not authorized'}), 401
token_data = Config.ACCESS_TOKENS[shop]
access_token = token_data.get('access_token')
if not access_token:
return jsonify({'error': 'No access token available'}), 401
try:
# 调用Shoplazza API获取订单列表
api_url = f"https://{shop}/openapi/2020-01/orders"
headers = {
'Access-Token': access_token,
'Content-Type': 'application/json'
}
response = requests.get(api_url, headers=headers)
response.raise_for_status()
return jsonify({
'shop': shop,
'orders': response.json()
})
except Exception as e:
current_app.logger.error(f"获取订单列表失败: {str(e)}")
return jsonify({'error': 'Failed to fetch orders'}), 500
@api_bp.route('/shop_info/<shop>')
def get_shop_info(shop):
"""
获取商店信息
"""
if shop not in Config.ACCESS_TOKENS:
return jsonify({'error': 'Shop not authorized'}), 401
token_data = Config.ACCESS_TOKENS[shop]
access_token = token_data.get('access_token')
if not access_token:
return jsonify({'error': 'No access token available'}), 401
try:
# 调用Shoplazza API获取商店信息
api_url = f"https://{shop}/openapi/2020-01/shop"
headers = {
'Access-Token': access_token,
'Content-Type': 'application/json'
}
response = requests.get(api_url, headers=headers)
response.raise_for_status()
return jsonify({
'shop': shop,
'shop_info': response.json()
})
except Exception as e:
current_app.logger.error(f"获取商店信息失败: {str(e)}")
return jsonify({'error': 'Failed to fetch shop info'}), 500
|