This article mainly share with you the PHP implementation of the simulation get and post to the interface to submit data, mainly in the form of code and share with you, hope to help everyone.
Get Commit get 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 Submission Fetch data
/*** @desc implement weather content reply */public function testweixin () {$access _token = $this Getaccesstoken (); $customMessageSendUrl = ' https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token= '. $ Access_token; $description = ' details of today's weather (obtained from third parties). '; $url = ' http://weather.com/'; $picurl = ' http://weather.com/'; $postDataArr = Array (' touser ' = ' OPENID ', ' msgtype ' = > ' News ', ' News ' =>array (' articles ' =>array (' title ' = ' The 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);}