{"id":47980,"date":"2024-12-02T08:39:36","date_gmt":"2024-12-02T00:39:36","guid":{"rendered":"https:\/\/fwq.ai\/blog\/47980\/"},"modified":"2024-12-02T08:39:36","modified_gmt":"2024-12-02T00:39:36","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-php-%e4%b8%8e%e6%97%a5%e5%8e%86%e6%9c%8d%e5%8a%a1%e5%90%8c%e6%ad%a5%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/47980\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 PHP \u4e0e\u65e5\u5386\u670d\u52a1\u540c\u6b65\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u5982\u4f55\u4f7f\u7528 PHP \u4e0e\u65e5\u5386\u670d\u52a1\u540c\u6b65\uff1f<\/h1>\n<p>\u5c0f\u4f19\u4f34\u4eec\u6709\u6ca1\u6709\u89c9\u5f97\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u5f88\u6709\u610f\u601d\uff1f\u6709\u610f\u601d\u5c31\u5bf9\u4e86\uff01\u4eca\u5929\u5c31\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5982\u4f55\u4f7f\u7528 PHP \u4e0e\u65e5\u5386\u670d\u52a1\u540c\u6b65\uff1f\u300b<\/span>\uff0c\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u5728\u5b66\u4e60\u4e2d\u5bf9\u5176\u4e2d\u90e8\u5206\u77e5\u8bc6\u70b9\u6709\u7591\u95ee\uff0c\u6216\u8bb8\u770b\u4e86\u672c\u6587\u5c31\u80fd\u5e2e\u5230\u4f60\uff01<\/p>\n<p>\u5982\u4f55\u4f7f\u7528 PHP \u4e0e\u65e5\u5386\u670d\u52a1\u540c\u6b65\uff1f\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u4f7f\u7528 PHP \u4e0e\u65e5\u5386\u670d\u52a1\uff08\u5982 Google \u65e5\u5386\u6216 Apple \u65e5\u5386\uff09\u540c\u6b65\uff1a\u521d\u59cb\u5316\u5ba2\u6237\u7aef\u6388\u6743\u5ba2\u6237\u7aef\u521b\u5efa Google \u670d\u52a1\u83b7\u53d6\u4e8b\u4ef6\uff08\u53ef\u9009\uff09\u521b\u5efa\u4e8b\u4ef6\uff08\u53ef\u9009\uff09\u5220\u9664\u4e8b\u4ef6\uff08\u53ef\u9009\uff09<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729947269671ce685727d3.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 PHP \u4e0e\u65e5\u5386\u670d\u52a1\u540c\u6b65\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 PHP \u4e0e\u65e5\u5386\u670d\u52a1\u540c\u6b65\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 PHP \u4e0e\u65e5\u5386\u670d\u52a1\u540c\u6b65\uff1f<\/strong><\/p>\n<p><strong>\u524d\u8a00<\/strong><\/p>\n<p>\u65e5\u5386\u670d\u52a1\uff08\u5982 Google \u65e5\u5386\u6216 Apple \u65e5\u5386\uff09\u63d0\u4f9b\u4e86\u7ba1\u7406\u65e5\u7a0b\u548c\u4e8b\u4ef6\u7684\u4fbf\u6377\u65b9\u5f0f\u3002\u901a\u8fc7\u4f7f\u7528 PHP\uff0c\u6211\u4eec\u53ef\u4ee5\u4e0e\u8fd9\u4e9b\u670d\u52a1\u540c\u6b65\u5e76\u81ea\u52a8\u6267\u884c\u4efb\u52a1\u3002<\/p>\n<p><strong>\u524d\u63d0\u6761\u4ef6<\/strong><\/p>\n<ul>\n<li>PHP 7.2 \u6216\u66f4\u9ad8\u7248\u672c<\/li>\n<li>cURL \u6269\u5c55<\/li>\n<li>Google \u5e94\u7528\u51ed\u8bc1\uff08\u5bf9\u4e8e\u540c\u6b65 Google \u65e5\u5386\uff09<\/li>\n<\/ul>\n<p><strong>\u96c6\u6210\u65e5\u5386\u670d\u52a1<\/strong><\/p>\n<ol>\n<li><strong>\u83b7\u53d6\u51ed\u8bc1\uff1a<\/strong> \u5bf9\u4e8e Google \u65e5\u5386\uff0c\u8bf7\u8bbf\u95ee Google \u5f00\u53d1\u8005\u63a7\u5236\u53f0\u5e76\u521b\u5efa OAuth 2.0 \u51ed\u8bc1\u3002<\/li>\n<li>\n<p><strong>\u5b89\u88c5 Google API \u5ba2\u6237\u7aef\u5e93\uff1a<\/strong> \u4f7f\u7528 Composer \u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>composer require google\/apiclient:^2.0<\/pre>\n<\/li>\n<li><strong>\u4f7f\u7528\u670d\u52a1\u5e10\u6237\uff1a<\/strong> \u5982\u679c\u60a8\u4e0d\u5e0c\u671b\u4f7f\u7528 OAuth\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u670d\u52a1\u5e10\u6237\u3002\u6709\u5173\u8be6\u7ec6\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605 Google \u6587\u6863\u3002<\/li>\n<\/ol>\n<p><strong>\u540c\u6b65\u65e5\u5386<\/strong><\/p>\n<p><strong>1. \u521d\u59cb\u5316\u5ba2\u6237\u7aef<\/strong><\/p>\n<pre>$client = new Google_Client();\n$client-&gt;setAuthConfig('client_secret.json');\n$client-&gt;addScope('https:\/\/www.googleapis.com\/auth\/calendar');<\/pre>\n<p><strong>2. \u6388\u6743\u5ba2\u6237\u7aef<\/strong><\/p>\n<pre>$accessToken = file_get_contents('access_token.json');\n$client-&gt;setAccessToken($accessToken);<\/pre>\n<p><strong>3. \u521b\u5efa Google \u670d\u52a1<\/strong><\/p>\n<pre>$service = new Google_Service_Calendar($client);<\/pre>\n<p><strong>4. \u83b7\u53d6\u4e8b\u4ef6<\/strong><\/p>\n<pre>$events = $service-&gt;events-&gt;listEvents('primary');<\/pre>\n<p><strong>5. \u521b\u5efa\u4e8b\u4ef6<\/strong><\/p>\n<pre>$event = new Google_Service_Calendar_Event(array(\n  'summary' =&gt; 'My Event',\n  'start' =&gt; array(\n    'dateTime' =&gt; '2023-08-30T10:00:00+08:00',\n  ),\n  'end' =&gt; array(\n    'dateTime' =&gt; '2023-08-30T11:00:00+08:00',\n  ),\n));\n\n$event = $service-&gt;events-&gt;insert('primary', $event);<\/pre>\n<p><strong>6. \u5220\u9664\u4e8b\u4ef6<\/strong><\/p>\n<pre>$service-&gt;events-&gt;delete('primary', $eventId);<\/pre>\n<p><strong>\u5b9e\u7528\u6848\u4f8b<\/strong><\/p>\n<p><strong>\u5c06 Google \u65e5\u5386\u4e8b\u4ef6\u540c\u6b65\u5230\u6570\u636e\u5e93<\/strong><\/p>\n<pre>\/\/ \u83b7\u53d6 Google \u65e5\u5386\u4e2d\u7684\u4e8b\u4ef6\n$events = $service-&gt;events-&gt;listEvents('primary');\n\n\/\/ \u5faa\u73af\u904d\u5386\u4e8b\u4ef6\uff0c\u5e76\u4fdd\u5b58\u5230\u6570\u636e\u5e93\nforeach ($events as $event) {\n  $stmt = $conn-&gt;prepare('INSERT INTO events (title, start, end) VALUES (?, ?, ?)');\n  $stmt-&gt;bind_param('sss', $event-&gt;getSummary(), $event-&gt;start-&gt;dateTime, $event-&gt;end-&gt;dateTime);\n  $stmt-&gt;execute();\n}<\/pre>\n<p>\u901a\u8fc7\u4f7f\u7528 PHP \u548c\u65e5\u5386\u670d\u52a1\uff0c\u6211\u4eec\u53ef\u4ee5\u5b9e\u73b0\u4e8b\u4ef6\u7ba1\u7406\u4efb\u52a1\u7684\u81ea\u52a8\u5316\uff0c\u63d0\u9ad8\u5de5\u4f5c\u6548\u7387\u3002<\/p>\n<p>\u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300a\u5982\u4f55\u4f7f\u7528 PHP \u4e0e\u65e5\u5386\u670d\u52a1\u540c\u6b65\uff1f\u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~\u7c73\u4e91\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03\u6587\u7ae0\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4f7f\u7528 PHP \u4e0e\u65e5\u5386\u670d\u52a1\u540c\u6b65\uff1f \u5c0f\u4f19\u4f34\u4eec\u6709\u6ca1\u6709\u89c9\u5f97\u5b66\u4e60\u6587\u7ae0\u5f88\u6709\u610f\u601d\uff1f\u6709\u610f\u601d\u5c31\u5bf9\u4e86\uff01\u4eca\u5929\u5c31\u7ed9\u5927\u5bb6\u5e26\u6765\u300a\u5982\u4f55\u4f7f\u7528 PHP \u4e0e\u65e5\u5386\u670d\u52a1\u540c\u6b65\uff1f\u300b\uff0c\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230\uff0c\u82e5\u662f\u5728\u5b66\u4e60\u4e2d\u5bf9\u5176\u4e2d\u90e8\u5206\u77e5\u8bc6\u70b9\u6709\u7591\u95ee\uff0c\u6216\u8bb8\u770b\u4e86\u672c\u6587\u5c31\u80fd\u5e2e\u5230\u4f60\uff01 \u5982\u4f55\u4f7f\u7528 PHP \u4e0e\u65e5\u5386\u670d\u52a1\u540c\u6b65\uff1f\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u4f7f\u7528 PHP \u4e0e\u65e5\u5386\u670d\u52a1\uff08\u5982 Google \u65e5\u5386\u6216 Apple \u65e5\u5386\uff09\u540c\u6b65\uff1a\u521d\u59cb\u5316\u5ba2\u6237\u7aef\u6388\u6743\u5ba2\u6237\u7aef\u521b\u5efa Google \u670d\u52a1\u83b7\u53d6\u4e8b\u4ef6\uff08\u53ef\u9009\uff09\u521b\u5efa\u4e8b\u4ef6\uff08\u53ef\u9009\uff09\u5220\u9664\u4e8b\u4ef6\uff08\u53ef\u9009\uff09 \u5982\u4f55\u4f7f\u7528 PHP \u4e0e\u65e5\u5386\u670d\u52a1\u540c\u6b65\uff1f \u524d\u8a00 \u65e5\u5386\u670d\u52a1\uff08\u5982 Google \u65e5\u5386\u6216 Apple \u65e5\u5386\uff09\u63d0\u4f9b\u4e86\u7ba1\u7406\u65e5\u7a0b\u548c\u4e8b\u4ef6\u7684\u4fbf\u6377\u65b9\u5f0f\u3002\u901a\u8fc7\u4f7f\u7528 PHP\uff0c\u6211\u4eec\u53ef\u4ee5\u4e0e\u8fd9\u4e9b\u670d\u52a1\u540c\u6b65\u5e76\u81ea\u52a8\u6267\u884c\u4efb\u52a1\u3002 \u524d\u63d0\u6761\u4ef6 PHP 7.2 \u6216\u66f4\u9ad8\u7248\u672c cURL \u6269\u5c55 Google \u5e94\u7528\u51ed\u8bc1\uff08\u5bf9\u4e8e\u540c\u6b65 Google \u65e5\u5386\uff09 \u96c6\u6210\u65e5\u5386\u670d\u52a1 \u83b7\u53d6\u51ed\u8bc1\uff1a \u5bf9\u4e8e Google \u65e5\u5386\uff0c\u8bf7\u8bbf\u95ee Google \u5f00\u53d1\u8005\u63a7\u5236\u53f0\u5e76\u521b\u5efa OAuth 2.0 \u51ed\u8bc1\u3002 \u5b89\u88c5 Google API \u5ba2\u6237\u7aef\u5e93\uff1a \u4f7f\u7528 Composer \u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a composer [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-47980","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47980","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=47980"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47980\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=47980"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=47980"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=47980"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}