Store Call API code example, small shop Call API example
When you start calling the store API, you may encounter problems. System error is always prompted, in the final analysis, the wrong parameters are sent.
Several invocation examples are given below:
The example is not completely 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 Productsfunction 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.'}'); Pay special attention here, this is in JSON format. Echo""; Print_r (Json_decode ($ResData)); } //Get all Groupsfunction Getallcategory ($state =0, $token) {$url="https://api.weixin.qq.com/merchant/group/getall?access_token=". $token; $ResData= Curlrequest ($url,'{"Status":'. $state.'}'); Echo""; Print_r (Json_decode ($ResData)); } //Get product information based on group IDfunction Getproductbygroudid ($state =0, $token) {$url="https://api.weixin.qq.com/merchant/group/getbyid?access_token=". $token; $ResData= Curlrequest ($url,'{"group_id":'. $state.'}'); Echo""; Print_r (Json_decode ($ResData)); } //Get 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 based on product_idfunction Getoneproductbyid ($state =0, $token) {$url="https://api.weixin.qq.com/merchant/get?access_token=". $token; $ResData= Curlrequest ($url,'{"product_id": "'. $state.'""}'); Echo"" ; Print_r (Json_decode ($ResData)); } $AccessToken =Getaccesstoken (); //gstateproduct (1, $AccessToken); // getallcategory (1, $AccessToken); // Getproductbygroudid (207061749, $AccessToken); Getoneproductbyid ("pf82vwn45zr8eolur5maistjg8wu", $ Accesstoken);
http://www.bkjia.com/PHPjc/1094587.html www.bkjia.com true http://www.bkjia.com/PHPjc/1094587.html techarticle Small store Call API code example, small shop Call API example just started to call the store API, you may encounter problems. System error is always prompted, in the final analysis or hair ...