{"id":16689,"date":"2023-12-12T11:46:40","date_gmt":"2023-12-12T03:46:40","guid":{"rendered":"https:\/\/www.zhidianwl.com\/zhidian\/?p=16689"},"modified":"2023-12-12T11:46:40","modified_gmt":"2023-12-12T03:46:40","slug":"php%e5%bc%80%e5%8f%91%e5%ae%89%e5%8d%93app%e6%8e%a8%e9%80%81%e6%b6%88%e6%81%af%e6%80%8e%e4%b9%88%e5%bc%84%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.zhidianwl.com\/zhidian\/2023\/16689\/","title":{"rendered":"php\u5f00\u53d1\u5b89\u5353app\u63a8\u9001\u6d88\u606f\u600e\u4e48\u5f04\uff1f"},"content":{"rendered":"
Android\u7cfb\u7edf\u63d0\u4f9b\u4e86Google Cloud Messaging (GCM)\u7528\u4e8e\u5411\u79fb\u52a8\u8bbe\u5907\uff08Android \u8bbe\u5907\uff09\u53d1\u9001\u63a8\u9001\u901a\u77e5\u3002GCM \u670d\u52a1\u672c\u8eab\u652f\u6301 HTTP\/JSON\u534f\u8bae\uff0c\u6240\u4ee5\u53ef\u4ee5\u4f7f\u7528 PHP \u5f00\u53d1\u63a8\u9001\u901a\u77e5\u3002<\/p>\n
1. \u83b7\u53d6 Google Cloud Messaging API Key<\/p>\n
\u5728 Google \u63a7\u5236\u53f0\u7533\u8bf7\u751f\u6210\u4e00\u4e2a Google Cloud Messaging API Key\u3002\u751f\u6210\u5b8c\u6210\u540e\uff0c\u5c06 API Key \u5907\u4efd\u4e0b\u6765\u5907\u7528\u3002<\/p>\n
2. \u83b7\u53d6\u8bbe\u5907\u7684 Registration ID<\/p>\n
\u5f53\u5e94\u7528\u7b2c\u4e00\u6b21\u542f\u52a8\u65f6\uff0c\u5e94\u8be5\u901a\u8fc7 GCM \u5411\u670d\u52a1\u5668\u53d1\u9001\u4e00\u4e2a\u6ce8\u518c\u8bf7\u6c42\uff0c\u4ee5\u4fbf\u5728\u670d\u52a1\u5668\u4fdd\u5b58\u8bbe\u5907\u7684 Registration ID\u3002<\/p>\n
3. \u7f16\u5199 PHP \u4ee3\u7801\u8fdb\u884c\u6d88\u606f\u63a8\u9001<\/p>\n
“`php<\/p>\n<\/p>\n
\/\/ Replace with real client registration IDs<\/p>\n
$registrationIds = array( ‘registration_id_0’, ‘registration_id_1’ );<\/p>\n
\/\/ Message to be sent<\/p>\n
$message = “Your message here.”;<\/p>\n
\/\/ Set POST variables<\/p>\n
$url = ‘https:\/\/gcm-http.googleapis.com\/gcm\/send’;<\/p>\n
$fields = array(<\/p>\n
‘registration_ids’ => $registrationIds,<\/p>\n