WeChat store Call API code sample, small shop call API Sample _php Tutorial

Source: Internet
Author: User

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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.