PHP version of micro-store invoke API sample code _php tips

Source: Internet
Author: User
Tags curl

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.

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.