Sample Code of the api called by the php store
This article describes how to call APIs in a php store. We will share this with you for your reference. The details are as follows:
You may encounter problems when calling the store api. The system always prompts system error. In the final analysis, the sent parameter is incorrect.
The following are several call examples:
The example is not completely written.
<? Phpfunction cUrlRequest ($ url, $ data = null) {$ curl = curl_init (); curl_setopt ($ curl, CURLOPT_URL, $ url); curl_setopt ($ curl, CURLOPT_SSL_VERIFYPEER, FALSE ); curl_setopt ($ curl, CURLOPT_SSL_VERIFYHOST, FALSE); if (! Empty ($ data) {curl_setopt ($ curl, CURLOPT_POST, 1); curl_setopt ($ curl, CURLOPT_POSTFIELDS, $ data);} curl_setopt ($ curl, expires, 1 ); $ output = curl_exec ($ curl); curl_close ($ curl); return $ output;} // get all functions gStateProduct ($ state = 0, $ token) {// https://api.weixin.qq.com/merchant/getbystatus? Access_token = ACCESS_TOKEN // {"status": 0} // $ AccessToken = "xxxxxxxx"; $ url = "https://api.weixin.qq.com/merchant/getbystatus? Access_token = ". $ token; // print_r ($ this-> AccessToken); $ ResData = cUrlRequest ($ url, '{"status ":'. $ state. '}'); // note that this is in json format. Echo "<pre>"; print_r (json_decode ($ ResData);} // get all group functions getAllCategory ($ state = 0, $ token) {$ url = "https://api.weixin.qq.com/merchant/group/getall? Access_token = ". $ token; $ ResData = cUrlRequest ($ url, '{"status ":'. $ state. '}'); echo "<pre>"; print_r (json_decode ($ ResData);} // obtain the product information based on the group id. function getProductByGroudid ($ state = 0, $ token) {$ url = "https://api.weixin.qq.com/merchant/group/getbyid? Access_token = ". $ token; $ ResData = cUrlRequest ($ url, '{"group_id ":'. $ state. '}'); echo "<pre>"; print_r (json_decode ($ ResData);} // obtain accesstokenfunction getAccessToken () {$ appid = "your appid "; $ appsecret = "your appsecret"; $ url = "https://api.weixin.qq.com/cgi-bin/token? Grant_type = client_credential & appid = ". $ appid. "& secret = ". $ appsecret; $ result = cUrlRequest ($ url); $ jsoninfo = json_decode ($ result, true); $ access_token = $ jsoninfo ["access_token"]; return $ access_token ;} // get a single item function getOneProductByid ($ state = 0, $ token) {$ url = "https://api.weixin.qq.com/merchant/get? Access_token = ". $ token; $ ResData = cUrlRequest ($ url, '{"product_id ":"'. $ state. '""}'); echo "<pre>"; print_r (json_decode ($ ResData);} $ AccessToken = getAccessToken (); // gStateProduct (1, $ AccessToken); // getAllCategory (1, $ AccessToken); // getProductByGroudid (207061749, $ AccessToken); getOneProductByid ("your", $ AccessToken );