微信小店调用api代码示例
刚开始调用微信小店api的时候,可能大家会遇到问题。系统总是提示system error,归根结底还是发送的参数不正确。
下面给出几个调用例子:
例子写得不全。
<?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, );
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, );
$output = curl_exec($curl);
curl_close($curl);
return $output;
} //获取所有商品
function gStateProduct($state = ,$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.'}'); //特别注意这里,这个是json格式的。
echo "<pre>";
print_r( json_decode($ResData) );
} //获得所有分组
function getAllCategory($state = ,$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) );
} //根据分组id来获得商品信息
function getProductByGroudid($state = ,$token)
{
$url = "https://api.weixin.qq.com/merchant/group/getbyid?access_token=".$token;
$ResData = cUrlRequest($url,'{"group_id": '.$state.'}');
echo "<pre>";
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 = ,$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);
微信小店调用api代码示例的更多相关文章
- 图解微信小程序---调用API操作步骤
图解微信小程序---调用API操作步骤 什么是API API(Application Programming Interface,应用程序编程接口:是一些预先定义的函数,目的是提供应用程序与开发人员基 ...
- 微信小程序调用api接口
请求的第三方微信url大概有3种 1)$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=$appid&s ...
- C#开发微信门户及应用(24)-微信小店货架信息管理
在前面微信小店系列篇<C#开发微信门户及应用(22)-微信小店的开发和使用>里面介绍了一些微信小店的基础知识,以及<C#开发微信门户及应用(23)-微信小店商品管理接口的封装和测试& ...
- C#开发微信门户及应用(22)-微信小店的开发和使用
在做企业电子商务方面,微信小店虽然较淘宝天猫等起步较晚,但是作为一个电商平台,这个影响力不容忽视,结合微信的特点和便利,微信小店具有很好的粘合性和广泛的用户基础,因此花费一定的时间,在这方面做深入的研 ...
- 微信小程序通过api接口将json数据展现到小程序示例
这篇文章主要介绍了微信小程序通过api接口将json数据展现到小程序示例,小编觉得挺不错的,现在分享给大家,也给大家做个参考.一起跟随小编过来看看吧实现知乎客户端的一个重要知识前提就是,要知道怎么通过 ...
- 微信小店开发(2) DIY货架
微信小店的货架支持开放给开发者使用,即开发者可以将自己的页面作为货架,通过JavaScript API来调起微信客户端原生的商品详情页. 请注意:1. 开发者需要预先通过1.1中的增加商品API,预先 ...
- C#开发微信门户及应用(23)-微信小店商品管理接口的封装和测试
在上篇<C#开发微信门户及应用(22)-微信小店的开发和使用>里面介绍了一些微信小店的基础知识,以及对应的对象模型,本篇继续微信小店的主题,介绍其中API接口的封装和测试使用.微信小店的相 ...
- (实用篇)php官方微信接口大全(微信支付、微信红包、微信摇一摇、微信小店)
微信入口绑定,微信事件处理,微信API全部操作包含在这些文件中.内容有:微信摇一摇接口/微信多客服接口/微信支付接口/微信红包接口/微信卡券接口/微信小店接口/JSAPI <?php class ...
- 把微信小程序异步API转为Promise,简化异步编程
把微信小程序异步API转化为Promise.用Promise处理异步操作有多方便,谁用谁知道. 微信官方没有给出Promise API来处理异步操作,而官方API异步的又非常多,这使得多异步编程会层层 ...
随机推荐
- leetcode441
public class Solution { public int ArrangeCoins(int n) { //convert int to long to prevent integer ov ...
- Eclipse 插件集合
以下是我整理的自己开发过程中的常用Eclipse插件,按字母排序: (1) AmaterasUML 介绍:Eclipse的UML插件,支持UML活动图,class图,sequenc ...
- MS SQL 2000 分配权限
/** 分配权限 **/ use [master]create login [ln-tf\liaobin] from windows;gogrant control server to [ln-tf\ ...
- 可视化库-Matplotlib-盒图(第四天)
盒图由五个数值点组成,最小观测值,下四分位数,中位数,上四分位数,最大观测值 IQR = Q3 - Q1 Q3表示上四分位数, Q1表示下四分位数,IQR表示盒图的长度 最小观测值 min =Q1 ...
- java对象转json对象
org.java类 public class orgs { private String id; private String name; public String getId() { return ...
- ASP.NET 网页动态添加客户端脚本
在System.Web.UI.Page类中包含了RegisterStarupScript()和RegisterClientScriptBlock()两个方法,使用这两个方法可以实现向Web页面动态添加 ...
- [z] How can we render CSS3 in a WebBrowser Control ?
http://www.pedautreppe.com/post/How-can-we-render-CSS3-in-a-WebBrowser-Control-.aspx
- dock panel
http://www.cnblogs.com/masterfy/archive/2009/06/02/1494593.html http://www.cnblogs.com/wuhuacong/p/3 ...
- null与not null
.not null CREATE TABLE `test` ( `col1` VARCHAR( ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NUL ...
- POP邮件收取邮件 代码
// 111111.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <WinSock.h> #include ...