public function _make_tmp_xcx_code() { // 查看是否已存储到数据库 $request_data = [ 'path' => "/pages/product_type/product_detail?id=100", // 注意是path , 不是page 'width' => 280 ]; $access_token = $this->_get_access_token(); if (!$access_token){ return false; } vendor('Func.Http'); //$url = "https://api.weixin.qq.com/wxa/getwxacode?access_token=" . $access_token; $request_url = 'https://api.weixin.qq.com/wxa/getwxacode?access_token='.$access_token; //$result = Http::doPostJson($request_url,$request_data); $request_data = json_encode($request_data); $result = $this->_requestPost($request_url, $request_data); $this->setlog([$request_url,$request_data],[$result,json_decode($result,true),$result->errcode,$result['errcode']],__METHOD__,'code.log'); $decode_result = json_decode($result,true); if ($decode_result['errcode']){ dump($decode_result); exit; } // 存入cdn $cdn_result = $this->upload_cdn($result,'suncode'); $this->setlog([],$cdn_result,__METHOD__.'__33','xcx_code.log'); dump($cdn_result); exit; } public function _requestPost($url, $data, $ssl=true) { //curl完成 $curl = curl_init(); //设置curl选项 curl_setopt($curl, CURLOPT_URL, $url);//URL $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ' Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0 FirePHP/0.7.4'; curl_setopt($curl, CURLOPT_USERAGENT, $user_agent);//user_agent,请求代理信息 curl_setopt($curl, CURLOPT_AUTOREFERER, true);//referer头,请求来源 curl_setopt($curl, CURLOPT_TIMEOUT, 30);//设置超时时间 //SSL相关 if ($ssl) { curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);//禁用后cURL将终止从服务端进行验证 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);//检查服务器SSL证书中是否存在一个公用名(common name)。 } // 处理post相关选项 curl_setopt($curl, CURLOPT_POST, true);// 是否为POST请求 curl_setopt($curl, CURLOPT_POSTFIELDS, $data);// 处理请求数据 // 处理响应结果 curl_setopt($curl, CURLOPT_HEADER, false);//是否处理响应头 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);//curl_exec()是否返回响应结果 // 发出请求 $response = curl_exec($curl); if (false === $response) { echo '<br>', curl_error($curl), '<br>'; return false; } curl_close($curl); return $response; }
<pre>array(3) {
["errno"] => string(1) "0"
["errmsg"] => string(2) "ok"
["save_name"] => string(46) "http://cdn.caomall.net/1567500276665758601.png"
}
</pre>