本文实例讲述了php版微信小店API二次开发及使用方法。分享给大家供大家参考,具体如下:

1. weixiaodian.php页面:

class wXd

{

public $AppID = "";

public $AppSecret = "";

public $OutPut = "";

public $AccessToken = "";

public $ID = "";

public $HandleAT = array();

public $Logistics = array();

public function __construct($ID = '0'){

$this->ID = $ID;

$this->sLogisticsList();

}

public 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;

}

//获取ACCESSTOKEN

public function sAcessToken(){

$this->HandleAT = $this->gAccessToken();

if($this->HandleAT->expire_time < time()){

$appid = $this->AppID;

$appsecret = $this->AppSecret;

$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$appsecret;

$result = https_request($url);

//echo '

'; var_dump($result);die;

$jsoninfo = json_decode($result, true);

$access_token = $jsoninfo["access_token"];

$this->pAccessToken($access_token);

return $access_token;

}

else{

return $this->HandleAT->access_token;

}

}

//保存ACCESSTOKEN

public function pAccessToken($accesstoken){

$Path = $_SERVER['DOCUMENT_ROOT']."/jSon_file/access_token_".$this->ID.".json";

//print_r($Path);

if(!file_exists($Path)){

touch($Path);

chmod($Path,0777);

}

$data['expire_time'] = time() + 7000;

$data['access_token'] = $accesstoken;

$fp = fopen($Path, "w");

fwrite($fp, json_encode($data));

fclose($fp);

}

//读取ACCESSTOKEN

public function gAccessToken(){

$Path = $_SERVER['DOCUMENT_ROOT']."/jSon_file/access_token_".$this->ID.".json";

if(!file_exists($Path)){

$data['expire_time'] = 0;

$data['access_token'] = '';

}

else{

$data = json_decode(file_get_contents($Path));

//print_r($data);

}

return $data;

}

//获取所有商品

public function gStateProduct($state = 0){

//https://api.weixin.qq.com/merchant/getbystatus?access_token=ACCESS_TOKEN

//{"status": 0}

$this->AccessToken = $this->sAcessToken();

$url = "https://api.weixin.qq.com/merchant/getbystatus?access_token=".$this->AccessToken;

//print_r($this->AccessToken);

$ResData = $this->cUrlRequest($url,'{"status": '.$state.'}');

//echo "

";

print_r( json_decode($ResData) );

}

//设置微小店物流支持列表

public function sLogisticsList(){

$this->Logistics['Fsearch_code'] = "邮政EMS";

$this->Logistics['002shentong'] = "申通快递";

$this->Logistics['066zhongtong'] = "中通速递";

$this->Logistics['056yuantong'] = "圆通速递";

$this->Logistics['042tiantian'] = "天天快递";

$this->Logistics['003shunfeng'] = "顺丰速运";

$this->Logistics['059Yunda'] = "韵达快运";

$this->Logistics['064zhaijisong'] = "宅急送";

$this->Logistics['020huitong'] = "汇通快运";

$this->Logistics['zj001yixun'] = "易迅快递";

}

//获取订单详情

public function gOrderInfo($order){

$this->AccessToken = $this->sAcessToken();

//print_r($this->AccessToken);

$url = "https://api.weixin.qq.com/merchant/order/getbyid?access_token=".$this->AccessToken;

$ResData = $this->cUrlRequest($url,'{"order_id": "'.$order.'"}');

//$url = "https://api.weixin.qq.com/merchant/order/getbyfilter?access_token=".$this->AccessToken;

//$ResData = $this->cUrlRequest($url,'{"status": 2}');

print_r( json_decode($ResData) );

}

//查询全部订单

public function gOrderAll($data = array()){

$this->AccessToken = $this->sAcessToken();

$url = "https://api.weixin.qq.com/merchant/order/getbyfilter?access_token=".$this->AccessToken;

if(!empty($data)){

$data = json_encode($data);

}

else{

$firstday = strtotime(date("Y-m-01",time()));

$data = array('begintime' => $firstday,'endtime' => strtotime("$firstday +1 month -1 day"));

$data = json_encode($data);

}

$ResData = $this->cUrlRequest($url,$data);

print_r( json_decode($ResData) );

}

//设置订单发货

public function sOrderDelivery($data = array("need_delivery" => '0')){

$this->AccessToken = $this->sAcessToken();

$url = "https://api.weixin.qq.com/merchant/order/setdelivery?access_token=".$this->AccessToken;

if(!empty($data)){

$data = json_encode($data);

}

else{

$data = array("need_delivery" => '0');

$data = json_encode($data);

}

$ResData = $this->cUrlRequest($url,$data);

print_r( json_decode($ResData) );

}

//关闭订单

public function sOrderClose($order){

$this->AccessToken = $this->sAcessToken();

$url = "https://api.weixin.qq.com/merchant/order/close?access_token=".$this->AccessToken;

$ResData = $this->cUrlRequest($url,'{"order_id": "'.$order.'"}');

print_r( json_decode($ResData) );

}

}

2. 页面执行代码<?php

include_once 'class/weixiaodian.php';

$wXd = new wXd();

echo "

";

//查询全部商品

$wXd->gStateProduct();

//获取订单信息

$wXd->gOrderInfo('12963133879983601645');

//关闭订单

$wXd->sOrderClose('12963133879983600740');

//发货订单设置

$data['need_delivery'] = '1';

$data['order_id'] = '12963133879983600667';

$data['delivery_company'] = '059Yunda';

$data['delivery_track_no'] = '1000464090326';

$wXd->sOrderDelivery($data);

//获取所有订单

$wXd->gOrderAll();

echo "

";

以上就是php版微信小店API二次开发及使用示例的内容,更多相关内容请关注PHP中文网(www.erdangjiade.com)!

微信商城二次开发php,php版微信小店API二次开发及使用示例-微信开发相关推荐

  1. 微信小店的钱如何自动提现到个人微信?

    微信小店是为微信官方免费提供给商家的小程序,但是功能有点简单.例如不支持资金提现到个人微信.订单提醒.手机发货.订单打印.分享到朋友圈等等,这让用微信小店的商家非常麻烦. 那微信小程序怎么实现自动提现 ...

  2. arcgis开发 多版本之间如何兼容_arcgis api 4.x for js 结合 react 入门开发系列初探篇(附源码下载)...

    你还在使用 JQuery 或者 Dojo 框架开发 arcgis api 4.x for js 吗?想试试模块化开发吗?随着前端技术的发展,arcgis api 4.x for js 也有了结合 re ...

  3. 来学习开发一个网页版马里奥小游戏吧

    大家好,我是TJ 一个励志推荐10000款开源项目与工具的程序员 说起全球最有吸金能力的IP,大家会想到什么呢?是漫威?是哈利波特?还是王者荣耀(笑)? 其实很多印象都是主观的,根据Wikimili从 ...

  4. 微信小店 API 手册

    微信商铺API手册V1.13 目录 1.      商品管理接口.................................................................... ...

  5. 夏日葵电商:开发一个微信商城系统多少钱

    在微信大热的今天,微信商城也是马不停蹄加速发展,对于广大商家来说,这无疑就是一个经济主导地位,只要你定好格局,瞄准适合自身发展的经济市场,然后开发一个符合用户所需的微信商城系统,加以一定的营销策略就可 ...

  6. 第六篇 :微信公众平台开发实战Java版之如何自定义微信公众号菜单

    我们来了解一下 自定义菜单创建接口: http请求方式:POST(请使用https协议) https://api.weixin.qq.com/cgi-bin/menu/create?access_to ...

  7. 第三篇 :微信公众平台开发实战Java版之请求消息,响应消息以及事件消息类的封装...

    微信服务器和第三方服务器之间究竟是通过什么方式进行对话的? 下面,我们先看下图: 其实我们可以简单的理解: (1)首先,用户向微信服务器发送消息: (2)微信服务器接收到用户的消息处理之后,通过开发者 ...

  8. 第八篇 :微信公众平台开发实战Java版之如何网页授权获取用户基本信息

    第一部分:微信授权获取基本信息的介绍 我们首先来看看官方的文档怎么说: 如果用户在微信客户端中访问第三方网页,公众号可以通过微信网页授权机制,来获取用户基本信息,进而实现业务逻辑. 关于网页授权回调域 ...

  9. 第一篇:微信公众平台开发实战Java版之了解微信公众平台基础知识以及资料准备...

    相信很多人或多或少听说了微信公众平台的火热.但是开发还是有一点门槛,鉴于挺多朋友问我怎么开发,问多了,自己平时也进行以下总结. 所以下面给大家分享一下我的经验: 第一部分   介绍微信公众号的一些简单 ...

最新文章

  1. 直方图_20210420
  2. 在leangoo里怎么插入泳道,上下移动泳道和删除泳道?
  3. MPB:宁大张德民组-对虾养殖系统微生物组样品的采集与制备
  4. 针灸研究登上Nature:哈佛团队找出刺激穴位治疗疾病背后原理
  5. jupyter notebook 更改工作目录
  6. 一次 Young GC 的优化实践
  7. VTK:IO之GenericDataObjectReader
  8. 【Redis】杂项基础知识;Redis数据类型
  9. 新版本idea的run/debug configuration
  10. 2017.3.14 软件包管理器 思考记录
  11. android之menu,一起学Android之Menu
  12. Asp.Net把word文件转换为html文件
  13. iOS 动态添加属性方法
  14. Unicode、UTF-8、UTF-16之间的关系
  15. matlab solve 矩阵方程,用solve函数能求解带有未知数的矩阵方程组吗
  16. 无人驾驶综述:等级划分
  17. dnf怎么显示连接服务器失败怎么回事,登录DNF显示连接不到服务器怎么办 服务器连接失败解决方法...
  18. 淘宝宝贝商家编码 管理好你的宝贝
  19. 解决 Chrome 浏览器跨域加载本地文件的问题
  20. QQ群霸屏技术教程:不论霸屏技术,只谈QQ认证群

热门文章

  1. Android Studio 连接雷电模拟器运行程序
  2. Largest Rectangular Area in a Histogram
  3. halcon学习-vector_to_rigid/similarity/创建灰度渐变/创建及加入队列,例程
  4. 区块链巨头争相布局,区块链江湖暗流涌动
  5. 进程/线程/协程的区别
  6. 看当QQ动态头像会爱
  7. ThinkPHP6开发的电商后台管理系统
  8. Deepin Linux 系统常用快捷键记录
  9. 域适应行人重识别中的多中心表征网络
  10. PHP App Store Server API 苹果API退款 查询订单 历史订单 PHP校验签名解码