{"id":1176517,"date":"2025-01-15T17:45:40","date_gmt":"2025-01-15T09:45:40","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1176517.html"},"modified":"2025-01-15T17:45:42","modified_gmt":"2025-01-15T09:45:42","slug":"python%e5%a6%82%e4%bd%95%e5%8f%91%e9%80%81%e9%aa%8c%e8%af%81%e5%90%97","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1176517.html","title":{"rendered":"python\u5982\u4f55\u53d1\u9001\u9a8c\u8bc1\u5417"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25111652\/247e8d39-6f10-4c45-9d52-5e059d07ab72.webp\" alt=\"python\u5982\u4f55\u53d1\u9001\u9a8c\u8bc1\u5417\" \/><\/p>\n<p><p> <strong>\u4f7f\u7528Python\u53d1\u9001\u9a8c\u8bc1\u7801\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528SMTP\u534f\u8bae\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\u3001\u4f7f\u7528SMS\u7f51\u5173\u53d1\u9001\u77ed\u4fe1\u3001\u4f7f\u7528\u7b2c\u4e09\u65b9API\u53d1\u9001\u77ed\u4fe1\u3002<\/strong> \u8fd9\u4e9b\u65b9\u6cd5\u90fd\u6709\u5404\u81ea\u7684\u4f18\u70b9\u548c\u9002\u7528\u573a\u666f\u3002\u4ee5\u4e0b\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5176\u4e2d\u4e00\u79cd\u65b9\u6cd5\uff1a<strong>\u4f7f\u7528SMTP\u534f\u8bae\u53d1\u9001\u7535\u5b50\u90ae\u4ef6<\/strong>\u3002<\/p>\n<\/p>\n<p><p>SMTP\uff08Simple M<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>l Transfer Protocol\uff09\u662f\u7528\u4e8e\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\u7684\u6807\u51c6\u534f\u8bae\u3002Python\u5185\u7f6e\u4e86<code>smtplib<\/code>\u5e93\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u4f7f\u7528SMTP\u534f\u8bae\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528<code>smtplib<\/code>\u53d1\u9001\u5e26\u6709\u9a8c\u8bc1\u7801\u7684\u7535\u5b50\u90ae\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import smtplib<\/p>\n<p>from email.mime.text import MIMEText<\/p>\n<p>from email.mime.multipart import MIMEMultipart<\/p>\n<p>def send_verification_email(receiver_email, verification_code):<\/p>\n<p>    sender_email = &quot;your_email@example.com&quot;<\/p>\n<p>    sender_password = &quot;your_email_password&quot;<\/p>\n<p>    subject = &quot;Your Verification Code&quot;<\/p>\n<p>    body = f&quot;Your verification code is {verification_code}&quot;<\/p>\n<p>    # Create the email<\/p>\n<p>    msg = MIMEMultipart()<\/p>\n<p>    msg[&quot;From&quot;] = sender_email<\/p>\n<p>    msg[&quot;To&quot;] = receiver_email<\/p>\n<p>    msg[&quot;Subject&quot;] = subject<\/p>\n<p>    msg.attach(MIMEText(body, &quot;plain&quot;))<\/p>\n<p>    # Send the email<\/p>\n<p>    try:<\/p>\n<p>        server = smtplib.SMTP(&quot;smtp.example.com&quot;, 587)<\/p>\n<p>        server.starttls()<\/p>\n<p>        server.login(sender_email, sender_password)<\/p>\n<p>        server.sendmail(sender_email, receiver_email, msg.as_string())<\/p>\n<p>        server.quit()<\/p>\n<p>        print(&quot;Verification email sent successfully!&quot;)<\/p>\n<p>    except Exception as e:<\/p>\n<p>        print(f&quot;Failed to send email: {e}&quot;)<\/p>\n<h2><strong>Example usage<\/strong><\/h2>\n<p>send_verification_email(&quot;receiver_email@example.com&quot;, &quot;123456&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u793a\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u901a\u8fc7SMTP\u670d\u52a1\u5668\u53d1\u9001\u4e00\u5c01\u5e26\u6709\u9a8c\u8bc1\u7801\u7684\u7535\u5b50\u90ae\u4ef6\u3002\u4f60\u9700\u8981\u66ff\u6362\u793a\u4f8b\u4e2d\u7684<code>sender_email<\/code>\u3001<code>sender_password<\/code>\u548cSMTP\u670d\u52a1\u5668\u5730\u5740\u4e3a\u4f60\u81ea\u5df1\u7684\u4fe1\u606f\u3002\u4ee5\u4e0b\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u4f7f\u7528SMTP\u534f\u8bae\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\u7684\u5177\u4f53\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u51c6\u5907\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\u7684\u73af\u5883<\/h3>\n<\/p>\n<p><p>\u5728\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\u4e4b\u524d\uff0c\u9700\u8981\u51c6\u5907\u597d\u4ee5\u4e0b\u73af\u5883\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u7535\u5b50\u90ae\u4ef6\u8d26\u6237<\/strong>\uff1a\u4f60\u9700\u8981\u4e00\u4e2a\u7535\u5b50\u90ae\u4ef6\u8d26\u6237\u6765\u53d1\u9001\u9a8c\u8bc1\u7801\u3002\u53ef\u4ee5\u4f7f\u7528Gmail\u3001Outlook\u6216\u4efb\u4f55\u5176\u4ed6\u652f\u6301SMTP\u534f\u8bae\u7684\u7535\u5b50\u90ae\u4ef6\u670d\u52a1\u3002<\/li>\n<li><strong>SMTP\u670d\u52a1\u5668\u4fe1\u606f<\/strong>\uff1a\u83b7\u53d6\u4f60\u6240\u4f7f\u7528\u7684\u7535\u5b50\u90ae\u4ef6\u670d\u52a1\u7684SMTP\u670d\u52a1\u5668\u5730\u5740\u548c\u7aef\u53e3\u53f7\u3002\u4f8b\u5982\uff0cGmail\u7684SMTP\u670d\u52a1\u5668\u5730\u5740\u662f<code>smtp.gmail.com<\/code>\uff0c\u7aef\u53e3\u53f7\u662f587\u3002<\/li>\n<li><strong>\u7535\u5b50\u90ae\u4ef6\u5e93<\/strong>\uff1aPython\u5185\u7f6e\u4e86<code>smtplib<\/code>\u5e93\uff0c\u65e0\u9700\u989d\u5916\u5b89\u88c5\u3002\u4f46\u4e3a\u4e86\u65b9\u4fbf\u521b\u5efa\u548c\u5904\u7406\u7535\u5b50\u90ae\u4ef6\u5185\u5bb9\uff0c\u53ef\u4ee5\u4f7f\u7528<code>email<\/code>\u6a21\u5757\u4e2d\u7684<code>MIMEText<\/code>\u548c<code>MIMEMultipart<\/code>\u7c7b\u3002<\/li>\n<\/ol>\n<p><h3>\u4e8c\u3001\u7f16\u5199\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\u7684\u4ee3\u7801<\/h3>\n<\/p>\n<ol>\n<li><strong>\u5bfc\u5165\u6240\u9700\u5e93<\/strong>\uff1a\u9996\u5148\u5bfc\u5165<code>smtplib<\/code>\u3001<code>MIMEText<\/code>\u548c<code>MIMEMultipart<\/code>\u5e93\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">import smtplib<\/p>\n<p>from email.mime.text import MIMEText<\/p>\n<p>from email.mime.multipart import MIMEMultipart<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u5b9a\u4e49\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\u7684\u51fd\u6570<\/strong>\uff1a\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570<code>send_verification_email<\/code>\uff0c\u8be5\u51fd\u6570\u63a5\u53d7\u63a5\u6536\u8005\u7684\u7535\u5b50\u90ae\u4ef6\u5730\u5740\u548c\u9a8c\u8bc1\u7801\u4f5c\u4e3a\u53c2\u6570\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">def send_verification_email(receiver_email, verification_code):<\/p>\n<p>    sender_email = &quot;your_email@example.com&quot;<\/p>\n<p>    sender_password = &quot;your_email_password&quot;<\/p>\n<p>    subject = &quot;Your Verification Code&quot;<\/p>\n<p>    body = f&quot;Your verification code is {verification_code}&quot;<\/p>\n<p>    # Create the email<\/p>\n<p>    msg = MIMEMultipart()<\/p>\n<p>    msg[&quot;From&quot;] = sender_email<\/p>\n<p>    msg[&quot;To&quot;] = receiver_email<\/p>\n<p>    msg[&quot;Subject&quot;] = subject<\/p>\n<p>    msg.attach(MIMEText(body, &quot;plain&quot;))<\/p>\n<p>    # Send the email<\/p>\n<p>    try:<\/p>\n<p>        server = smtplib.SMTP(&quot;smtp.example.com&quot;, 587)<\/p>\n<p>        server.starttls()<\/p>\n<p>        server.login(sender_email, sender_password)<\/p>\n<p>        server.sendmail(sender_email, receiver_email, msg.as_string())<\/p>\n<p>        server.quit()<\/p>\n<p>        print(&quot;Verification email sent successfully!&quot;)<\/p>\n<p>    except Exception as e:<\/p>\n<p>        print(f&quot;Failed to send email: {e}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u521b\u5efa\u7535\u5b50\u90ae\u4ef6\u5185\u5bb9<\/strong>\uff1a\u4f7f\u7528<code>MIMEText<\/code>\u548c<code>MIMEMultipart<\/code>\u7c7b\u521b\u5efa\u7535\u5b50\u90ae\u4ef6\u5185\u5bb9\uff0c\u5305\u62ec\u53d1\u4ef6\u4eba\u3001\u6536\u4ef6\u4eba\u3001\u4e3b\u9898\u548c\u6b63\u6587\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">msg = MIMEMultipart()<\/p>\n<p>msg[&quot;From&quot;] = sender_email<\/p>\n<p>msg[&quot;To&quot;] = receiver_email<\/p>\n<p>msg[&quot;Subject&quot;] = subject<\/p>\n<p>msg.attach(MIMEText(body, &quot;plain&quot;))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"4\">\n<li><strong>\u53d1\u9001\u7535\u5b50\u90ae\u4ef6<\/strong>\uff1a\u4f7f\u7528<code>smtplib.SMTP<\/code>\u7c7b\u8fde\u63a5SMTP\u670d\u52a1\u5668\uff0c\u767b\u5f55\u53d1\u4ef6\u4eba\u8d26\u6237\uff0c\u5e76\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">try:<\/p>\n<p>    server = smtplib.SMTP(&quot;smtp.example.com&quot;, 587)<\/p>\n<p>    server.starttls()<\/p>\n<p>    server.login(sender_email, sender_password)<\/p>\n<p>    server.sendmail(sender_email, receiver_email, msg.as_string())<\/p>\n<p>    server.quit()<\/p>\n<p>    print(&quot;Verification email sent successfully!&quot;)<\/p>\n<p>except Exception as e:<\/p>\n<p>    print(f&quot;Failed to send email: {e}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528SMS\u7f51\u5173\u53d1\u9001\u77ed\u4fe1<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u901a\u8fc7\u7535\u5b50\u90ae\u4ef6\u53d1\u9001\u9a8c\u8bc1\u7801\uff0c\u8fd8\u53ef\u4ee5\u901a\u8fc7SMS\u7f51\u5173\u53d1\u9001\u77ed\u4fe1\u9a8c\u8bc1\u7801\u3002SMS\u7f51\u5173\u662f\u4e00\u79cd\u5141\u8bb8\u8ba1\u7b97\u673a\u7f51\u7edc\u53d1\u9001\u548c\u63a5\u6536SMS\u6d88\u606f\u7684\u670d\u52a1\u3002\u5e38\u89c1\u7684SMS\u7f51\u5173\u63d0\u4f9b\u5546\u5305\u62ecTwilio\u3001Nexmo\u548cPlivo\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528Twilio\u53d1\u9001\u77ed\u4fe1\u9a8c\u8bc1\u7801\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u5b89\u88c5Twilio\u5e93<\/strong>\uff1a\u9996\u5148\u9700\u8981\u5b89\u88c5Twilio\u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528pip\u547d\u4ee4\u5b89\u88c5\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">pip install twilio<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u5bfc\u5165Twilio\u5e93<\/strong>\uff1a\u5728Python\u4ee3\u7801\u4e2d\u5bfc\u5165Twilio\u5e93\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">from twilio.rest import Client<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u5b9a\u4e49\u53d1\u9001\u77ed\u4fe1\u7684\u51fd\u6570<\/strong>\uff1a\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570<code>send_verification_sms<\/code>\uff0c\u8be5\u51fd\u6570\u63a5\u53d7\u63a5\u6536\u8005\u7684\u624b\u673a\u53f7\u7801\u548c\u9a8c\u8bc1\u7801\u4f5c\u4e3a\u53c2\u6570\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">def send_verification_sms(receiver_phone, verification_code):<\/p>\n<p>    account_sid = &quot;your_twilio_account_sid&quot;<\/p>\n<p>    auth_token = &quot;your_twilio_auth_token&quot;<\/p>\n<p>    twilio_phone = &quot;your_twilio_phone_number&quot;<\/p>\n<p>    body = f&quot;Your verification code is {verification_code}&quot;<\/p>\n<p>    client = Client(account_sid, auth_token)<\/p>\n<p>    try:<\/p>\n<p>        message = client.messages.create(<\/p>\n<p>            body=body,<\/p>\n<p>            from_=twilio_phone,<\/p>\n<p>            to=receiver_phone<\/p>\n<p>        )<\/p>\n<p>        print(&quot;Verification SMS sent successfully!&quot;)<\/p>\n<p>    except Exception as e:<\/p>\n<p>        print(f&quot;Failed to send SMS: {e}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"4\">\n<li><strong>\u8c03\u7528\u53d1\u9001\u77ed\u4fe1\u7684\u51fd\u6570<\/strong>\uff1a\u8c03\u7528<code>send_verification_sms<\/code>\u51fd\u6570\u53d1\u9001\u9a8c\u8bc1\u7801\u77ed\u4fe1\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">send_verification_sms(&quot;+1234567890&quot;, &quot;123456&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u4f7f\u7528\u7b2c\u4e09\u65b9API\u53d1\u9001\u77ed\u4fe1<\/h3>\n<\/p>\n<p><p>\u9664\u4e86Twilio\u5916\uff0c\u8fd8\u6709\u8bb8\u591a\u5176\u4ed6\u7b2c\u4e09\u65b9API\u53ef\u4ee5\u7528\u6765\u53d1\u9001\u77ed\u4fe1\u9a8c\u8bc1\u7801\u3002\u4f8b\u5982\uff0cNexmo\u548cPlivo\u4e5f\u662f\u5e38\u7528\u7684SMS\u670d\u52a1\u63d0\u4f9b\u5546\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528Nexmo\u53d1\u9001\u77ed\u4fe1\u9a8c\u8bc1\u7801\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u5b89\u88c5Nexmo\u5e93<\/strong>\uff1a\u9996\u5148\u9700\u8981\u5b89\u88c5Nexmo\u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528pip\u547d\u4ee4\u5b89\u88c5\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">pip install nexmo<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u5bfc\u5165Nexmo\u5e93<\/strong>\uff1a\u5728Python\u4ee3\u7801\u4e2d\u5bfc\u5165Nexmo\u5e93\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">import nexmo<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u5b9a\u4e49\u53d1\u9001\u77ed\u4fe1\u7684\u51fd\u6570<\/strong>\uff1a\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570<code>send_verification_sms<\/code>\uff0c\u8be5\u51fd\u6570\u63a5\u53d7\u63a5\u6536\u8005\u7684\u624b\u673a\u53f7\u7801\u548c\u9a8c\u8bc1\u7801\u4f5c\u4e3a\u53c2\u6570\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">def send_verification_sms(receiver_phone, verification_code):<\/p>\n<p>    client = nexmo.Client(key=&#39;your_nexmo_api_key&#39;, secret=&#39;your_nexmo_api_secret&#39;)<\/p>\n<p>    body = f&quot;Your verification code is {verification_code}&quot;<\/p>\n<p>    try:<\/p>\n<p>        response = client.send_message({<\/p>\n<p>            &#39;from&#39;: &#39;NEXMO&#39;,<\/p>\n<p>            &#39;to&#39;: receiver_phone,<\/p>\n<p>            &#39;text&#39;: body,<\/p>\n<p>        })<\/p>\n<p>        if response[&#39;messages&#39;][0][&#39;status&#39;] == &#39;0&#39;:<\/p>\n<p>            print(&quot;Verification SMS sent successfully!&quot;)<\/p>\n<p>        else:<\/p>\n<p>            print(f&quot;Failed to send SMS: {response[&#39;messages&#39;][0][&#39;error-text&#39;]}&quot;)<\/p>\n<p>    except Exception as e:<\/p>\n<p>        print(f&quot;Failed to send SMS: {e}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"4\">\n<li><strong>\u8c03\u7528\u53d1\u9001\u77ed\u4fe1\u7684\u51fd\u6570<\/strong>\uff1a\u8c03\u7528<code>send_verification_sms<\/code>\u51fd\u6570\u53d1\u9001\u9a8c\u8bc1\u7801\u77ed\u4fe1\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">send_verification_sms(&quot;1234567890&quot;, &quot;123456&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u4f7f\u7528Python\u53d1\u9001\u9a8c\u8bc1\u7801\u7684\u6700\u4f73\u5b9e\u8df5<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\uff0c\u53d1\u9001\u9a8c\u8bc1\u7801\u7684\u529f\u80fd\u901a\u5e38\u9700\u8981\u96c6\u6210\u5230\u7528\u6237\u6ce8\u518c\u3001\u767b\u5f55\u6216\u5bc6\u7801\u91cd\u7f6e\u7b49\u6d41\u7a0b\u4e2d\u3002\u4e3a\u4e86\u786e\u4fdd\u9a8c\u8bc1\u7801\u53d1\u9001\u7684\u53ef\u9760\u6027\u548c\u5b89\u5168\u6027\uff0c\u5efa\u8bae\u9075\u5faa\u4ee5\u4e0b\u6700\u4f73\u5b9e\u8df5\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u4f7f\u7528\u5f3a\u968f\u673a\u6027\u751f\u6210\u9a8c\u8bc1\u7801<\/strong>\uff1a\u786e\u4fdd\u751f\u6210\u7684\u9a8c\u8bc1\u7801\u5177\u6709\u8db3\u591f\u7684\u968f\u673a\u6027\u548c\u4e0d\u53ef\u9884\u6d4b\u6027\u3002\u53ef\u4ee5\u4f7f\u7528Python\u7684<code>random<\/code>\u6a21\u5757\u751f\u6210\u9a8c\u8bc1\u7801\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">import random<\/p>\n<p>import string<\/p>\n<p>def generate_verification_code(length=6):<\/p>\n<p>    return &#39;&#39;.join(random.choices(string.digits, k=length))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\n<p><strong>\u8bbe\u7f6e\u9a8c\u8bc1\u7801\u6709\u6548\u671f<\/strong>\uff1a\u4e3a\u9a8c\u8bc1\u7801\u8bbe\u7f6e\u4e00\u4e2a\u6709\u6548\u671f\uff0c\u901a\u5e38\u4e3a\u51e0\u5206\u949f\uff0c\u4ee5\u9632\u6b62\u9a8c\u8bc1\u7801\u88ab\u6ee5\u7528\u3002\u53ef\u4ee5\u5c06\u9a8c\u8bc1\u7801\u548c\u751f\u6210\u65f6\u95f4\u5b58\u50a8\u5728\u6570\u636e\u5e93\u4e2d\uff0c\u5e76\u5728\u9a8c\u8bc1\u65f6\u68c0\u67e5\u5176\u6709\u6548\u6027\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u9650\u5236\u9a8c\u8bc1\u7801\u53d1\u9001\u9891\u7387<\/strong>\uff1a\u4e3a\u4e86\u9632\u6b62\u6ee5\u7528\uff0c\u9650\u5236\u540c\u4e00\u7528\u6237\u5728\u4e00\u5b9a\u65f6\u95f4\u5185\u53d1\u9001\u9a8c\u8bc1\u7801\u7684\u6b21\u6570\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u5728\u6570\u636e\u5e93\u4e2d\u8bb0\u5f55\u6bcf\u6b21\u53d1\u9001\u9a8c\u8bc1\u7801\u7684\u65f6\u95f4\uff0c\u5e76\u5728\u53d1\u9001\u65b0\u7684\u9a8c\u8bc1\u7801\u524d\u68c0\u67e5\u662f\u5426\u7b26\u5408\u53d1\u9001\u9891\u7387\u9650\u5236\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u52a0\u5bc6\u5b58\u50a8\u9a8c\u8bc1\u7801<\/strong>\uff1a\u4e3a\u4e86\u4fdd\u62a4\u7528\u6237\u7684\u9690\u79c1\u548c\u5b89\u5168\uff0c\u9a8c\u8bc1\u7801\u5728\u5b58\u50a8\u65f6\u5e94\u8fdb\u884c\u52a0\u5bc6\u6216\u54c8\u5e0c\u5904\u7406\u3002\u53ef\u4ee5\u4f7f\u7528Python\u7684<code>hashlib<\/code>\u6a21\u5757\u8fdb\u884c\u54c8\u5e0c\u5904\u7406\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">import hashlib<\/p>\n<p>def hash_verification_code(code):<\/p>\n<p>    return hashlib.sha256(code.encode()).hexdigest()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"5\">\n<li><strong>\u91c7\u7528\u591a\u56e0\u7d20\u8ba4\u8bc1<\/strong>\uff1a\u9664\u4e86\u53d1\u9001\u9a8c\u8bc1\u7801\u5916\uff0c\u8fd8\u53ef\u4ee5\u7ed3\u5408\u5176\u4ed6\u8ba4\u8bc1\u65b9\u5f0f\uff08\u5982\u5bc6\u7801\u3001\u6307\u7eb9\u8bc6\u522b\u7b49\uff09\u5b9e\u73b0\u591a\u56e0\u7d20\u8ba4\u8bc1\uff0c\u8fdb\u4e00\u6b65\u63d0\u9ad8\u5b89\u5168\u6027\u3002<\/li>\n<\/ol>\n<p><h3>\u516d\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u672c\u6587\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u4f7f\u7528Python\u53d1\u9001\u9a8c\u8bc1\u7801\u7684\u591a\u79cd\u65b9\u6cd5\uff0c\u5305\u62ec\u4f7f\u7528SMTP\u534f\u8bae\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\u3001\u4f7f\u7528SMS\u7f51\u5173\u53d1\u9001\u77ed\u4fe1\u548c\u4f7f\u7528\u7b2c\u4e09\u65b9API\u53d1\u9001\u77ed\u4fe1\u3002\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u9002\u7528\u573a\u666f\u548c\u4f18\u7f3a\u70b9\u3002\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\uff0c\u53ef\u4ee5\u6839\u636e\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\uff0c\u5e76\u9075\u5faa\u6700\u4f73\u5b9e\u8df5\uff0c\u786e\u4fdd\u9a8c\u8bc1\u7801\u53d1\u9001\u7684\u53ef\u9760\u6027\u548c\u5b89\u5168\u6027\u3002\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u4e86\u89e3\u548c\u5b9e\u73b0Python\u53d1\u9001\u9a8c\u8bc1\u7801\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528Python\u53d1\u9001\u9a8c\u8bc1\u7801\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53d1\u9001\u9a8c\u8bc1\u7801\u901a\u5e38\u53ef\u4ee5\u901a\u8fc7\u90ae\u4ef6\u6216\u77ed\u4fe1\u7684\u65b9\u5f0f\u8fdb\u884c\u3002\u4f7f\u7528\u90ae\u4ef6\u53d1\u9001\u9a8c\u8bc1\u7801\u65f6\uff0c\u53ef\u4ee5\u5229\u7528\u5185\u7f6e\u7684<code>smtplib<\/code>\u5e93\uff0c\u7ed3\u5408<code>email<\/code>\u6a21\u5757\u6784\u5efa\u90ae\u4ef6\u5185\u5bb9\u3002\u5bf9\u4e8e\u77ed\u4fe1\u53d1\u9001\uff0c\u53ef\u4ee5\u4f7f\u7528\u7b2c\u4e09\u65b9\u670d\u52a1\u5982Twilio\u6216Nexmo\uff0c\u63d0\u4f9bAPI\u63a5\u53e3\uff0c\u65b9\u4fbf\u5feb\u901f\u5b9e\u73b0\u9a8c\u8bc1\u7801\u7684\u53d1\u9001\u3002<\/p>\n<p><strong>\u53d1\u9001\u9a8c\u8bc1\u7801\u65f6\u9700\u8981\u6ce8\u610f\u54ea\u4e9b\u5b89\u5168\u6027\u95ee\u9898\uff1f<\/strong><br \/>\u5728\u53d1\u9001\u9a8c\u8bc1\u7801\u8fc7\u7a0b\u4e2d\uff0c\u786e\u4fdd\u7528\u6237\u4fe1\u606f\u7684\u5b89\u5168\u81f3\u5173\u91cd\u8981\u3002\u5e94\u91c7\u7528HTTPS\u534f\u8bae\u8fdb\u884c\u6570\u636e\u4f20\u8f93\uff0c\u5e76\u5bf9\u9a8c\u8bc1\u7801\u8fdb\u884c\u52a0\u5bc6\u5b58\u50a8\u3002\u540c\u65f6\uff0c\u8bbe\u5b9a\u9a8c\u8bc1\u7801\u7684\u6709\u6548\u671f\u548c\u5c1d\u8bd5\u6b21\u6570\u9650\u5236\uff0c\u907f\u514d\u6076\u610f\u653b\u51fb\u548c\u6ee5\u7528\u3002<\/p>\n<p><strong>\u5982\u4f55\u9a8c\u8bc1\u7528\u6237\u8f93\u5165\u7684\u9a8c\u8bc1\u7801\uff1f<\/strong><br \/>\u5728\u7528\u6237\u8f93\u5165\u9a8c\u8bc1\u7801\u540e\uff0c\u53ef\u4ee5\u5c06\u5176\u4e0e\u6570\u636e\u5e93\u4e2d\u5b58\u50a8\u7684\u9a8c\u8bc1\u7801\u8fdb\u884c\u6bd4\u5bf9\u3002\u786e\u4fdd\u6bd4\u8f83\u65f6\u8003\u8651\u5230\u9a8c\u8bc1\u7801\u7684\u8fc7\u671f\u65f6\u95f4\u3002\u5982\u679c\u9a8c\u8bc1\u7801\u6b63\u786e\u4e14\u672a\u8fc7\u671f\uff0c\u5219\u53ef\u4ee5\u5b8c\u6210\u7528\u6237\u8eab\u4efd\u9a8c\u8bc1\uff0c\u5141\u8bb8\u5176\u7ee7\u7eed\u64cd\u4f5c\u3002\u8fd8\u53ef\u4ee5\u8003\u8651\u5728\u9a8c\u8bc1\u7801\u9a8c\u8bc1\u5931\u8d25\u65f6\uff0c\u63d0\u4f9b\u53cb\u597d\u7684\u9519\u8bef\u63d0\u793a\uff0c\u4ee5\u6539\u5584\u7528\u6237\u4f53\u9a8c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u4f7f\u7528Python\u53d1\u9001\u9a8c\u8bc1\u7801\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528SMTP\u534f\u8bae\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\u3001\u4f7f\u7528SMS\u7f51\u5173\u53d1\u9001\u77ed\u4fe1\u3001\u4f7f\u7528\u7b2c\u4e09\u65b9API\u53d1 [&hellip;]","protected":false},"author":3,"featured_media":1176521,"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\/1176517"}],"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=1176517"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1176517\/revisions"}],"predecessor-version":[{"id":1176523,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1176517\/revisions\/1176523"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1176521"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1176517"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1176517"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1176517"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}