{"id":105,"date":"2018-03-31T13:25:36","date_gmt":"2018-03-31T05:25:36","guid":{"rendered":"http:\/\/ihongchao.com\/?p=105"},"modified":"2018-04-01T10:00:51","modified_gmt":"2018-04-01T02:00:51","slug":"%e5%be%ae%e4%bf%a1%e5%85%ac%e4%bc%97%e5%8f%b7%e4%b8%8a%e4%bc%a0%e5%9b%be%e7%89%87%e7%9a%84php7%e9%80%82%e7%94%a8%e4%bb%a3%e7%a0%81%e7%89%87%e6%ae%b5","status":"publish","type":"post","link":"https:\/\/ihongchao.com\/post\/105\/","title":{"rendered":"\u5fae\u4fe1\u516c\u4f17\u53f7\u4e0a\u4f20\u56fe\u7247\u7684PHP7\u9002\u7528\u4ee3\u7801\u7247\u6bb5"},"content":{"rendered":"

\u901a\u8fc7\u5fae\u4fe1\u516c\u4f17\u5e73\u53f0API\u8fdb\u884c\u63a8\u9001\u7684\u7b2c\u4e00\u6b65\u5c31\u662f\u4e0a\u4f20\u6587\u7ae0\uff08\u56fe\u6587\u7d20\u6750\uff09\uff0c\u800c\u4e0a\u4f20\u56fe\u6587\u7d20\u6750\u7684\u7b2c\u4e00\u6b65\u5c31\u662f\u4e0a\u4f20\u9884\u89c8\u56fe\uff08thumb\uff09\u3002\u800c\u8fd9\u4e2a\u9884\u89c8\u56fe\u7684\u4e0a\u4f20\u5219\u56f0\u6270\u4e86\u6211\u4e00\u663c\u591c\uff0c\u4e00\u76f4\u56de\u663e\uff1a<\/p>\n

string(70) \"{\"errcode\":41005,\"errmsg\":\"media data missing hint: [BHVBhA03833064]\"}\"<\/pre>\n

\u4e5f\u5c31\u662f\u7f3a\u5c11\u8d44\u6e90\u6587\u4ef6\u3002\u4e0d\u8fc7\u597d\u5728\uff0c\u95ee\u9898\u6700\u7ec8\u987a\u5229\u89e3\u51b3\u4e86\u3002\u73b0\u5c06\u4ee3\u7801\u8fdb\u884c\u8bb0\u5f55<\/p>\n

\u5f00\u53d1\u73af\u5883\uff1aCentOS 7.4 + Apache 2.4 + PHP 7.1.13\uff08php_mod\uff09<\/p>\n

cUrl\u4e0a\u4f20\u4ee3\u7801\u5982\u4e0b\uff0c\u8981\u6ce8\u610f\u7684\u662f\uff0c\u7531\u4e8e\u63d2\u4ef6\u7684\u5173\u7cfb\uff0c\u4ee3\u7801\u4e2d\u7684”\/\/”\u5b9e\u9645\u4e3a”h-t-t-p-s:\/\/”\uff0c\u8bf7\u81ea\u884c\u8865\u5168\uff0c\u4ee5\u514d\u529f\u80fd\u51fa\u9519\uff1a<\/p>\n

 function http_post($url,$param){           \r\n\t $oCurl = curl_init();           \r\n\t if(stripos($url,\"https:\/\/\")!==FALSE){                   \r\n\t\t curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);                   \r\n\t\t curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false);           \r\n\t }          \r\n\t $strPOST = $param;          \r\n\t curl_setopt($oCurl, CURLOPT_URL, $url);           \r\n\t curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1 );           \r\n\t curl_setopt($oCurl, CURLOPT_POST,true);           \r\n\t curl_setopt($oCurl, CURLOPT_POSTFIELDS,$strPOST);          \r\n\t $sContent = curl_exec($oCurl);\r\n\t curl_close($oCurl);\r\n\t return $sContent;\r\n }<\/pre>\n

\u7136\u540e\u662f\u8c03\u7528\uff1a<\/p>\n

$access_token = 'https:\/\/ihongchao.com';\r\n$url = 'https:\/\/api.weixin.qq.com\/cgi-bin\/material\/add_material?access_token='.$access_token.'&type=thumb';\r\n$path = '..\/img\/test.jpg';\r\n$data = array('media' => new \\CURLFile(realpath($path)));\r\nvar_dump(http_post($url,$field));<\/pre>\n

\u4ee5\u4e0a\u53ef\u4ee5\u8bf4\u5c31\u662f\u4e00\u4e2a\u5b8c\u6574\u7684\u5b9e\u73b0\uff0c\u8fd0\u884c\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n

string(208) \"{\"media_id\":\"*******\",\"url\":\"*******\"}\"<\/pre>\n

\u5177\u4f53\u7684\u6211\u4e5f\u4e0d\u662f\u5f88\u61c2\uff0c\u53ea\u77e5\u9053PHP\u4ece5.5\u5f00\u59cb\u5bf9curl\u4e0a\u4f20\u505a\u51fa\u4e86\u8c03\u6574\uff0c\u589e\u52a0\u4e86CURLFile\u7c7b\uff0c\u5e76\u4ecePHP5.6\u5f00\u59cb\u79fb\u9664\u4e86@\u65b9\u6cd5\u3002\u7136\u800c\u7f51\u4e0a\u7684\u6587\u7ae0\u90fd\u662f\u590d\u5236\u7c98\u8d34\uff0c\u5927\u90e8\u5206\u662f\u8001\u4ee3\u7801\uff0c\u65b0\u7248\u672c\u7684PHP\u6839\u672c\u4e0d\u80fd\u7528\uff0c\u90e8\u5206\u9002\u7528\u65b0\u7248\u672c\u7684\u4ee3\u7801\u53c8\u6216\u591a\u6216\u5c11\u5b58\u5728\u9519\u8bef\u3002\u6700\u540e\u7ec8\u4e8e\u5728sf\u4e2d\u627e\u5230\u4e86\u6bd4\u8f83\u8be6\u7ec6\u7684\u89e3\u91ca\uff0c\u4e8e\u662f\u4e0a\u4f20\u8bf7\u6c42\u5c31\u5f97\u5230\u4e86\u6b63\u5e38\u7684\u54cd\u5e94\u3002<\/p>\n

P.S.\uff1a\u56e0\u4e3a\u6211\u7528\u7684\u662f\u63a5\u53e3\u6d4b\u8bd5\u5e73\u53f0\uff0c\u6240\u4ee5\u6ca1\u6709\u7fa4\u53d1\u6743\u9650\uff0c\u4e0a\u4f20\u540e\u53ea\u80fd\u901a\u8fc7\u9884\u89c8\u63a5\u53e3\u63a8\u9001\u81f3\u624b\u673a\uff0c\u6bcf\u5929100\u6b21\uff0c\u5751\u7239\u2584\u2588\u2580\u2588\u25cf<\/p>\n","protected":false},"excerpt":{"rendered":"

\u901a\u8fc7\u5fae\u4fe1\u516c\u4f17\u5e73\u53f0API\u8fdb\u884c\u63a8\u9001\u7684\u7b2c\u4e00\u6b65\u5c31\u662f\u4e0a\u4f20\u6587\u7ae0\uff08\u56fe\u6587\u7d20\u6750\uff09\uff0c\u800c\u4e0a\u4f20\u56fe\u6587\u7d20\u6750\u7684\u7b2c\u4e00\u6b65\u5c31\u662f\u4e0a\u4f20\u9884\u89c8\u56fe\uff08thum … \u7ee7\u7eed\u9605\u8bfb\u5fae\u4fe1\u516c\u4f17\u53f7\u4e0a\u4f20\u56fe\u7247\u7684PHP7\u9002\u7528\u4ee3\u7801\u7247\u6bb5<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[26,25],"_links":{"self":[{"href":"https:\/\/ihongchao.com\/wp-json\/wp\/v2\/posts\/105"}],"collection":[{"href":"https:\/\/ihongchao.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ihongchao.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ihongchao.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ihongchao.com\/wp-json\/wp\/v2\/comments?post=105"}],"version-history":[{"count":11,"href":"https:\/\/ihongchao.com\/wp-json\/wp\/v2\/posts\/105\/revisions"}],"predecessor-version":[{"id":116,"href":"https:\/\/ihongchao.com\/wp-json\/wp\/v2\/posts\/105\/revisions\/116"}],"wp:attachment":[{"href":"https:\/\/ihongchao.com\/wp-json\/wp\/v2\/media?parent=105"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ihongchao.com\/wp-json\/wp\/v2\/categories?post=105"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ihongchao.com\/wp-json\/wp\/v2\/tags?post=105"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}