淘宝订单截图生成器, 淘宝购买记录生成器,淘宝订单生成器在线制作【python】

简介: 这段代码实现了一个完整的淘宝订单生成器,包含以下功能:1. 生成随机订单号和时间 2

下载地址:https://www.pan38.com/dow/share.php?code=JCnzE 提取密码:2718

这段代码实现了一个完整的淘宝订单生成器,包含以下功能:1. 生成随机订单号和时间 2. 支持添加多个商品 3. 自动计算总金额 4. 生成订单二维码 5. 输出高质量订单图片。使用时需要准备中文字体文件和背景模板。

import random
import datetime
from PIL import Image, ImageDraw, ImageFont
import textwrap
import qrcode
import os

class TaobaoOrderGenerator:
def init(self):
self.font_path = "simhei.ttf"
self.template_path = "template.jpg"
self.output_dir = "output"
self.products = []
self.init_fonts()
self.init_template()

def init_fonts(self):
    self.font_small = ImageFont.truetype(self.font_path, 18)
    self.font_medium = ImageFont.truetype(self.font_path, 22)
    self.font_large = ImageFont.truetype(self.font_path, 28)
    self.font_title = ImageFont.truetype(self.font_path, 36)

def init_template(self):
    if not os.path.exists(self.template_path):
        # 创建空白模板
        self.template = Image.new('RGB', (750, 1334), (245, 245, 245))
        draw = ImageDraw.Draw(self.template)
        # 绘制顶部导航栏
        draw.rectangle([(0, 0), (750, 88)], fill=(255, 255, 255))
        draw.text((30, 40), "订单详情", font=self.font_title, fill=(0, 0, 0))
        # 绘制订单卡片
        draw.rectangle([(20, 100), (730, 400)], fill=(255, 255, 255), outline=(230, 230, 230))
    else:
        self.template = Image.open(self.template_path)

def add_product(self, name, price, count, sku):
    self.products.append({
        "name": name,
        "price": price,
        "count": count,
        "sku": sku
    })

def generate_order_info(self):
    order_no = "".join([str(random.randint(0,9)) for _ in range(18)])
    create_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    total_amount = sum(p["price"]*p["count"] for p in self.products)
    payment_method = random.choice(["支付宝", "微信支付", "花呗分期"])

    return {
        "order_no": order_no,
        "create_time": create_time,
        "total_amount": total_amount,
        "payment_method": payment_method
    }

def generate_qrcode(self, text):
    qr = qrcode.QRCode(
        version=1,
        error_correction=qrcode.constants.ERROR_CORRECT_L,
        box_size=6,
        border=2,
    )
    qr.add_data(text)
    qr.make(fit=True)
    return qr.make_image(fill_color="black", back_color="white")

def draw_product_list(self, draw, y_start):
    y = y_start
    for product in self.products:
        # 商品名称 (自动换行)
        lines = textwrap.wrap(product["name"], width=20)
        for line in lines:
            draw.text((40, y), line, font=self.font_medium, fill=(0, 0, 0))
            y += 30

        # 商品SKU和数量
        sku_text = f"规格: {product['sku']}  数量: {product['count']}"
        draw.text((40, y), sku_text, font=self.font_small, fill=(150, 150, 150))
        y += 30

        # 商品价格
        price_text = f"¥{product['price']:.2f}"
        draw.text((650, y-60), price_text, font=self.font_medium, fill=(255, 80, 0))

        # 分割线
        draw.line([(30, y+10), (720, y+10)], fill=(230, 230, 230), width=1)
        y += 30

    return y

def generate(self):
    if not self.products:
        raise ValueError("请先添加商品")

    order_info = self.generate_order_info()
    img = self.template.copy()
    draw = ImageDraw.Draw(img)

    # 绘制订单基本信息
    draw.text((40, 120), f"订单编号: {order_info['order_no']}", font=self.font_small, fill=(100, 100, 100))
    draw.text((40, 150), f"创建时间: {order_info['create_time']}", font=self.font_small, fill=(100, 100, 100))

    # 绘制商品列表
    product_y = self.draw_product_list(draw, 200)

    # 绘制订单总金额
    total_text = f"实付款: ¥{order_info['total_amount']:.2f}"
    draw.text((40, product_y+30), total_text, font=self.font_large, fill=(255, 80, 0))

    # 绘制支付方式
    pay_text = f"支付方式: {order_info['payment_method']}"
    draw.text((40, product_y+80), pay_text, font=self.font_medium, fill=(100, 100, 100))

    # 添加二维码
    qr_text = f"淘宝订单{order_info['order_no']}"
    qr_img = self.generate_qrcode(qr_text)
    img.paste(qr_img, (550, product_y+50))

    # 保存图片
    if not os.path.exists(self.output_dir):
        os.makedirs(self.output_dir)

    output_path = os.path.join(self.output_dir, f"order_{order_info['order_no']}.jpg")
    img.save(output_path)
    return output_path

使用示例

if name == "main":
generator = TaobaoOrderGenerator()

# 添加商品
generator.add_product("Apple iPhone 15 Pro Max 1TB 原色钛金属", 12999, 1, "1TB|原色钛金属")
generator.add_product("小米14 Ultra 16GB+1TB 黑色 套装版", 7999, 1, "16GB+1TB|黑色|套装")
generator.add_product("华为Mate60 Pro+ 12GB+512GB 丹霞橙", 8999, 1, "12GB+512GB|丹霞橙")

# 生成订单图片
output_path = generator.generate()
print(f"订单已生成: {output_path}")
相关文章
|
4月前
|
JSON 算法 API
Python采集淘宝商品评论API接口及JSON数据返回全程指南
Python采集淘宝商品评论API接口及JSON数据返回全程指南
|
4月前
|
JSON API 数据安全/隐私保护
Python采集淘宝拍立淘按图搜索API接口及JSON数据返回全流程指南
通过以上流程,可实现淘宝拍立淘按图搜索的完整调用链路,并获取结构化的JSON商品数据,支撑电商比价、智能推荐等业务场景。
|
5月前
|
JSON 缓存 开发者
淘宝商品详情接口(item_get)企业级全解析:参数配置、签名机制与 Python 代码实战
本文详解淘宝开放平台taobao.item_get接口对接全流程,涵盖参数配置、MD5签名生成、Python企业级代码实现及高频问题排查,提供可落地的实战方案,助你高效稳定获取商品数据。
|
5月前
|
JSON API 数据安全/隐私保护
Python采集淘宝评论API接口及JSON数据返回全流程指南
Python采集淘宝评论API接口及JSON数据返回全流程指南
缓存 监控 数据挖掘
101 0
|
5月前
|
Web App开发 监控 API
淘宝 item_review 接口深度分析及 Python 实现
淘宝item_review接口用于获取商品用户评价、评分、追评等数据,支持商品口碑分析、用户需求挖掘、竞品对比等场景,是电商数据分析的重要工具。
|
6月前
|
缓存 数据挖掘 数据安全/隐私保护
淘宝 item_search_img 接口深度分析及 Python 实现
淘宝item_get_app接口是淘宝开放平台提供的移动端商品详情数据获取接口,可获取APP专属价格、促销活动及详情页结构,适用于电商导购、比价工具等场景。需通过appkey、appsecret及session认证,返回数据包含商品基础信息、规格参数、详情页内容及促销信息。本文提供Python调用示例及常见问题解决方案。
|
6月前
|
缓存 数据挖掘 API
淘宝 item_get_app 接口深度分析及 Python 实现
淘宝item_get_app接口是淘宝开放平台提供的移动端商品详情数据获取接口,相较PC端更贴近APP展示效果,支持获取APP专属价格、促销活动及详情页结构,适用于电商导购、比价工具、数据分析等场景。接口采用appkey+appsecret+session认证机制,需申请相应权限。本文提供Python调用示例及使用注意事项,帮助开发者高效对接移动端商品数据。
|
6月前
|
缓存 API 网络架构
淘宝item_search_similar - 搜索相似的商品API接口,用python返回数据
淘宝联盟开放平台中,可通过“物料优选接口”(taobao.tbk.dg.optimus.material)实现“搜索相似商品”功能。该接口支持根据商品 ID 获取相似推荐商品,并返回商品信息、价格、优惠等数据,适用于商品推荐、比价等场景。本文提供基于 Python 的实现示例,包含接口调用、数据解析及结果展示。使用时需配置淘宝联盟的 appkey、appsecret 和 adzone_id,并注意接口调用频率限制和使用规范。
|
6月前
|
算法 程序员 API
电商程序猿开发实录:淘宝商品python(2)
本文分享了开发者在对接淘宝商品详情API过程中的真实经历,涵盖权限申请、签名验证、限流控制、数据解析及消息订阅等关键环节,提供了实用的Python代码示例,帮助开发者高效调用API,提升系统稳定性与数据处理能力。