

{"id":263,"date":"2023-09-19T17:39:28","date_gmt":"2023-09-19T09:39:28","guid":{"rendered":"https:\/\/www.01j.top\/?p=263"},"modified":"2023-09-19T17:41:42","modified_gmt":"2023-09-19T09:41:42","slug":"php-%e5%ae%9e%e7%8e%b0%e5%be%ae%e4%bf%a1%e5%b0%8f%e7%a8%8b%e5%ba%8f%e6%95%8f%e6%84%9f%e5%9b%be%e7%89%87%e3%80%81%e5%86%85%e5%ae%b9%e6%a3%80%e6%b5%8b%e6%8e%a5%e5%8f%a3","status":"publish","type":"post","link":"https:\/\/www.01j.top\/?p=263","title":{"rendered":"PHP \u5b9e\u73b0\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u654f\u611f\u56fe\u7247\u3001\u5185\u5bb9\u68c0\u6d4b\u63a5\u53e3"},"content":{"rendered":"\n<h2 id=\"h2-0\">php\u540e\u7aef\u6e90\u7801-\u4e3b\u8981\u662f\u4e3a\u4e86\u8c03\u7528\u5fae\u4fe1\u5c0f\u7a0b\u5e8fmsgSecCheck\u3001imgSecCheck\u63a5\u53e3\u3002<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>        \u5148\u9644\u4e0a\u5c0f\u7a0b\u5e8f\u63a5\u53e3\u8bf4\u660e\u6587\u6863\u5730\u5740\uff1ahttps:\/\/developers.weixin.qq.com\/miniprogram\/dev\/api\/open-api\/sec-check\/msgSecCheck.html\r\n        1\u3001\u9996\u5148\u8981\u83b7\u53d6access_token\uff08\u9700\u8981appId\u3001appSecret\u3001grant_type\u8fd9\u4e2a\u662f\u56fa\u5b9a\u503c\uff09\uff1b\r\n        ###msgSecCheck\u63a5\u53e3\uff1a\r\n        2\u3001\u7528\u83b7\u53d6\u5230\u7684token\u5e26\u5165\u5230\u5fae\u4fe1\u7aef\u7684\u63a5\u53e3\u5730\u5740\uff1a https:\/\/api.weixin.qq.com\/wxa\/msg_sec_check?access_token=ACCESS_TOKEN\u3002\r\n            \u8fd9\u91cc\u9700\u8981\u6ce8\u610f\u7684\u662f\uff1a 1\u3001message\u4fe1\u606f\u7684\u683c\u5f0f\u8981\u662fJSON\u683c\u5f0f\uff0c\u4e0d\u80fd\u76f4\u63a5\u4f20string\uff0c\u4e0d\u7136\u4f1a\u62a5 47001\uff0cdata format error hin \u9519\u8bef\u3002\r\n       ###imgSecCheck\u63a5\u53e3\uff1a\r\n        3\u3001\u7528\u83b7\u53d6\u5230\u7684token\u5e26\u5165\u5230\u5fae\u4fe1\u7aef\u7684\u63a5\u53e3\u5730\u5740\uff1ahttps:\/\/api.weixin.qq.com\/wxa\/img_sec_check?access_token=ACCESS_TOKEN\u3002\r\n            \u8fd9\u91cc\u9700\u8981\u6ce8\u610f\u7684\u662f\uff1a 1\u3001image\u7684\u683c\u5f0f\u8981\u662fformdata \u683c\u5f0f\uff0c\u4e0d\u80fd\u76f4\u63a5\u4f20url\uff0c\u4e0d\u7136\u4f1a\u62a5 41005\uff0cmedia data missing hin \u9519\u8bef\u3002\u53c2\u6570\u540d\u5e94\u8be5\u4f7f\u7528\uff1amedia\uff0c\u8fd9\u662f\u5c0f\u7a0b\u5e8f\u5b9a\u597d\u7684\u3002\r\n            \u6211\u8fd9\u91cc\u662f\u83b7\u53d6\u5230\u5fae\u4fe1\u4e0a\u4f20\u7684\u56fe\u7247\u7684url,\u7136\u540e\u628a\u5b83\u4e0b\u8f7d\u5230\u4e00\u4e2a\u5b58\u653e\u4e34\u65f6\u6587\u4ef6\u7684\u533a\/dev\/shm\uff0c\u7136\u540e\u518d\u8f6c\u4e3acurlFile()\u5bf9\u8c61 \u3002\r\n        \u9644\u4e0a\u5177\u4f53\u4ee3\u7801\uff1a\r\n  \r\n         \/*\u5fae\u4fe1\u56fe\u7247\u654f\u611f\u5185\u5bb9\u68c0\u6d4b*\/\r\n    public function imgSecCheck($img)\r\n    {\r\n        $img = file_get_contents($img);\r\n        $filePath = '\/dev\/shm\/tmp1.png';\r\n        file_put_contents($filePath, $img);\r\n        $obj = new CURLFile(realpath($filePath));\r\n        $obj->setMimeType(\"image\/jpeg\");\r\n        $file&#91;'media'] = $obj;\r\n        $token = $this->getAccessToken();\r\n        $url = \"https:\/\/api.weixin.qq.com\/wxa\/img_sec_check?access_token=$token\";\r\n        $info = $this->http_request($url,$file);\r\n        return json_decode($info,true);\r\n    }\r\n \r\n    \/*\u5fae\u4fe1\u6587\u5b57\u654f\u611f\u5185\u5bb9\u68c0\u6d4b*\/\r\n    public function msgSecCheck($msg)\r\n    {\r\n        $token = $this->getAccessToken();\r\n        $url = \"https:\/\/api.weixin.qq.com\/wxa\/msg_sec_check?access_token=$token\";\r\n        $info = $this->http_request($url,json_encode($msg));\r\n        return json_decode($info,true);\r\n    }\r\n \r\n    \/*\u83b7\u53d6access_token,\u4e0d\u80fd\u7528\u4e8e\u83b7\u53d6\u7528\u6237\u4fe1\u606f\u7684token*\/\r\n    public function getAccessToken()\r\n    {\r\n        $token_file = '\/dev\/shm\/heka_token.json';\r\n        $data = json_decode(file_get_contents($token_file));\r\n        if ($data->expire_time &lt; time()) {\r\n            $url = \"https:\/\/api.weixin.qq.com\/cgi-bin\/token?grant_type=client_credential&amp;appid=$this->appId&amp;secret=$this->appSecret\";\r\n            $res = json_decode($this->http_request($url));\r\n            $access_token = $res->access_token;\r\n            if ($access_token) {\r\n                $data->expire_time = time() + 7000;\r\n                $data->access_token = $access_token;\r\n                file_put_contents($token_file, json_encode($data));\r\n            }\r\n        } else {\r\n            $access_token = $data->access_token;\r\n        }\r\n        return $access_token;\r\n    }\r\n \r\n \r\n    \/\/HTTP\u8bf7\u6c42\uff08\u652f\u6301HTTP\/HTTPS\uff0c\u652f\u6301GET\/POST\uff09\r\n    private function http_request($url, $data = null)\r\n    {\r\n        $curl = curl_init();\r\n        curl_setopt($curl, CURLOPT_URL, $url);\r\n        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);\r\n        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);\r\n \r\n        if (!empty($data)) {\r\n            curl_setopt($curl, CURLOPT_POST, TRUE);\r\n            curl_setopt($curl, CURLOPT_POSTFIELDS,$data);\r\n        }\r\n        curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);\r\n        $output = curl_exec($curl);\r\n        curl_close($curl);\r\n        file_put_contents('\/tmp\/heka_weixin.' . date(\"Ymd\") . '.log', date('Y-m-d H:i:s') . \"\\t\" . $output . \"\\n\", FILE_APPEND);\r\n        return $output;\r\n    }<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>php\u540e\u7aef\u6e90\u7801-\u4e3b\u8981\u662f\u4e3a\u4e86\u8c03\u7528\u5fae\u4fe1\u5c0f\u7a0b\u5e8fmsgSecCheck\u3001imgSecCheck\u63a5\u53e3\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[42],"tags":[],"_links":{"self":[{"href":"https:\/\/www.01j.top\/index.php?rest_route=\/wp\/v2\/posts\/263"}],"collection":[{"href":"https:\/\/www.01j.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.01j.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.01j.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.01j.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=263"}],"version-history":[{"count":1,"href":"https:\/\/www.01j.top\/index.php?rest_route=\/wp\/v2\/posts\/263\/revisions"}],"predecessor-version":[{"id":264,"href":"https:\/\/www.01j.top\/index.php?rest_route=\/wp\/v2\/posts\/263\/revisions\/264"}],"wp:attachment":[{"href":"https:\/\/www.01j.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.01j.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.01j.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}