{"id":3306,"date":"2021-03-11T17:11:02","date_gmt":"2021-03-11T08:11:02","guid":{"rendered":"https:\/\/taitan916.info\/blog\/?p=3306"},"modified":"2024-02-27T18:10:40","modified_gmt":"2024-02-27T09:10:40","slug":"post-3306","status":"publish","type":"post","link":"https:\/\/taitan916.info\/blog\/archives\/3306","title":{"rendered":"PHP\u3068LINE\u3092\u9023\u643a\u3055\u305b\u3066\u901a\u77e5\u3092\u9001\u308b\u65b9\u6cd5(file_get_contents \/ curl\u306e2\u30d1\u30bf\u30fc\u30f3)"},"content":{"rendered":"<p>PHP\u3068LINE\u3092\u9023\u643a\u3055\u305b\u3001LINE\u306b\u4f55\u3089\u304b\u306e\u901a\u77e5\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u9001\u4fe1\u3057\u305f\u3044\u3002\u4ee5\u4e0b\u306b\u65b9\u6cd5\u3092\u30e1\u30e2\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2><span id=\"LINE_Notify\">LINE Notify\u5074\u306e\u4f5c\u696d<\/span><\/h2>\n<p>\u4ee5\u4e0b\u306e\u904e\u53bb\u8a18\u4e8b\u53c2\u7167\u3002<\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"RVRK74lAEu\"><p><a href=\"https:\/\/taitan916.info\/blog\/archives\/3301\">GAS\u3068LINE\u3092\u9023\u643a\u3055\u305b\u3066\u901a\u77e5\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u9001\u308b\u65b9\u6cd5\u306e\u30e1\u30e2<\/a><\/p><\/blockquote>\n<p><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;GAS\u3068LINE\u3092\u9023\u643a\u3055\u305b\u3066\u901a\u77e5\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u9001\u308b\u65b9\u6cd5\u306e\u30e1\u30e2&#8221; &#8212; \u52c9\u5f37\u3057\u305f\u3053\u3068\u306e\u30e1\u30e2\" src=\"https:\/\/taitan916.info\/blog\/archives\/3301\/embed#?secret=1fb66WdjWU#?secret=RVRK74lAEu\" data-secret=\"RVRK74lAEu\" width=\"580\" height=\"327\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<h2>PHP\u5074\u306e\u4f5c\u696d<\/h2>\n<p>\u4ee5\u4e0b\u30bd\u30fc\u30b9\u3092\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3057\u3066\u30d6\u30e9\u30a6\u30b6\u304b\u3089\u8868\u793a(\u5b9f\u884c)\u3059\u308b\u3002<\/p>\n<h3>file_get_contents\u306e\u5834\u5408<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;?php\r\n\/\/\u30e1\u30c3\u30bb\u30fc\u30b8\u5185\u5bb9\r\n$message = '\u901a\u77e5\u30e1\u30c3\u30bb\u30fc\u30b8';\r\n\r\n\/\/LINE\u304b\u3089\u53d6\u5f97\u3057\u305f\u30c8\u30fc\u30af\u30f3\r\n$token = 'xxxxxxxxxxxxxxxxxx';\r\n\r\n\/\/API\u306eURL\r\n$url = 'https:\/\/notify-api.line.me\/api\/notify';\r\n\r\n$query = array(\r\n    'message' =&gt; $message, \r\n);\r\n \r\n\/\/URL\u30a8\u30f3\u30b3\u30fc\u30c9\u3055\u308c\u305f\u30af\u30a8\u30ea\u6587\u5b57\u5217\u3092\u751f\u6210\r\n$content = http_build_query($query, '', '&amp;');\r\n \r\n\/\/\u30d8\u30c3\u30c0\u8a2d\u5b9a\r\n$header = array(\r\n    'Content-Type: application\/x-www-form-urlencoded', \/\/form\u9001\u4fe1\u306e\u969b\u3001\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u304cWeb\u30b5\u30fc\u30d0\u30fc\u306b\u9001\u4fe1\u3059\u308b\u30b3\u30f3\u30c6\u30f3\u30c4\u30bf\u30a4\u30d7\r\n    'Content-Length: '.strlen($content), \/\/\u30e1\u30c3\u30bb\u30fc\u30b8\u672c\u6587\u306e\u9577\u3055\r\n    'Authorization: Bearer ' . $token,\r\n);\r\n \r\n\/\/\u30b9\u30c8\u30ea\u30fc\u30e0\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u8a2d\u5b9a\r\n$context = array(\r\n    'http' =&gt; array(\r\n        'ignore_errors' =&gt; true, \/\/\u30b9\u30c6\u30fc\u30bf\u30b9\u30b3\u30fc\u30c9\u304c\u5931\u6557\u3092\u610f\u5473\u3059\u308b\u5834\u5408\u3067\u3082\u30b3\u30f3\u30c6\u30f3\u30c4\u3092\u53d6\u5f97\r\n        'method' =&gt; 'POST', \/\/\u30e1\u30bd\u30c3\u30c9\u3002\u30c7\u30d5\u30a9\u30eb\u30c8\u306fGET\r\n        'header' =&gt; implode(\"\\r\\n\", $header), \/\/\u30d8\u30c3\u30c0\u8a2d\u5b9a\r\n        'content' =&gt; $content \/\/\u9001\u4fe1\u3057\u305f\u3044\u30c7\u30fc\u30bf\r\n    )\r\n);\r\n$res = file_get_contents($url, false, stream_context_create($context));\r\nvar_dump($res); \/\/string(29) \"{\"status\":200,\"message\":\"ok\"}\"<\/pre>\n<h3>curl\u306e\u5834\u5408<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;?php\r\n\/\/\u30e1\u30c3\u30bb\u30fc\u30b8\u5185\u5bb9\r\n$message = '\u901a\u77e5\u30e1\u30c3\u30bb\u30fc\u30b8';\r\n\r\n\/\/LINE\u304b\u3089\u53d6\u5f97\u3057\u305f\u30c8\u30fc\u30af\u30f3\r\n$token = 'xxxxxxxxxxxxxxxxxx';\r\n\r\n\/\/API\u306eURL\r\n$url = 'https:\/\/notify-api.line.me\/api\/notify';\r\n\r\n\/\/\u30e1\u30c3\u30bb\u30fc\u30b8\u3068\u30d8\u30c3\u30c0\u30fc\u8a2d\u5b9a\r\n$query = http_build_query(['message' =&gt; $message]);\r\n$header = [\r\n    'Content-Type: application\/x-www-form-urlencoded',\r\n    'Authorization: Bearer ' . $token,\r\n    'Content-Length: ' . strlen($query)\r\n];\r\n\r\n$options = [\r\n    CURLOPT_RETURNTRANSFER =&gt; true,\r\n    CURLOPT_POST =&gt; true,\r\n    CURLOPT_HTTPHEADER =&gt; $header,\r\n    CURLOPT_POSTFIELDS =&gt; $query\r\n];\r\n\r\ncurl_setopt_array($url, $options);\r\nvar_dump(curl_exec($ch)); \/\/string(29) \"{\"status\":200,\"message\":\"ok\"}\" \r\ncurl_close($ch);<\/pre>\n<p>&nbsp;<\/p>\n<h2>\u6240\u611f<\/h2>\n<p><a href=\"https:\/\/taitan916.info\/blog\/archives\/3301#LINE_Notify\" target=\"_blank\" rel=\"noopener\">GAS\u3068\u9023\u643a\u3055\u305b\u308b<\/a>\u3088\u308a\u3082\u82e5\u5e72\u9762\u5012\u306a\u3082\u306e\u306e\u3001PHP\u3060\u3068\u958b\u767a\u3057\u305f\u30b7\u30b9\u30c6\u30e0\u3068\u9023\u643a\u3057\u3066\u4f7f\u3046\u969b\u306b\u67d4\u8edf\u306b\u5bfe\u5fdc\u3067\u304d\u305d\u3046\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u53c2\u8003\u30b5\u30a4\u30c8<\/h2>\n<p><a href=\"https:\/\/panda-program.com\/posts\/use-line-notify-api-by-php-curl\" target=\"_blank\" rel=\"noopener\">https:\/\/panda-program.com\/posts\/use-line-notify-api-by-php-curl<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP\u3068LINE\u3092\u9023\u643a\u3055\u305b\u3001LINE\u306b\u4f55\u3089\u304b\u306e\u901a\u77e5\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u9001\u4fe1\u3057\u305f\u3044\u3002\u4ee5\u4e0b\u306b ... <\/p>\n","protected":false},"author":1,"featured_media":4313,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[98],"class_list":["post-3306","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-line"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/3306","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/comments?post=3306"}],"version-history":[{"count":5,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/3306\/revisions"}],"predecessor-version":[{"id":5172,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/3306\/revisions\/5172"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media\/4313"}],"wp:attachment":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media?parent=3306"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/categories?post=3306"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/tags?post=3306"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}