{"id":5358,"date":"2021-10-25T01:22:39","date_gmt":"2021-10-24T16:22:39","guid":{"rendered":"https:\/\/kumapress.com\/?p=5358"},"modified":"2021-10-25T01:58:42","modified_gmt":"2021-10-24T16:58:42","slug":"php%e3%81%aejson%e3%81%aepost%e9%80%9a%e4%bf%a1%e3%82%b5%e3%83%b3%e3%83%97%e3%83%ab%e3%81%a7%e3%81%99","status":"publish","type":"post","link":"https:\/\/kumapress.com\/?p=5358","title":{"rendered":"PHP\u306eJSON\u306ePOST\u901a\u4fe1\u30b5\u30f3\u30d7\u30eb\u3067\u3059"},"content":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\uff01<br \/>\n\u30b9\u30de\u30db\u30a2\u30d7\u30ea\u4f5c\u6210\u5bb6\u304f\u307e\u304b\u3051\u3067\u3059(^^)<\/p>\n<p>\u30ec\u30f3\u30bf\u30eb\u30b5\u30fc\u30d0\u30fc\u300c\u304f\u307e\u30d7\u30ec\u30b9\u300d\u3068\u306f\u3061\u304c\u3063\u3066\u3001OpenBlocks\u3092\u4f7f\u3063\u3066\u74b0\u5883\u69cb\u7bc9\u3092\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u666e\u6bb5\u306fCentOS\u3092\u4f7f\u3063\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001Debian\u74b0\u5883\u3082\u3088\u3046\u3084\u304f\u306a\u308c\u3066\u304d\u307e\u3057\u305f(^^;<br \/>\n\u3055\u3066\u4eca\u56de\u306fPHP\u3067\u4f5c\u6210\u3057\u305fAPI\u306b\u3064\u3044\u3066\u3001\u3053\u308c\u3082PHP\u304b\u3089JSON\u3067POST\u3059\u308b\u3053\u3068\u304c\u6709\u308a\u307e\u3057\u305f\u3002<br \/>\n\u4eca\u56de\u3053\u308c\u306b\u3001\u5927\u3044\u306b\u306f\u3081\u3089\u308c\u305f\u306e\u3067\u3001\u5fd8\u308c\u306a\u3044\u3088\u3046\u306b\u3068\u601d\u3044\u30e1\u30e2\u308a\u307e\u3059\u3002<\/p>\n<p>\u9001\u53d7\u4fe1\u306e\u30b5\u30f3\u30d7\u30eb\u3067\u3059\u3002<br \/>\n\u9001\u4fe1\u5074<\/p>\n<pre class=\"lang:php decode:true \" title=\"\u9001\u4fe1\u30b5\u30f3\u30d7\u30eb\">&lt;?php\n$data = [\n    'token'      =&gt; '123456789A',\n    'kokyaku_id' =&gt; 'abcdefg',\n    'cvv'        =&gt; '123',\n    'rec'        =&gt; [\n        'rec01' =&gt; 'rec01',\n        'rec02' =&gt; 'rec02'\n    ]\n];\n\n$json = json_encode( $data );\n\n$ch = curl_init();\n\ncurl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application\/json'));\ncurl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');\ncurl_setopt($ch, CURLOPT_POSTFIELDS, $json );\ncurl_setopt($ch, CURLOPT_RETURNTRANSFER, true);\ncurl_setopt($ch, CURLOPT_URL, 'http:\/\/192.168.5.254\/api\/chk_cvv.php');\n\n$result = curl_exec( $ch );\n$res_json = json_decode( $result, true );\n\ncurl_close($ch);\n\nvar_dump( $res_json );<\/pre>\n<p>\u53d7\u4fe1\u5074<\/p>\n<pre class=\"lang:php decode:true\" title=\"\u53d7\u4fe1\u5074\u30b5\u30f3\u30d7\u30eb\">&lt;?php\n$json = file_get_contents(\"php:\/\/input\");\n\/\/var_dump( $json );\n\n$rcv = json_decode( $json, true );\n\n\/\/var_dump( $rcv );\n\n$data = [\n    'result' =&gt; true,\n    'msg_cd'   =&gt; $rcv['token'] . '-' . $rcv['rec']['rec01'],\n    'messsage' =&gt; '\u6b63\u5e38\u306b\u53d6\u5f97\u3067\u304d\u307e\u3057\u305f'\n];\n\nheader('Content-Type:application\/json');\necho json_encode( $data );\nexit;\n?&gt;<\/pre>\n<p>CURL\u3092\u4f7f\u3063\u3066\u3001POST\u9001\u4fe1\u3057\u3066\u3001\u53d7\u4fe1\u30c7\u30fc\u30bf\u306e\u4e00\u90e8\u3092JSON\u5f62\u5f0f\u3067\u8fd4\u5374\u3059\u308b\u30b5\u30f3\u30d7\u30eb\u3067\u3059\u3002<\/p>\n<p>\u9001\u4fe1\u5074\u3092\u30d6\u30e9\u30a6\u30b6\u3067\u547c\u3073\u51fa\u3059\u3068\u3001<br \/>\narray(3) { [&#8220;result&#8221;]=&gt; bool(true) [&#8220;msg_cd&#8221;]=&gt; string(16) &#8220;123456789A-rec01&#8221; [&#8220;messsage&#8221;]=&gt; string(30) &#8220;\u6b63\u5e38\u306b\u53d6\u5f97\u3067\u304d\u307e\u3057\u305f&#8221; }<br \/>\n\u3063\u3066\u3001\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u4eca\u56de\u30cf\u30de\u3063\u305f\u306e\u306f\u3001\u53d7\u4fe1\u306e\u201dphp:\/\/input\u201d\u306e\u90e8\u5206\u3067\u3059\u3002<br \/>\nPOST\u306a\u3093\u3067\u3001$_POST\u3067\u3084\u3063\u3066\u3066\u3001\u5168\u7136\u53d7\u4fe1\u304c\u3067\u304d\u306a\u304b\u3063\u305f\u3093\u3067\u3059\u3002<br \/>\n\u3067\u3001&#8221;http_build_query&#8221;\u3067\u5b9f\u88c5\u3057\u305f\u308a\u3057\u305f\u3093\u3067\u3059\u304c\u3001\u306a\u3093\u304b\u8ca0\u3051\u305f\u611f\u304c\u30e0\u30af\u30e0\u30af\u3068\u51fa\u3066\u304d\u3066\u3057\u307e\u3063\u3066\u3002\u3002\u3002(^^;<br \/>\n\u3067\u3001&#8221;php:\/\/input&#8221;\u3068\u51fa\u4f1a\u3044\u307e\u3057\u305f\u3002<\/p>\n<p>\u8aad\u307f\u8fbc\u307f\u5c02\u7528\u306e\u30b9\u30c8\u30ea\u30fc\u30e0\u3060\u3051\u3069\u3001enctype=&#8221;multipart\/form-data&#8221; \u306b\u5bfe\u3057\u3066\u306f\u4f7f\u7528\u3067\u304d\u306a\u3044\u306e\u3067\u3001\u753b\u50cf\u306a\u3093\u304b\u306e\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u304c\u3042\u308b\u3068\u304d\u306f\u4f7f\u3048\u306a\u3044\u307f\u305f\u3044\u3067\u3059\u3002<\/p>\n<p>\u3055\u3066\u3001\u30d5\u30a1\u30a4\u30c8\u3067\u3059\uff01<\/p>\n<aside class=\"row veu_insertAds after\"><div class=\"col-md-6\"><script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\r\n<!-- \u7b2c 1 \u9762 - 2\uff08www.kumapress.com\uff09 -->\r\n<ins class=\"adsbygoogle\"\r\n     style=\"display:block\"\r\n     data-ad-client=\"ca-pub-5987681888830890\"\r\n     data-ad-slot=\"5379270693\"\r\n     data-ad-format=\"auto\"\r\n     data-full-width-responsive=\"true\"><\/ins>\r\n<script>\r\n     (adsbygoogle = window.adsbygoogle || []).push({});\r\n<\/script><\/div><div class=\"col-md-6\"><script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\r\n<!-- \u7b2c 1 \u9762 - 1\uff08www.kumapress.com\uff09 -->\r\n<ins class=\"adsbygoogle\"\r\n     style=\"display:block\"\r\n     data-ad-client=\"ca-pub-5987681888830890\"\r\n     data-ad-slot=\"7353370294\"\r\n     data-ad-format=\"auto\"\r\n     data-full-width-responsive=\"true\"><\/ins>\r\n<script>\r\n     (adsbygoogle = window.adsbygoogle || []).push({});\r\n<\/script><\/div><\/aside>","protected":false},"excerpt":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\uff01 \u30b9\u30de\u30db\u30a2\u30d7\u30ea\u4f5c\u6210\u5bb6\u304f\u307e\u304b\u3051\u3067\u3059(^^) \u30ec\u30f3\u30bf\u30eb\u30b5\u30fc\u30d0\u30fc\u300c\u304f\u307e\u30d7\u30ec\u30b9\u300d\u3068\u306f\u3061\u304c\u3063\u3066\u3001OpenBlocks\u3092\u4f7f\u3063\u3066\u74b0\u5883\u69cb\u7bc9\u3092\u3057\u3066\u3044\u307e\u3059\u3002 \u666e\u6bb5\u306fCentOS\u3092\u4f7f\u3063\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001Debian\u74b0\u5883\u3082\u3088\u3046\u3084\u304f\u306a\u308c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5309,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"vkexunit_cta_each_option":"","footnotes":""},"categories":[6,126],"tags":[185,177],"class_list":["post-5358","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","category-blog-memo","tag-json","tag-php7-4"],"_links":{"self":[{"href":"https:\/\/kumapress.com\/index.php?rest_route=\/wp\/v2\/posts\/5358","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kumapress.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kumapress.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kumapress.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kumapress.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5358"}],"version-history":[{"count":2,"href":"https:\/\/kumapress.com\/index.php?rest_route=\/wp\/v2\/posts\/5358\/revisions"}],"predecessor-version":[{"id":5361,"href":"https:\/\/kumapress.com\/index.php?rest_route=\/wp\/v2\/posts\/5358\/revisions\/5361"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kumapress.com\/index.php?rest_route=\/wp\/v2\/media\/5309"}],"wp:attachment":[{"href":"https:\/\/kumapress.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5358"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kumapress.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5358"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kumapress.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5358"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}