# -*- coding: utf-8 -*-
"""
Open Claw 1688运费查询+订单创建+付款一体化工具
功能:实时查运费、精准算利润、自动创建订单、快速付款
适合:电商采购、无货源、跨境、店群批量下单
复制即可运行,新手友好
"""
import requests
# ====================== 配置区(改成你自己的) ======================
API_KEY = "你自己的API_KEY"
API_SECRET = "你自己的API_SECRET"
# 商品ID
ITEM_ID = "702356889901"
# 采购数量
QUANTITY = 10
# 收货地区
AREA = "广东省 深圳市"
# 收货信息(订单创建用)
RECEIVE_NAME = "张先生"
RECEIVE_PHONE = "13800138000"
RECEIVE_ADDRESS = "深圳市南山区科技园"
# ====================================================================
# 接口地址
FEE_API_URL = "https://api-gw.onebound.cn/1688/item_fee" # 运费查询
ORDER_API_URL = "https://api-gw.onebound.cn/1688/order_create" # 创建订单
PAY_API_URL = "https://api-gw.onebound.cn/1688/pay" # 付款
# 1. 查询运费
def get_item_fee(num_iid, area, quantity):
params = {
"key": API_KEY,
"secret": API_SECRET,
"num_iid": num_iid,
"area": area,
"quantity": quantity,
"result_type": "jsonu"
}
try:
resp = requests.get(FEE_API_URL, params=params, timeout=10)
return resp.json()
except Exception as e:
print("运费查询异常:", e)
return {}
# 2. 创建订单
def create_order(num_iid, quantity, receive_info):
params = {
"key": API_KEY,
"secret": API_SECRET,
"num_iid": num_iid,
"quantity": quantity,
"receiver_name": receive_info["name"],
"receiver_phone": receive_info["phone"],
"receiver_address": receive_info["address"],
"result_type": "jsonu"
}
try:
resp = requests.get(ORDER_API_URL, params=params, timeout=15)
return resp.json()
except Exception as e:
print("创建订单异常:", e)
return {}
# 3. 订单付款
def pay_order(order_id):
params = {
"key": API_KEY,
"secret": API_SECRET,
"order_id": order_id,
"result_type": "jsonu"
}
try:
resp = requests.get(PAY_API_URL, params=params, timeout=15)
return resp.json()
except Exception as e:
print("付款异常:", e)
return {}
# 展示成本利润+执行流程
def run_flow():
print("===== Open Claw 1688运费+订单+付款一体化工具 =====")
# 1. 获取运费
fee_data = get_item_fee(ITEM_ID, AREA, QUANTITY)
if not fee_data:
return
fee = fee_data.get("carriage", 0)
price = fee_data.get("price", 0)
is_free = fee_data.get("free_carriage", False)
total_cost = float(price) * QUANTITY + float(fee)
print("\n==================== 运费&成本核算 ====================")
print(f"商品ID:{ITEM_ID}")
print(f"单价:{price} 元")
print(f"采购数量:{QUANTITY} 件")
print(f"运费:{fee} 元({'包邮' if is_free else '不包邮'})")
print(f"总成本:{total_cost:.2f} 元")
print("======================================================\n")
# 2. 创建订单
receive_info = {
"name": RECEIVE_NAME,
"phone": RECEIVE_PHONE,
"address": RECEIVE_ADDRESS
}
order_data = create_order(ITEM_ID, QUANTITY, receive_info)
order_id = order_data.get("order_id", "")
if order_id:
print(f"✅ 订单创建成功,订单号:{order_id}")
else:
print("❌ 订单创建失败")
return
# 3. 快速付款
pay_data = pay_order(order_id)
if pay_data.get("code") == 0:
print(f"✅ 付款成功,订单可发货!")
else:
print(f"❌ 付款失败:{pay_data.get('msg')}")
if __name__ == "__main__":
run_flow()