This example describes the way PHP submits and obtains data using the curl analog get and post to the micro-communication interface. Share to everyone for your reference, specific as follows:
PHP Curl function can imitate the user to do some operations, such as we can imitate the user submits the data also can imitate the user to carry on the website to visit, below we will introduce uses the curl simulation to carry on the micro-communication interface's get and the post example, the example very simple two:
Get commit FETCH data
/**
* @desc get access_token
* @return String access_token
/function Getaccesstoken () {
$AppId = ' 1232assad13213123 ';
$AppSecret = ' 2312312321adss3123213 ';
$GETURL = ' https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid= '. $AppId. ' &secret= '. $AppSecret;
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_url, $GETURL);
curl_setopt ($ch, Curlopt_header, 0);
curl_setopt ($ch, Curlopt_returntransfer, 1);
curl_setopt ($ch, Curl_sslversion_ssl, 2);
curl_setopt ($ch, Curlopt_ssl_verifypeer, FALSE);
curl_setopt ($ch, Curlopt_ssl_verifyhost, FALSE);
$data = curl_exec ($ch);
$response = Json_decode ($data);
return $response->access_token;
}
Post commit fetch data
/** * @desc achieve weather content reply/Public function testweixin () {$access _token = $this->getaccess
Token ();
$CUSTOMMESSAGESENDURL = ' https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token= '. $access _token; $description = ' Details of today's weather (obtained from a third party).
';
$url = ' http://weather.com/';
$picurl = ' http://weather.com/'; $POSTDATAARR = Array (' Touser ' => ' OPENID ', ' msgtype ' => ' news ', ' News ' =>array (' articles ' =>array ') (' title ' =& gt; '
Day of the weather ', ' description ' => $description, ' url ' => $url, ' Picurl ' => $picurl,),);
$postJosnData = Json_encode ($POSTDATAARR);
$ch = Curl_init ($CUSTOMMESSAGESENDURL);
curl_setopt ($ch, Curlopt_header, 0);
curl_setopt ($ch, Curlopt_returntransfer, 1);
curl_setopt ($ch, Curlopt_post, 1);
curl_setopt ($ch, Curlopt_postfields, $postJosnData);
curl_setopt ($ch, Curlopt_ssl_verifypeer, FALSE);
curl_setopt ($ch, Curlopt_ssl_verifyhost, FALSE);
$data = curl_exec ($ch);
Var_dump ($data); }
The example is relatively simple and there is no good detailed analysis, we can copy to achieve the function we want.
For more information on PHP related content readers can view the site topics: "PHP micro-credit Development Skills summary", "PHP coding and transcoding Operation skills Summary", "PHP Network Programming Skills Summary", "PHP basic Grammar Introductory Course", "PHP string (String) Usage Summary", "php+ MySQL Database operations Introduction tutorial and PHP Common database operation Skills Summary
I hope this article will help you with the PHP program design.