{"id":250,"date":"2023-10-20T13:22:55","date_gmt":"2023-10-20T05:22:55","guid":{"rendered":"https:\/\/www.nickyoo7.com\/?p=250"},"modified":"2023-10-20T13:22:55","modified_gmt":"2023-10-20T05:22:55","slug":"ios-%e5%bb%ba%e7%ab%8b%e9%81%a0%e8%b7%9d%e6%8e%a8%e6%92%ad-app-%e4%ba%94-%e6%8e%a8%e6%92%ad%e6%b8%ac%e8%a9%a6-%e4%bd%bf%e7%94%a8-php","status":"publish","type":"post","link":"https:\/\/www.nickyoo7.com\/?p=250","title":{"rendered":"iOS \u5efa\u7acb\u9060\u8ddd\u63a8\u64ad App (\u4e94) \u63a8\u64ad\u6e2c\u8a66 \u2013 \u4f7f\u7528 php"},"content":{"rendered":"<p>iOS \u5efa\u7acb\u9060\u8ddd\u63a8\u64ad App (\u4e94) \u63a8\u64ad\u6e2c\u8a66 \u2013 \u4f7f\u7528 php<br \/>\n<!--more-->1.\u4f3a\u670d\u5668\u6aa2\u67e5\u4e8b\u9805<br \/>\n(1) Web Server \u9700\u652f\u63f4 HTTP\/2<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">\u6aa2\u6e2c\u65b9\u6cd5\u4e00 : For Linux\r\n$ curl --http2 -I https:\/\/www.google.com\r\n\u4e0d\u652f\u63f4\u51fa\u73fe :\r\ncurl : (1) Unsupported protocol\r\n\r\n\u6aa2\u6e2c\u65b9\u5f0f\u4e8c : \u4f7f\u7528 php\r\n&lt;?php\r\n    echo $_SERVER[ \"SERVER_PROTOCOL\" ];\r\n<\/pre>\n<p>(2) PHP \u7248\u672c\u9700 5.5.24 \u7248\u4ee5\u4e0a php \u7684 curl \u624d\u6709\u652f\u63f4 HTTP\/2<\/p>\n<p>2. PHP \u7a0b\u5f0f\u78bc<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\">&lt;?php\r\n    $team_id=\"\"; \/\/\u958b\u767c\u8005 team ID\r\n    $key_id=\"\";  \/\/p8 \u683c\u5f0f\u8b49\u66f8\u7684 ID\r\n    $pkey_file=\"AuthKey_xxxxxx.p8\"; \/\/p8\u8b49\u66f8\u7684\u5b58\u653e\u4f4d\u5740\uff0c\u52ff\u4f7f\u7528\u4e2d\u6587\u3002\u7d55\u5c0d\u8def\u5f91\r\n    $bundle_id=\"\"; \/\/App\u7684 Boundle ID\r\n    $device_token=\"\"; \/\/Device token\r\n    \r\n    $msg=\"\u6e2c\u8a66\u8a0a\u606f\";\r\n    $r=Sent_Notification_iOS($team_id ,$key_id,$pkey_file,$bundle_id,$device_token,$msg);\r\n    \r\nfunction Sent_Notification_iOS($team_id ,$key_id,$pkey_file,$bundle_id,$device_token,$msg){\r\n    \/\/ Create the notification payload\r\n    $payload = array(\r\n        'aps' =&gt; array(\r\n            'alert' =&gt; $msg,\r\n            'sound' =&gt; 'default'\r\n        )\r\n    );\r\n    $payload_json = json_encode($payload);\r\n\r\n    \/\/\u6b63\u5f0f\u74b0\u5883\u63a8\u9001\r\n    \/\/$url = 'https:\/\/api.push.apple.com\/3\/device\/' . $device_token;\r\n\r\n    \/\/\u6c99\u76d2\u63a8\u9001\u5730\u5740\r\n    $url = \"https:\/\/api.sandbox.push.apple.com\/3\/device\/\".$device_token;\r\n    \r\n    $jwt = get_JWT($team_id ,$key_id,$pkey_file,$bundle_id);\r\n        \r\n    $headers = array(\r\n        'Authorization: Bearer '.$jwt,\r\n        'Content-Type: application\/json',\r\n       \t'apns-topic: '.$bundle_id,\r\n    );\r\n    $ch = curl_init($url);\r\n    curl_setopt($ch, CURLOPT_POSTFIELDS, $payload_json);\r\n    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0); \/\/\u9019\u91cc\u5f88\u95dc\u9375\uff0c\u4ee5http2\u767c\u9001\u8acb\u6c42\uff0c\u5982\u679c\u4f60\u7684curl\u4e0d\u652f\u6301http2\u5247\u9700\u8981\u770b\u524d\u9762\u7684\u6b65\u9a5f\r\n    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);\r\n    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);\r\n    $response = curl_exec($ch);\r\n    $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);\r\n    var_dump($response);\r\n    curl_close($ch);\r\n\r\n    \/\/ Check the response\r\n    if ($http_code == 200) {\r\n        echo 'Notification sent successfully.';\r\n    } else {\r\n        echo 'Notification failed with error code: ' . $http_code;\r\n    }\r\n    \r\n}\r\nfunction get_JWT($team_id ,$key_id,$pkey_file,$bundle_id){\r\n\r\n\/\/ token\u904e\u671f\u6642\u9593\r\n    $expires = time() + 3600;\r\n\r\n    \/\/ Generate the JWT header\r\n    $header = array(\r\n        'alg' =&gt; 'ES256',\r\n        'kid' =&gt; $key_id\r\n    );\r\n\r\n    $jwt_header = base64_encode(json_encode($header));\r\n\r\n    \/\/ Generate the JWT payload\r\n    $payload = array(\r\n        'iss' =&gt; $team_id,\r\n        'iat' =&gt; time()\r\n    );\r\n    $jwt_payload = base64_encode(json_encode($payload));\r\n\r\n    \/\/\u8f09\u5165\u8b49\u66f8\u6587\u4ef6\r\n    $pkey_contents = file_get_contents($pkey_file);\r\n    $pkey = openssl_get_privatekey($pkey_contents);\r\n\r\n    \/\/JWT \u7c3d\u540d\r\n    $signature = '';\r\n    openssl_sign($jwt_header . '.' . $jwt_payload, $signature, $pkey, 'sha256');\r\n    $jwt_signature = base64_encode($signature);\r\n    \r\n    \/\/ Generate the final JWT\r\n    $jwt = $jwt_header . '.' . $jwt_payload . '.' . $jwt_signature;\r\n    return $jwt;\r\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>iOS \u5efa\u7acb\u9060\u8ddd\u63a8\u64ad App (\u4e94) \u63a8\u64ad\u6e2c\u8a66 \u2013 \u4f7f\u7528 php<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29,6],"tags":[],"class_list":["post-250","post","type-post","status-publish","format-standard","hentry","category-ios","category-php","entry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>iOS \u5efa\u7acb\u9060\u8ddd\u63a8\u64ad App (\u4e94) \u63a8\u64ad\u6e2c\u8a66 \u2013 \u4f7f\u7528 php - oo7&#039;s World<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.nickyoo7.com\/?p=250\" \/>\n<meta property=\"og:locale\" content=\"zh_TW\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"iOS \u5efa\u7acb\u9060\u8ddd\u63a8\u64ad App (\u4e94) \u63a8\u64ad\u6e2c\u8a66 \u2013 \u4f7f\u7528 php - oo7&#039;s World\" \/>\n<meta property=\"og:description\" content=\"iOS \u5efa\u7acb\u9060\u8ddd\u63a8\u64ad App (\u4e94) \u63a8\u64ad\u6e2c\u8a66 \u2013 \u4f7f\u7528 php\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.nickyoo7.com\/?p=250\" \/>\n<meta property=\"og:site_name\" content=\"oo7&#039;s World\" \/>\n<meta property=\"article:published_time\" content=\"2023-10-20T05:22:55+00:00\" \/>\n<meta name=\"author\" content=\"oo7\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005:\" \/>\n\t<meta name=\"twitter:data1\" content=\"oo7\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9810\u4f30\u95b1\u8b80\u6642\u9593\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\u9418\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.nickyoo7.com\\\/?p=250#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.nickyoo7.com\\\/?p=250\"},\"author\":{\"name\":\"oo7\",\"@id\":\"https:\\\/\\\/www.nickyoo7.com\\\/#\\\/schema\\\/person\\\/2ab2a209159a41a5c551869792fd0367\"},\"headline\":\"iOS \u5efa\u7acb\u9060\u8ddd\u63a8\u64ad App (\u4e94) \u63a8\u64ad\u6e2c\u8a66 \u2013 \u4f7f\u7528 php\",\"datePublished\":\"2023-10-20T05:22:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.nickyoo7.com\\\/?p=250\"},\"wordCount\":15,\"articleSection\":[\"iOS \u958b\u767c\",\"PHP\"],\"inLanguage\":\"zh-TW\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.nickyoo7.com\\\/?p=250\",\"url\":\"https:\\\/\\\/www.nickyoo7.com\\\/?p=250\",\"name\":\"iOS \u5efa\u7acb\u9060\u8ddd\u63a8\u64ad App (\u4e94) \u63a8\u64ad\u6e2c\u8a66 \u2013 \u4f7f\u7528 php - oo7&#039;s World\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.nickyoo7.com\\\/#website\"},\"datePublished\":\"2023-10-20T05:22:55+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.nickyoo7.com\\\/#\\\/schema\\\/person\\\/2ab2a209159a41a5c551869792fd0367\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.nickyoo7.com\\\/?p=250#breadcrumb\"},\"inLanguage\":\"zh-TW\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.nickyoo7.com\\\/?p=250\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.nickyoo7.com\\\/?p=250#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9801\",\"item\":\"https:\\\/\\\/www.nickyoo7.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"iOS \u5efa\u7acb\u9060\u8ddd\u63a8\u64ad App (\u4e94) \u63a8\u64ad\u6e2c\u8a66 \u2013 \u4f7f\u7528 php\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.nickyoo7.com\\\/#website\",\"url\":\"https:\\\/\\\/www.nickyoo7.com\\\/\",\"name\":\"oo7&#039;s World\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.nickyoo7.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"zh-TW\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.nickyoo7.com\\\/#\\\/schema\\\/person\\\/2ab2a209159a41a5c551869792fd0367\",\"name\":\"oo7\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-TW\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e2ffdb3c64d0daa8a28af5806bcb94e283c27974a48761397038108203287e0d?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e2ffdb3c64d0daa8a28af5806bcb94e283c27974a48761397038108203287e0d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e2ffdb3c64d0daa8a28af5806bcb94e283c27974a48761397038108203287e0d?s=96&d=mm&r=g\",\"caption\":\"oo7\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"iOS \u5efa\u7acb\u9060\u8ddd\u63a8\u64ad App (\u4e94) \u63a8\u64ad\u6e2c\u8a66 \u2013 \u4f7f\u7528 php - oo7&#039;s World","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.nickyoo7.com\/?p=250","og_locale":"zh_TW","og_type":"article","og_title":"iOS \u5efa\u7acb\u9060\u8ddd\u63a8\u64ad App (\u4e94) \u63a8\u64ad\u6e2c\u8a66 \u2013 \u4f7f\u7528 php - oo7&#039;s World","og_description":"iOS \u5efa\u7acb\u9060\u8ddd\u63a8\u64ad App (\u4e94) \u63a8\u64ad\u6e2c\u8a66 \u2013 \u4f7f\u7528 php","og_url":"https:\/\/www.nickyoo7.com\/?p=250","og_site_name":"oo7&#039;s World","article_published_time":"2023-10-20T05:22:55+00:00","author":"oo7","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005:":"oo7","\u9810\u4f30\u95b1\u8b80\u6642\u9593":"1 \u5206\u9418"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.nickyoo7.com\/?p=250#article","isPartOf":{"@id":"https:\/\/www.nickyoo7.com\/?p=250"},"author":{"name":"oo7","@id":"https:\/\/www.nickyoo7.com\/#\/schema\/person\/2ab2a209159a41a5c551869792fd0367"},"headline":"iOS \u5efa\u7acb\u9060\u8ddd\u63a8\u64ad App (\u4e94) \u63a8\u64ad\u6e2c\u8a66 \u2013 \u4f7f\u7528 php","datePublished":"2023-10-20T05:22:55+00:00","mainEntityOfPage":{"@id":"https:\/\/www.nickyoo7.com\/?p=250"},"wordCount":15,"articleSection":["iOS \u958b\u767c","PHP"],"inLanguage":"zh-TW"},{"@type":"WebPage","@id":"https:\/\/www.nickyoo7.com\/?p=250","url":"https:\/\/www.nickyoo7.com\/?p=250","name":"iOS \u5efa\u7acb\u9060\u8ddd\u63a8\u64ad App (\u4e94) \u63a8\u64ad\u6e2c\u8a66 \u2013 \u4f7f\u7528 php - oo7&#039;s World","isPartOf":{"@id":"https:\/\/www.nickyoo7.com\/#website"},"datePublished":"2023-10-20T05:22:55+00:00","author":{"@id":"https:\/\/www.nickyoo7.com\/#\/schema\/person\/2ab2a209159a41a5c551869792fd0367"},"breadcrumb":{"@id":"https:\/\/www.nickyoo7.com\/?p=250#breadcrumb"},"inLanguage":"zh-TW","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.nickyoo7.com\/?p=250"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.nickyoo7.com\/?p=250#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9801","item":"https:\/\/www.nickyoo7.com\/"},{"@type":"ListItem","position":2,"name":"iOS \u5efa\u7acb\u9060\u8ddd\u63a8\u64ad App (\u4e94) \u63a8\u64ad\u6e2c\u8a66 \u2013 \u4f7f\u7528 php"}]},{"@type":"WebSite","@id":"https:\/\/www.nickyoo7.com\/#website","url":"https:\/\/www.nickyoo7.com\/","name":"oo7&#039;s World","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.nickyoo7.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-TW"},{"@type":"Person","@id":"https:\/\/www.nickyoo7.com\/#\/schema\/person\/2ab2a209159a41a5c551869792fd0367","name":"oo7","image":{"@type":"ImageObject","inLanguage":"zh-TW","@id":"https:\/\/secure.gravatar.com\/avatar\/e2ffdb3c64d0daa8a28af5806bcb94e283c27974a48761397038108203287e0d?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/e2ffdb3c64d0daa8a28af5806bcb94e283c27974a48761397038108203287e0d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e2ffdb3c64d0daa8a28af5806bcb94e283c27974a48761397038108203287e0d?s=96&d=mm&r=g","caption":"oo7"}}]}},"_links":{"self":[{"href":"https:\/\/www.nickyoo7.com\/index.php?rest_route=\/wp\/v2\/posts\/250","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nickyoo7.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nickyoo7.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nickyoo7.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nickyoo7.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=250"}],"version-history":[{"count":1,"href":"https:\/\/www.nickyoo7.com\/index.php?rest_route=\/wp\/v2\/posts\/250\/revisions"}],"predecessor-version":[{"id":251,"href":"https:\/\/www.nickyoo7.com\/index.php?rest_route=\/wp\/v2\/posts\/250\/revisions\/251"}],"wp:attachment":[{"href":"https:\/\/www.nickyoo7.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=250"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nickyoo7.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=250"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nickyoo7.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=250"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}