One background
The development interface of WeChat public account usually uses http request, selects http/https protocol, supports curl command to get or post data;
two php function cURL function
🎜Three PHP Get and Post implementation🎜01 Initialize cURL Session, return handle;
void curl_close ( resource $ch )resource curl_init ([ string $url = NULL ] )
02 Set a cURL transfer option;bool curl_setopt ( resource $ch , int $option , mixed $value )
ex: curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); <br> //Return the information obtained by curl_exec() in the form of a file stream instead of outputting it directly.
03 Execute cURL sessionmixed curl_exec ( resource $ch )
mixed curl_exec ( resource $ch )
04 Close a cURL session and release all resources. The cURL handle ch will also be releasedvoid curl_close ( resource $ch )
Get // Scenario 1: Upload picture materials to WeChat server
`ch=curli nit( ); access_token; //Interface call credentials; need to be obtained actively;typ e=“ image"; url = "http://file.api.weixin.qq.com/cgi-bin/media/ upload?access_token=access_token&type=type”;
$filepath = dirname(FILE)."test.jpg";filedata =a rray("media"= >" @". filepath);
curl_setopt(ch,CURLOP TU RL, url); // Required
curl_setopt(ch,CURLOP TR ETURNTRANSFER ,1) " curl setopt(ch, CURLOPT_POST,1); // post data curl_setopt(ch,CURLOP TP // post variable curl_setopt(ch,CURLOP TH EADER,0) ;output = curl_exec( ch) ;curl_close(ch);va rd u mp(output); // Decompress json data packet; outputa rray= jsondecode ( output,true ); d
=output_array[" media_id”]; echo $media_id; "Post // Download picture material (part CODE) from WeChat server access t
oken;// pick up口 Add with with Certificate; Need WantMasterMove GetGet ; media_id; // Obtained when uploading picture material; $url = "http://file.api.weixin.qq.com/ cgi-bin/media/get?access_token=$access_token&media_id=$media_id"; $ch =curl_init(); curl_setopt($ch,CURLOPT_URL,$URL); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); $output = curl_exec($ch); curl_close($ch); ').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); }); The above introduces PHP feature 01: cURL implements get and post, and performs data interaction between URLs; including aspects of the content, I hope it will be helpful to friends who are interested in PHP tutorials.