{"id":245,"date":"2023-10-18T14:31:20","date_gmt":"2023-10-18T06:31:20","guid":{"rendered":"https:\/\/www.nickyoo7.com\/?p=245"},"modified":"2023-10-18T14:39:49","modified_gmt":"2023-10-18T06:39:49","slug":"ios-%e5%bb%ba%e7%ab%8b%e9%81%a0%e8%b7%9d%e6%8e%a8%e6%92%ad-app-%e5%9b%9b-%e6%8e%a8%e6%92%ad%e6%b8%ac%e8%a9%a6-%e4%bd%bf%e7%94%a8-mac-%e7%b5%82%e7%ab%af%e6%a9%9f","status":"publish","type":"post","link":"https:\/\/www.nickyoo7.com\/?p=245","title":{"rendered":"iOS \u5efa\u7acb\u9060\u8ddd\u63a8\u64ad App (\u56db) \u63a8\u64ad\u6e2c\u8a66 &#8211; \u4f7f\u7528 mac \u7d42\u7aef\u6a5f"},"content":{"rendered":"<p>iOS \u5efa\u7acb\u9060\u8ddd\u63a8\u64ad App (\u56db) \u63a8\u64ad\u6e2c\u8a66 &#8211; \u4f7f\u7528 mac \u7d42\u7aef\u6a5f<br \/>\n<!--more-->\u5c07\u4e0b\u5217\u7a0b\u5f0f\u78bc\u4f9d\u9700\u6c42\u586b\u5165\u5c0d\u61c9\u7684\u8cc7\u6599\uff0c\u4e26\u5b58\u6210 token_send.sh<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">TEAM_ID= #\u958b\u767c\u8005ID(\u5728\u5e33\u865f\u8cc7\u6599\u53f3\u4e0a\u89d2)\r\nTOKEN_KEY_FILE_NAME= #p8\u683c\u5f0f\u7684 Keys\r\nAUTH_KEY_ID= Keys \u7684 ID\r\nTOPIC= #App \u7684 Bundle Iden\r\nDEVICE_TOKEN= #\u4f7f\u7528\u8005\u8a2d\u5099\u7684DEVICE_TOKEN\r\nAPNS_HOST_NAME=api.sandbox.push.apple.com\r\n\r\n\r\nJWT_ISSUE_TIME=$(date +%s)\r\nJWT_HEADER=$(printf '{ \"alg\": \"ES256\", \"kid\": \"%s\" }' \"${AUTH_KEY_ID}\" | openssl base64 -e -A | tr -- '+\/' '-_' | tr -d =)\r\nJWT_CLAIMS=$(printf '{ \"iss\": \"%s\", \"iat\": %d }' \"${TEAM_ID}\" \"${JWT_ISSUE_TIME}\" | openssl base64 -e -A | tr -- '+\/' '-_' | tr -d =)\r\nJWT_HEADER_CLAIMS=\"${JWT_HEADER}.${JWT_CLAIMS}\"\r\nJWT_SIGNED_HEADER_CLAIMS=$(printf \"${JWT_HEADER_CLAIMS}\" | openssl dgst -binary -sha256 -sign \"${TOKEN_KEY_FILE_NAME}\" | openssl base64 -e -A | tr -- '+\/' '-_' | tr -d =)\r\nAUTHENTICATION_TOKEN=\"${JWT_HEADER}.${JWT_CLAIMS}.${JWT_SIGNED_HEADER_CLAIMS}\"\r\n\r\nPAYLOAD='\r\n{\r\n    \"aps\": {\r\n        \"alert\": {\r\n            \"title\": \"\u975e\u6d32\u5927\u8349\u539f\",\r\n            \"subtitle\": \"\u80af\u4e9e\",\r\n            \"body\": \"\u5927\u8c61\u4e00\u96bb\"\r\n        },\r\n        \"badge\": 10,\r\n        \"sound\": \"default\",\r\n        \"content-available\" : 1\r\n            },\r\n}\r\n'\r\necho $JWT_ISSUE_TIME\r\ncurl -v \\\r\n    --header \"apns-collapse-id: oo7\" \\\r\n    --header \"apns-topic: $TOPIC\" \\\r\n    --header \"apns-push-type: alert\" \\\r\n    --header \"authorization: bearer $AUTHENTICATION_TOKEN\" \\\r\n    --data \"$PAYLOAD\" \\\r\n    --http2 https:\/\/${APNS_HOST_NAME}\/3\/device\/${DEVICE_TOKEN}\r\n\r\n#curl -v --header \"apns-topic: $TOPIC\" --header \"apns-push-type: alert\" --header \"authorization: bearer $AUTHENTICATION_TOKEN\" --data \"$PAYLOAD\" --http2 https:\/\/${APNS_HOST_NAME}\/3\/device\/${DEVICE_TOKEN}<\/pre>\n<p>\u5c07 \u53d6\u5f97 \u7684 p8 \u683c\u5f0f\u7684 Key \u548c token_send.sh \u653e\u5728\u540c\u4e00\u76ee\u9304\u3002(\u5efa\u8b70\u4e0d\u8981\u6709\u4e2d\u6587)<br \/>\n\u57f7\u884c\u4e0b\u5217\u6307\u4ee4\u6e2c\u8a66 :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">source .\/token_send.sh<\/pre>\n<p>&nbsp;<\/p>\n<p>\u76f8\u95dc PAYLOAD \u7684\u503c\u53ef\u53c3\u8003 : <a href=\"https:\/\/developer.apple.com\/documentation\/usernotifications\/setting_up_a_remote_notification_server\/generating_a_remote_notification\">https:\/\/developer.apple.com\/documentation\/usernotifications\/setting_up_a_remote_notification_server\/generating_a_remote_notification<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>iOS \u5efa\u7acb\u9060\u8ddd\u63a8\u64ad App (\u56db) \u63a8\u64ad\u6e2c\u8a66 &#8211; \u4f7f\u7528 mac \u7d42\u7aef\u6a5f<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[],"class_list":["post-245","post","type-post","status-publish","format-standard","hentry","category-ios","entry"],"_links":{"self":[{"href":"https:\/\/www.nickyoo7.com\/index.php?rest_route=\/wp\/v2\/posts\/245","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=245"}],"version-history":[{"count":3,"href":"https:\/\/www.nickyoo7.com\/index.php?rest_route=\/wp\/v2\/posts\/245\/revisions"}],"predecessor-version":[{"id":248,"href":"https:\/\/www.nickyoo7.com\/index.php?rest_route=\/wp\/v2\/posts\/245\/revisions\/248"}],"wp:attachment":[{"href":"https:\/\/www.nickyoo7.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=245"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nickyoo7.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=245"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nickyoo7.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=245"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}