This article describes the PHP method for post data uploading based on curl. Share to everyone for your reference. The implementation methods are as follows:
Copy Code code as follows:
Two-dimensional code
$QRCode _url= "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=". $ACC _token;
$data = ' {expire_seconds ': 1800, ' action_name ': ' Qr_scene ', ' action_info ': {' SCENE ': {' scene_id ': 123}}} ';
/*
$ch = Curl_init ($MENU _url);
curl_setopt ($ch, Curlopt_customrequest, "POST");
curl_setopt ($ch, Curlopt_postfields, $data);
curl_setopt ($ch, Curlopt_returntransfer, true);
curl_setopt ($ch, Curlopt_ssl_verifypeer, false);
curl_setopt ($ch, Curlopt_httpheader, Array (' Content-type:application/json ', ' content-length: '. strlen ($data)));
$info = curl_exec ($ch);
*/
Function post ($url, $params = false, $header = Array ()) {
$ch = Curl_init ();
$cookieFile = ' sdadsd_cookiejar.txt ';
curl_setopt ($ch, Curlopt_post, 1);
curl_setopt ($ch, curlopt_connecttimeout, 60);
curl_setopt ($ch, Curlopt_cookiejar, $cookieFile);
curl_setopt ($ch, Curlopt_cookiefile, $cookieFile);
curl_setopt ($ch, Curlopt_returntransfer, 1);
curl_setopt ($ch, curlopt_followlocation, 1);
curl_setopt ($ch, Curlopt_ssl_verifypeer,false);
curl_setopt ($ch, Curlopt_httpget, true);
curl_setopt ($ch, Curlopt_timeout, 30);
if ($params!== false) {curl_setopt ($ch, Curlopt_postfields, $params);}
curl_setopt ($ch, Curlopt_useragent, ' mozilla/5.0 (Windows NT 5.1; rv:21.0) gecko/20100101 firefox/21.0 ');
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, Curlopt_httpheader, $header);
$result = curl_exec ($ch);
Curl_close ($ch);
return $result;
}
$result = post ($QRCode _url, $data);
I hope this article will help you with your PHP program design.