This article is an example of the PHP version of micro-store invoke the API method. Share to everyone for your reference, specific as follows:
When you start calling the micro-store API, you may encounter problems. System error is always prompted, but the parameters sent are incorrect.
Several invocation examples are given below:
Examples are not fully written.
<?php function 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, Curlopt_returntransfer, 1);
$output = curl_exec ($curl);
Curl_close ($curl);
return $output; //Get all commodity function 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. '} ');
Special note here, this is in JSON format.
echo "<pre>";
Print_r (Json_decode ($ResData)); //Get all Group function 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)); ///Based on the group ID to obtain the Commodity information function getproductbygroudid ($state = 0, $token) {$url = "https://api.weixin.qq.com/merchant/group/ge
Tbyid?access_token= ". $token;
$ResData = Curlrequest ($url, ' {group_id ': '. $state. '} ');
echo "<pre>";
Print_r (Json_decode ($ResData));
}//Get Accesstoken function 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; ///According to PRODUCT_ID to obtain a single product 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 ("Pf82vwn45zr8eolur5maistjg8wu", $AccessToken);
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.