search
HomeWeChat AppletWeChat DevelopmentPHP version of WeChat store calling api sample code

The example in this article describes how to call the API in the PHP version of WeChat store. Share it with everyone for your reference, the details are as follows:

When you first start calling the WeChat store API, you may encounter problems. The system always prompts system error. In the final analysis, the parameters sent are incorrect.

A few calling examples are given below:

The examples are not complete.

<?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;
}
//获取所有商品
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,&#39;{"status": &#39;.$state.&#39;}&#39;);  //特别注意这里,这个是json格式的。
   echo "<pre class="brush:php;toolbar:false">";
   print_r( json_decode($ResData) );
}
//获得所有分组
function getAllCategory($state = 0,$token)
{
    $url = "https://api.weixin.qq.com/merchant/group/getall?access_token=".$token;
    $ResData = cUrlRequest($url,&#39;{"status": &#39;.$state.&#39;}&#39;);
    echo "<pre class="brush:php;toolbar:false">";
    print_r( json_decode($ResData) );
}
//根据分组id来获得商品信息
function getProductByGroudid($state = 0,$token)
{
  $url = "https://api.weixin.qq.com/merchant/group/getbyid?access_token=".$token;
  $ResData = cUrlRequest($url,&#39;{"group_id": &#39;.$state.&#39;}&#39;);
  echo "<pre class="brush:php;toolbar:false">";
   print_r( json_decode($ResData) );
}
//获取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;
}
//根据product_id来获取单个商品
function getOneProductByid($state = 0,$token)
{
  $url="https://api.weixin.qq.com/merchant/get?access_token=".$token;
  $ResData = cUrlRequest($url,&#39;{"product_id": "&#39;.$state.&#39;""}&#39;);
  echo "<pre class="brush:php;toolbar:false">";
   print_r( json_decode($ResData) );
}
$AccessToken=getAccessToken();
//gStateProduct(1,$AccessToken);
//getAllCategory(1,$AccessToken);
//getProductByGroudid(207061749,$AccessToken);
getOneProductByid("pf82VwN45zr8eOlur5mAiSTjg8WU",$AccessToken);

The above is the content of the API sample code for the PHP version of WeChat store. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use