{"id":240,"date":"2023-10-31T12:56:53","date_gmt":"2023-10-31T04:56:53","guid":{"rendered":"https:\/\/www.liaoxinghui.com\/?p=240"},"modified":"2023-10-31T12:56:54","modified_gmt":"2023-10-31T04:56:54","slug":"python%e5%af%b9%e6%8e%a5%e9%98%bf%e9%87%8c%e7%9f%ad%e4%bf%a1%e6%8e%a5%e5%8f%a3","status":"publish","type":"post","link":"https:\/\/www.liaoxinghui.com\/?p=240","title":{"rendered":"Python\u8c03\u7528\u963f\u91cc\u63a5\u53e3\u53d1\u9001\u624b\u673a\u77ed\u4fe1"},"content":{"rendered":"<p class=\"wp-block-paragraph\">python\u8c03\u7528\u963f\u91cc\u63a5\u53e3\u53d1\u9001\u624b\u673a\u77ed\u4fe1\uff0c\u53ef\u4ee5\u505a\u901a\u77e5\uff0c\u9a8c\u8bc1\u77ed\u4fe1\u4ec0\u4e48\u7684\uff0c\u540e\u53f0\u81ea\u5b9a\u4e49\u6a21\u677f\uff0c\u7136\u540e\u628a\u6a21\u677f\u6539\u6210\u4f60\u81ea\u5df1\u7684\u5c31\u53ef\u4ee5\u4e86<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># coding=utf-8\n\"\"\"\n@Time \uff1a 2022\/9\/13 13:35\n@Author \uff1a Taering\n@File \uff1a\u624b\u673a\u53d1\u9001\u9a8c\u8bc1\u7801.py\n@IDE \uff1aPyCharm\n@DESC :\n\"\"\"\n\nfrom typing import List\n\nfrom alibabacloud_dysmsapi20170525.client import Client as Dysmsapi20170525Client\nfrom alibabacloud_tea_openapi import models as open_api_models\nfrom alibabacloud_dysmsapi20170525 import models as dysmsapi_20170525_models\nfrom alibabacloud_tea_util import models as util_models\nfrom alibabacloud_tea_util.client import Client as UtilClient\n\nclass Sample:\n    def __init__(self):\n        pass\n\n    @staticmethod\n    def create_client(\n            access_key_id: str,\n            access_key_secret: str,\n    ) -&gt; Dysmsapi20170525Client:\n        \"\"\"\n        \u4f7f\u7528AK&amp;SK\u521d\u59cb\u5316\u8d26\u53f7Client\n        @param access_key_id:\n        @param access_key_secret:\n        @return: Client\n        @throws Exception\n        \"\"\"\n        config = open_api_models.Config(\n            # \u5fc5\u586b\uff0c\u60a8\u7684 AccessKey ID,\n            access_key_id=access_key_id,\n            # \u5fc5\u586b\uff0c\u60a8\u7684 AccessKey Secret,\n            access_key_secret=access_key_secret\n        )\n        # Endpoint \u8bf7\u53c2\u8003 https:\/\/api.aliyun.com\/product\/Dysmsapi\n        config.endpoint = f'dysmsapi.aliyuncs.com'\n        return Dysmsapi20170525Client(config)\n\n    @staticmethod\n    def main(\n            args: List[str],\n    ) -&gt; None:\n        # \u8bf7\u786e\u4fdd\u4ee3\u7801\u8fd0\u884c\u73af\u5883\u8bbe\u7f6e\u4e86\u73af\u5883\u53d8\u91cf ALIBABA_CLOUD_ACCESS_KEY_ID \u548c ALIBABA_CLOUD_ACCESS_KEY_SECRET\u3002\n        # \u5de5\u7a0b\u4ee3\u7801\u6cc4\u9732\u53ef\u80fd\u4f1a\u5bfc\u81f4 AccessKey \u6cc4\u9732\uff0c\u5e76\u5a01\u80c1\u8d26\u53f7\u4e0b\u6240\u6709\u8d44\u6e90\u7684\u5b89\u5168\u6027\u3002\u4ee5\u4e0b\u4ee3\u7801\u793a\u4f8b\u4f7f\u7528\u73af\u5883\u53d8\u91cf\u83b7\u53d6 AccessKey \u7684\u65b9\u5f0f\u8fdb\u884c\u8c03\u7528\uff0c\u4ec5\u4f9b\u53c2\u8003\uff0c\u5efa\u8bae\u4f7f\u7528\u66f4\u5b89\u5168\u7684 STS \u65b9\u5f0f\uff0c\u66f4\u591a\u9274\u6743\u8bbf\u95ee\u65b9\u5f0f\u8bf7\u53c2\u89c1\uff1ahttps:\/\/help.aliyun.com\/document_detail\/378659.html\n        client = Sample.create_client('\u4f60\u7684ID', '\u4f60\u7684key')# \u4e3a\u4e86\u5b89\u5168\uff0c\u5efa\u8bae\u5c06\u5173\u952e\u4fe1\u606f\u5199\u5165\u7cfb\u7edf\u53d8\u91cf\u6216\u8005\u914d\u7f6e\u6210\u914d\u7f6e\u6587\u4ef6\n        send_sms_request = dysmsapi_20170525_models.SendSmsRequest(\n            sign_name='\u4f60\u7684\u7b7e\u540d',\n            template_code='\u6a21\u677f\u540d\u5b57',\n            phone_numbers='\u624b\u673a\u53f7',\n            template_param='{\"code\":\"\u4fe1\u606f\u53d8\u91cf\"}'\n        )\n        runtime = util_models.RuntimeOptions()\n        try:\n            # \u590d\u5236\u4ee3\u7801\u8fd0\u884c\u8bf7\u81ea\u884c\u6253\u5370 API \u7684\u8fd4\u56de\u503c\n            res = client.send_sms_with_options(send_sms_request, runtime)\n            print(res)\n            if res.body.message == 'OK':\n                print({'code': '200', 'msg': 'send message successful'})\n            else:\n                print({'code': '400', 'msg': 'please wait for 1 min'}) # \u8fd8\u6709\u5176\u4ed6\u7684\u8fd4\u56de\uff0c\u63a5\u53e3\u6587\u6863\u4e2d\u6709\uff0c\u81ea\u5df1\u6839\u636e\u4e1a\u52a1\u8c03\u6574\n\n        except Exception as error:\n            # \u5982\u6709\u9700\u8981\uff0c\u8bf7\u6253\u5370 error\n            UtilClient.assert_as_string(error.message)\n\nif __name__ == '__main__':\n    list = []\n    Sample.main(list)\n<\/pre>","protected":false},"excerpt":{"rendered":"<p>python\u8c03\u7528\u963f\u91cc\u63a5\u53e3\u53d1\u9001\u624b\u673a\u77ed\u4fe1\uff0c\u53ef\u4ee5\u505a\u901a\u77e5\uff0c\u9a8c\u8bc1\u77ed\u4fe1\u4ec0\u4e48\u7684\uff0c\u540e\u53f0\u81ea\u5b9a\u4e49\u6a21\u677f\uff0c\u7136\u540e\u628a\u6a21\u677f\u6539\u6210\u4f60\u81ea\u5df1\u7684\u5c31\u53ef\u4ee5\u4e86<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[49,50],"class_list":["post-240","post","type-post","status-publish","format-standard","hentry","category-python","tag-python","tag-50"],"views":483,"_links":{"self":[{"href":"https:\/\/www.liaoxinghui.com\/index.php?rest_route=\/wp\/v2\/posts\/240","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.liaoxinghui.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.liaoxinghui.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.liaoxinghui.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.liaoxinghui.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=240"}],"version-history":[{"count":2,"href":"https:\/\/www.liaoxinghui.com\/index.php?rest_route=\/wp\/v2\/posts\/240\/revisions"}],"predecessor-version":[{"id":242,"href":"https:\/\/www.liaoxinghui.com\/index.php?rest_route=\/wp\/v2\/posts\/240\/revisions\/242"}],"wp:attachment":[{"href":"https:\/\/www.liaoxinghui.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=240"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.liaoxinghui.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=240"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.liaoxinghui.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=240"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}