{"id":1084974,"date":"2025-01-08T13:11:57","date_gmt":"2025-01-08T05:11:57","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1084974.html"},"modified":"2025-01-08T13:12:00","modified_gmt":"2025-01-08T05:12:00","slug":"%e5%a6%82%e4%bd%95%e7%bb%99python%e7%a8%8b%e5%ba%8f%e8%ae%be%e7%bd%ae%e6%bf%80%e6%b4%bb%e7%a0%81-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1084974.html","title":{"rendered":"\u5982\u4f55\u7ed9python\u7a0b\u5e8f\u8bbe\u7f6e\u6fc0\u6d3b\u7801"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24195103\/b38c3717-08ff-423e-b029-fb5ed16e585b.webp\" alt=\"\u5982\u4f55\u7ed9python\u7a0b\u5e8f\u8bbe\u7f6e\u6fc0\u6d3b\u7801\" \/><\/p>\n<p><p> <strong>\u7ed9Python\u7a0b\u5e8f\u8bbe\u7f6e\u6fc0\u6d3b\u7801\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff1a\u901a\u8fc7\u547d\u4ee4\u884c\u8f93\u5165\u3001\u901a\u8fc7GUI\u8f93\u5165\u3001\u901a\u8fc7\u914d\u7f6e\u6587\u4ef6\u8f93\u5165<\/strong>\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u901a\u8fc7\u547d\u4ee4\u884c\u8f93\u5165\u6fc0\u6d3b\u7801\u6765\u4fdd\u62a4Python\u7a0b\u5e8f\u7684\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><p>\u5728\u73b0\u4ee3\u8f6f\u4ef6\u5e94\u7528\u4e2d\uff0c\u4fdd\u62a4\u8f6f\u4ef6\u7684\u77e5\u8bc6\u4ea7\u6743\u548c\u786e\u4fdd\u5408\u6cd5\u4f7f\u7528\u975e\u5e38\u91cd\u8981\u3002\u6fc0\u6d3b\u7801\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u65b9\u6cd5\uff0c\u7528\u4e8e\u786e\u4fdd\u53ea\u6709\u6388\u6743\u7528\u6237\u624d\u80fd\u4f7f\u7528\u7279\u5b9a\u7684\u8f6f\u4ef6\u3002\u4e0b\u9762\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u7ed9Python\u7a0b\u5e8f\u8bbe\u7f6e\u6fc0\u6d3b\u7801\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u901a\u8fc7\u547d\u4ee4\u884c\u8f93\u5165\u6fc0\u6d3b\u7801<\/h3>\n<\/p>\n<p><p>\u5728\u8fd9\u79cd\u65b9\u6cd5\u4e2d\uff0c\u7528\u6237\u5728\u8fd0\u884c\u7a0b\u5e8f\u65f6\u9700\u8981\u901a\u8fc7\u547d\u4ee4\u884c\u8f93\u5165\u6fc0\u6d3b\u7801\u3002\u7a0b\u5e8f\u4f1a\u9a8c\u8bc1\u6fc0\u6d3b\u7801\u7684\u6709\u6548\u6027\uff0c\u7136\u540e\u51b3\u5b9a\u662f\u5426\u5141\u8bb8\u7528\u6237\u7ee7\u7eed\u4f7f\u7528\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<p><h4>1. \u83b7\u53d6\u6fc0\u6d3b\u7801<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u60a8\u9700\u8981\u751f\u6210\u5e76\u5206\u53d1\u6fc0\u6d3b\u7801\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u751f\u6210\u4e00\u4e2a\u7b80\u5355\u7684\u6fc0\u6d3b\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import uuid<\/p>\n<p>def generate_activation_code():<\/p>\n<p>    activation_code = str(uuid.uuid4())<\/p>\n<p>    return activation_code<\/p>\n<p>activation_code = generate_activation_code()<\/p>\n<p>print(&quot;Your activation code is:&quot;, activation_code)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u4f7f\u7528UUID\u5e93\u751f\u6210\u4e00\u4e2a\u552f\u4e00\u7684\u6fc0\u6d3b\u7801\u3002\u60a8\u53ef\u4ee5\u5c06\u751f\u6210\u7684\u6fc0\u6d3b\u7801\u53d1\u9001\u7ed9\u6388\u6743\u7528\u6237\u3002<\/p>\n<\/p>\n<p><h4>2. \u9a8c\u8bc1\u6fc0\u6d3b\u7801<\/h4>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u60a8\u9700\u8981\u5728\u7a0b\u5e8f\u7684\u4e3b\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee3\u7801\u6765\u9a8c\u8bc1\u7528\u6237\u8f93\u5165\u7684\u6fc0\u6d3b\u7801\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import sys<\/p>\n<p>def validate_activation_code(user_input, valid_code):<\/p>\n<p>    return user_input == valid_code<\/p>\n<p>if __name__ == &quot;__m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n__&quot;:<\/p>\n<p>    if len(sys.argv) != 2:<\/p>\n<p>        print(&quot;Usage: python your_program.py &lt;activation_code&gt;&quot;)<\/p>\n<p>        sys.exit(1)<\/p>\n<p>    user_input = sys.argv[1]<\/p>\n<p>    valid_code = &quot;your_predefined_activation_code&quot;  # Replace with your actual activation code<\/p>\n<p>    if validate_activation_code(user_input, valid_code):<\/p>\n<p>        print(&quot;Activation successful! Welcome to the program.&quot;)<\/p>\n<p>        # Proceed with the rest of your program<\/p>\n<p>    else:<\/p>\n<p>        print(&quot;Invalid activation code. Please try again.&quot;)<\/p>\n<p>        sys.exit(1)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u7528\u6237\u9700\u8981\u5728\u8fd0\u884c\u7a0b\u5e8f\u65f6\u63d0\u4f9b\u6fc0\u6d3b\u7801\uff0c\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python your_program.py your_activation_code<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7a0b\u5e8f\u4f1a\u9a8c\u8bc1\u7528\u6237\u8f93\u5165\u7684\u6fc0\u6d3b\u7801\u662f\u5426\u4e0e\u9884\u5b9a\u4e49\u7684\u6fc0\u6d3b\u7801\u5339\u914d\u3002\u5982\u679c\u5339\u914d\uff0c\u7a0b\u5e8f\u5c06\u7ee7\u7eed\u8fd0\u884c\uff1b\u5426\u5219\uff0c\u7a0b\u5e8f\u5c06\u9000\u51fa\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u901a\u8fc7GUI\u8f93\u5165\u6fc0\u6d3b\u7801<\/h3>\n<\/p>\n<p><p>\u5bf9\u4e8e\u6709\u56fe\u5f62\u7528\u6237\u754c\u9762\u7684\u5e94\u7528\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528Tkinter\u5e93\u6765\u521b\u5efa\u4e00\u4e2a\u8f93\u5165\u6846\uff0c\u7528\u6237\u53ef\u4ee5\u5728\u5176\u4e2d\u8f93\u5165\u6fc0\u6d3b\u7801\u3002<\/p>\n<\/p>\n<p><h4>1. \u5b89\u88c5Tkinter<\/h4>\n<\/p>\n<p><p>Tkinter\u662fPython\u7684\u6807\u51c6GUI\u5e93\uff0c\u901a\u5e38\u9ed8\u8ba4\u5b89\u88c5\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install tk<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u521b\u5efa\u6fc0\u6d3b\u7801\u8f93\u5165\u754c\u9762<\/h4>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528Tkinter\u521b\u5efa\u6fc0\u6d3b\u7801\u8f93\u5165\u754c\u9762\u5e76\u9a8c\u8bc1\u6fc0\u6d3b\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import tkinter as tk<\/p>\n<p>from tkinter import messagebox<\/p>\n<p>def validate_activation_code(user_input, valid_code):<\/p>\n<p>    return user_input == valid_code<\/p>\n<p>def on_submit():<\/p>\n<p>    user_input = entry.get()<\/p>\n<p>    valid_code = &quot;your_predefined_activation_code&quot;  # Replace with your actual activation code<\/p>\n<p>    if validate_activation_code(user_input, valid_code):<\/p>\n<p>        messagebox.showinfo(&quot;Activation&quot;, &quot;Activation successful! Welcome to the program.&quot;)<\/p>\n<p>        root.destroy()<\/p>\n<p>        # Proceed with the rest of your program<\/p>\n<p>    else:<\/p>\n<p>        messagebox.showerror(&quot;Activation&quot;, &quot;Invalid activation code. Please try again.&quot;)<\/p>\n<p>root = tk.Tk()<\/p>\n<p>root.title(&quot;Activation&quot;)<\/p>\n<p>label = tk.Label(root, text=&quot;Enter your activation code:&quot;)<\/p>\n<p>label.pack(pady=10)<\/p>\n<p>entry = tk.Entry(root, width=30)<\/p>\n<p>entry.pack(pady=5)<\/p>\n<p>submit_button = tk.Button(root, text=&quot;Submit&quot;, command=on_submit)<\/p>\n<p>submit_button.pack(pady=10)<\/p>\n<p>root.mainloop()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u793a\u4f8b\u521b\u5efa\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u7a97\u53e3\uff0c\u7528\u6237\u53ef\u4ee5\u5728\u5176\u4e2d\u8f93\u5165\u6fc0\u6d3b\u7801\u3002\u70b9\u51fb\u201cSubmit\u201d\u6309\u94ae\u540e\uff0c\u7a0b\u5e8f\u5c06\u9a8c\u8bc1\u6fc0\u6d3b\u7801\u7684\u6709\u6548\u6027\u5e76\u663e\u793a\u76f8\u5e94\u7684\u6d88\u606f\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u901a\u8fc7\u914d\u7f6e\u6587\u4ef6\u8f93\u5165\u6fc0\u6d3b\u7801<\/h3>\n<\/p>\n<p><p>\u53e6\u4e00\u79cd\u65b9\u6cd5\u662f\u8ba9\u7528\u6237\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u8f93\u5165\u6fc0\u6d3b\u7801\u3002\u7a0b\u5e8f\u542f\u52a8\u65f6\u4f1a\u8bfb\u53d6\u914d\u7f6e\u6587\u4ef6\u5e76\u9a8c\u8bc1\u6fc0\u6d3b\u7801\u3002<\/p>\n<\/p>\n<p><h4>1. \u521b\u5efa\u914d\u7f6e\u6587\u4ef6<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u521b\u5efa\u4e00\u4e2a\u914d\u7f6e\u6587\u4ef6\uff08\u4f8b\u5982\uff0cconfig.txt\uff09\u5e76\u5728\u5176\u4e2d\u5305\u542b\u6fc0\u6d3b\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code>activation_code=your_predefined_activation_code<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u8bfb\u53d6\u914d\u7f6e\u6587\u4ef6\u5e76\u9a8c\u8bc1\u6fc0\u6d3b\u7801<\/h4>\n<\/p>\n<p><p>\u5728\u7a0b\u5e8f\u7684\u4e3b\u6587\u4ef6\u4e2d\uff0c\u6dfb\u52a0\u4ee3\u7801\u6765\u8bfb\u53d6\u914d\u7f6e\u6587\u4ef6\u5e76\u9a8c\u8bc1\u6fc0\u6d3b\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def read_activation_code_from_file(file_path):<\/p>\n<p>    with open(file_path, &quot;r&quot;) as file:<\/p>\n<p>        for line in file:<\/p>\n<p>            if line.startswith(&quot;activation_code=&quot;):<\/p>\n<p>                return line.split(&quot;=&quot;)[1].strip()<\/p>\n<p>    return None<\/p>\n<p>def validate_activation_code(user_input, valid_code):<\/p>\n<p>    return user_input == valid_code<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    valid_code = read_activation_code_from_file(&quot;config.txt&quot;)<\/p>\n<p>    if not valid_code:<\/p>\n<p>        print(&quot;Activation code not found in configuration file.&quot;)<\/p>\n<p>        sys.exit(1)<\/p>\n<p>    user_input = input(&quot;Enter your activation code: &quot;)<\/p>\n<p>    if validate_activation_code(user_input, valid_code):<\/p>\n<p>        print(&quot;Activation successful! Welcome to the program.&quot;)<\/p>\n<p>        # Proceed with the rest of your program<\/p>\n<p>    else:<\/p>\n<p>        print(&quot;Invalid activation code. Please try again.&quot;)<\/p>\n<p>        sys.exit(1)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u793a\u4f8b\u4ece\u914d\u7f6e\u6587\u4ef6\u4e2d\u8bfb\u53d6\u9884\u5b9a\u4e49\u7684\u6fc0\u6d3b\u7801\uff0c\u5e76\u63d0\u793a\u7528\u6237\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u6fc0\u6d3b\u7801\u8fdb\u884c\u9a8c\u8bc1\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u751f\u6210\u548c\u9a8c\u8bc1\u590d\u6742\u6fc0\u6d3b\u7801<\/h3>\n<\/p>\n<p><p>\u4e3a\u4e86\u63d0\u9ad8\u5b89\u5168\u6027\uff0c\u60a8\u53ef\u80fd\u5e0c\u671b\u751f\u6210\u548c\u9a8c\u8bc1\u66f4\u590d\u6742\u7684\u6fc0\u6d3b\u7801\u3002\u4ee5\u4e0b\u793a\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528\u54c8\u5e0c\u51fd\u6570\u751f\u6210\u548c\u9a8c\u8bc1\u6fc0\u6d3b\u7801\u3002<\/p>\n<\/p>\n<p><h4>1. \u751f\u6210\u6fc0\u6d3b\u7801<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import hashlib<\/p>\n<p>import uuid<\/p>\n<p>def generate_activation_code(secret_key):<\/p>\n<p>    random_uuid = uuid.uuid4().hex<\/p>\n<p>    activation_code = hashlib.sha256((random_uuid + secret_key).encode()).hexdigest()<\/p>\n<p>    return activation_code<\/p>\n<p>secret_key = &quot;your_secret_key&quot;  # Replace with your actual secret key<\/p>\n<p>activation_code = generate_activation_code(secret_key)<\/p>\n<p>print(&quot;Your activation code is:&quot;, activation_code)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u793a\u4f8b\u4f7f\u7528UUID\u751f\u6210\u4e00\u4e2a\u968f\u673a\u5b57\u7b26\u4e32\uff0c\u5e76\u4f7f\u7528SHA-256\u54c8\u5e0c\u51fd\u6570\u751f\u6210\u6fc0\u6d3b\u7801\u3002<\/p>\n<\/p>\n<p><h4>2. \u9a8c\u8bc1\u6fc0\u6d3b\u7801<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import hashlib<\/p>\n<p>def validate_activation_code(user_input, valid_code, secret_key):<\/p>\n<p>    user_code = hashlib.sha256((user_input + secret_key).encode()).hexdigest()<\/p>\n<p>    return user_code == valid_code<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    valid_code = &quot;your_predefined_activation_code&quot;  # Replace with your actual activation code<\/p>\n<p>    secret_key = &quot;your_secret_key&quot;  # Replace with your actual secret key<\/p>\n<p>    user_input = input(&quot;Enter your activation code: &quot;)<\/p>\n<p>    if validate_activation_code(user_input, valid_code, secret_key):<\/p>\n<p>        print(&quot;Activation successful! Welcome to the program.&quot;)<\/p>\n<p>        # Proceed with the rest of your program<\/p>\n<p>    else:<\/p>\n<p>        print(&quot;Invalid activation code. Please try again.&quot;)<\/p>\n<p>        sys.exit(1)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u793a\u4f8b\u4f7f\u7528SHA-256\u54c8\u5e0c\u51fd\u6570\u9a8c\u8bc1\u7528\u6237\u8f93\u5165\u7684\u6fc0\u6d3b\u7801\u662f\u5426\u4e0e\u9884\u5b9a\u4e49\u7684\u6fc0\u6d3b\u7801\u5339\u914d\u3002<\/p>\n<\/p>\n<p><h3>\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u65b9\u6cd5\uff0c\u60a8\u53ef\u4ee5\u4e3aPython\u7a0b\u5e8f\u8bbe\u7f6e\u6fc0\u6d3b\u7801\uff0c\u786e\u4fdd\u53ea\u6709\u6388\u6743\u7528\u6237\u624d\u80fd\u4f7f\u7528\u60a8\u7684\u8f6f\u4ef6\u3002\u60a8\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u9002\u5408\u7684\u5b9e\u73b0\u65b9\u5f0f\uff0c\u4f8b\u5982\u901a\u8fc7\u547d\u4ee4\u884c\u8f93\u5165\u3001\u901a\u8fc7GUI\u8f93\u5165\u6216\u901a\u8fc7\u914d\u7f6e\u6587\u4ef6\u8f93\u5165\u6fc0\u6d3b\u7801\u3002\u6b64\u5916\uff0c\u60a8\u8fd8\u53ef\u4ee5\u4f7f\u7528\u54c8\u5e0c\u51fd\u6570\u751f\u6210\u548c\u9a8c\u8bc1\u66f4\u590d\u6742\u7684\u6fc0\u6d3b\u7801\uff0c\u4ee5\u63d0\u9ad8\u5b89\u5168\u6027\u3002\u603b\u4e4b\uff0c\u8bbe\u7f6e\u6fc0\u6d3b\u7801\u662f\u4fdd\u62a4\u8f6f\u4ef6\u77e5\u8bc6\u4ea7\u6743\u548c\u786e\u4fdd\u5408\u6cd5\u4f7f\u7528\u7684\u6709\u6548\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u7a0b\u5e8f\u4e2d\u751f\u6210\u6fc0\u6d3b\u7801\uff1f<\/strong><br \/>\u5728Python\u4e2d\u751f\u6210\u6fc0\u6d3b\u7801\u901a\u5e38\u6d89\u53ca\u5230\u968f\u673a\u6570\u751f\u6210\u548c\u5b57\u7b26\u4e32\u7f16\u7801\u3002\u53ef\u4ee5\u4f7f\u7528<code>random<\/code>\u6a21\u5757\u751f\u6210\u968f\u673a\u6570\u5b57\u6216\u5b57\u6bcd\uff0c\u7ed3\u5408\u65f6\u95f4\u6233\u6216\u7528\u6237\u4fe1\u606f\u751f\u6210\u552f\u4e00\u7684\u6fc0\u6d3b\u7801\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a  <\/p>\n<pre><code class=\"language-python\">import random\nimport string\n\ndef generate_activation_code(length=16):\n    characters = string.ascii_uppercase + string.digits\n    activation_code = &#39;&#39;.join(random.choice(characters) for _ in range(length))\n    return activation_code\n\nprint(generate_activation_code())\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u53ef\u4ee5\u786e\u4fdd\u6bcf\u4e2a\u6fc0\u6d3b\u7801\u90fd\u662f\u552f\u4e00\u4e14\u96be\u4ee5\u731c\u6d4b\u7684\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u7a0b\u5e8f\u4e2d\u9a8c\u8bc1\u6fc0\u6d3b\u7801\u7684\u6709\u6548\u6027\uff1f<\/strong><br \/>\u9a8c\u8bc1\u6fc0\u6d3b\u7801\u53ef\u4ee5\u901a\u8fc7\u5c06\u751f\u6210\u7684\u6fc0\u6d3b\u7801\u4e0e\u5b58\u50a8\u7684\u6709\u6548\u6fc0\u6d3b\u7801\u5217\u8868\u8fdb\u884c\u6bd4\u8f83\u3002\u5982\u679c\u6fc0\u6d3b\u7801\u5339\u914d\uff0c\u5219\u53ef\u4ee5\u786e\u8ba4\u5176\u6709\u6548\u6027\u3002\u53ef\u4ee5\u4f7f\u7528\u6570\u636e\u5e93\u6216\u7b80\u5355\u7684\u6587\u672c\u6587\u4ef6\u6765\u5b58\u50a8\u6fc0\u6d3b\u7801\u3002\u793a\u4f8b\u9a8c\u8bc1\u4ee3\u7801\u5982\u4e0b\uff1a  <\/p>\n<pre><code class=\"language-python\">def validate_activation_code(input_code, valid_codes):\n    return input_code in valid_codes\n\nvalid_codes = [&#39;ABCD1234EFGH5678&#39;, &#39;WXYZ9876QRST5432&#39;]  # \u793a\u4f8b\u6709\u6548\u6fc0\u6d3b\u7801\nprint(validate_activation_code(&#39;ABCD1234EFGH5678&#39;, valid_codes))  # \u8f93\u51fa\uff1aTrue\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u53ef\u4ee5\u8f7b\u677e\u5730\u7ef4\u62a4\u548c\u68c0\u67e5\u6fc0\u6d3b\u7801\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u7a0b\u5e8f\u4e2d\u5904\u7406\u6fc0\u6d3b\u7801\u7684\u8fc7\u671f\u95ee\u9898\uff1f<\/strong><br \/>\u4e3a\u4e86\u9632\u6b62\u6fc0\u6d3b\u7801\u88ab\u65e0\u9650\u4f7f\u7528\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u6fc0\u6d3b\u7801\u7684\u6709\u6548\u671f\u3002\u53ef\u4ee5\u5728\u751f\u6210\u6fc0\u6d3b\u7801\u65f6\u8bb0\u5f55\u751f\u6210\u65f6\u95f4\uff0c\u5e76\u5728\u9a8c\u8bc1\u65f6\u68c0\u67e5\u5f53\u524d\u65f6\u95f4\u4e0e\u751f\u6210\u65f6\u95f4\u7684\u5dee\u5f02\u3002\u5982\u679c\u8d85\u51fa\u8bbe\u5b9a\u7684\u6709\u6548\u671f\uff0c\u5219\u6fc0\u6d3b\u7801\u5931\u6548\u3002\u4ee5\u4e0b\u662f\u5904\u7406\u793a\u4f8b\uff1a  <\/p>\n<pre><code class=\"language-python\">import time\n\ndef is_activation_code_valid(generation_time, expiry_duration=86400):  # \u9ed8\u8ba4\u6709\u6548\u671f\u4e3a1\u5929\n    return time.time() - generation_time &lt; expiry_duration\n\ngeneration_time = time.time()  # \u8bb0\u5f55\u5f53\u524d\u65f6\u95f4\nprint(is_activation_code_valid(generation_time))  # \u8f93\u51fa\uff1aTrue\n<\/code><\/pre>\n<p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u53ef\u4ee5\u6709\u6548\u7ba1\u7406\u6fc0\u6d3b\u7801\u7684\u4f7f\u7528\u548c\u8fc7\u671f\u95ee\u9898\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u7ed9Python\u7a0b\u5e8f\u8bbe\u7f6e\u6fc0\u6d3b\u7801\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff1a\u901a\u8fc7\u547d\u4ee4\u884c\u8f93\u5165\u3001\u901a\u8fc7GUI\u8f93\u5165\u3001\u901a\u8fc7\u914d\u7f6e\u6587\u4ef6\u8f93\u5165\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55 [&hellip;]","protected":false},"author":3,"featured_media":1084981,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1084974"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1084974"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1084974\/revisions"}],"predecessor-version":[{"id":1084986,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1084974\/revisions\/1084986"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1084981"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1084974"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1084974"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1084974"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}