最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

php版微信小店API二次開發(fā)及使用示例

 更新時間:2016年11月12日 14:45:57   作者:youkuiyuan  
這篇文章主要介紹了php版微信小店API二次開發(fā)及使用方法,結(jié)合實例形式分析了針對微信小店API的調(diào)用及使用方法,需要的朋友可以參考下

本文實例講述了php版微信小店API二次開發(fā)及使用方法。分享給大家供大家參考,具體如下:

1. weixiaodian.php頁面:

<?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 '<pre>'; 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 "<pre>";
       print_r( json_decode($ResData) );
    }
    //設(shè)置微小店物流支持列表
    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) );
    }
    //查詢?nèi)坑唵?
    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) );
    }
    //設(shè)置訂單發(fā)貨
    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) );
    }
    //關(guān)閉訂單
    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. 頁面執(zhí)行代碼

<?php
include_once 'class/weixiaodian.php';
$wXd = new wXd();
echo "<pre>";
//查詢?nèi)可唐?
$wXd->gStateProduct();
//獲取訂單信息
$wXd->gOrderInfo('12963133879983601645');
//關(guān)閉訂單
$wXd->sOrderClose('12963133879983600740');
//發(fā)貨訂單設(shè)置
$data['need_delivery'] = '1';
$data['order_id'] = '12963133879983600667';
$data['delivery_company'] = '059Yunda';
$data['delivery_track_no'] = '1000464090326';
$wXd->sOrderDelivery($data);
//獲取所有訂單
$wXd->gOrderAll();
echo "</pre>";

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP微信開發(fā)技巧匯總》、《PHP編碼與轉(zhuǎn)碼操作技巧匯總》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP基本語法入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總

希望本文所述對大家PHP程序設(shè)計有所幫助。

相關(guān)文章

  • php遍歷目錄輸出目錄及其下的所有文件示例

    php遍歷目錄輸出目錄及其下的所有文件示例

    好多次筆試都會遇到這個問題,本文特寫下php遍歷目錄輸出目錄及其下的所有文件的方法
    2014-01-01
  • php讀取csv文件并輸出的方法

    php讀取csv文件并輸出的方法

    這篇文章主要介紹了php讀取csv文件并輸出的方法,涉及php中fgetcsv函數(shù)的使用技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-03-03
  • PHP 七大優(yōu)勢分析

    PHP 七大優(yōu)勢分析

    ASP是微軟公司實現(xiàn)動態(tài)網(wǎng)頁的一種技術(shù)。ASP支持一些腳本語言,主要以VBScripp為主。與ASP相比較,你還可以選擇另一中開放源代碼編程語言——PHP,PHP可以運行在多種操作系統(tǒng)下,其中包括Linux和windows。
    2009-06-06
  • PHP session反序列化漏洞超詳細講解

    PHP session反序列化漏洞超詳細講解

    這篇文章主要介紹了PHP?session反序列化漏洞,php?session反序列化漏洞存在的原因是當序列化session和讀取反序列化字符時采用的序列化選擇器不一樣時,處理的方法不一樣
    2023-02-02
  • php導入excel文件到mysql數(shù)據(jù)庫的方法

    php導入excel文件到mysql數(shù)據(jù)庫的方法

    這篇文章主要介紹了php導入excel文件到mysql數(shù)據(jù)庫的方法,分析了phpexcel類操作excel文件的技巧及導入數(shù)據(jù)庫的方法,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-01-01
  • php中sort函數(shù)排序知識點總結(jié)

    php中sort函數(shù)排序知識點總結(jié)

    在本篇文章里小編給大家分享的是一篇關(guān)于php中sort函數(shù)排序知識點總結(jié)內(nèi)容,有興趣的朋友們可以參考下。
    2021-01-01
  • PHP中的string類型使用說明

    PHP中的string類型使用說明

    string就是一串連續(xù)的字符。
    2010-07-07
  • php給圖片加文字水印

    php給圖片加文字水印

    本文給大家分享的是使用php實現(xiàn)的給圖片加水印的方法,十分的細致全面,有需要的小伙伴可以參考下。
    2015-07-07
  • 使用PHP和RabbitMQ實現(xiàn)消息隊列功能

    使用PHP和RabbitMQ實現(xiàn)消息隊列功能

    這篇文章主要介紹了如何使用PHP和RabbitMQ實現(xiàn)消息隊列功能,文中通過示例代碼介紹的非常詳細,對大家學習或者使用PHP具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧
    2024-03-03
  • 在PHP里得到前天和昨天的日期的代碼

    在PHP里得到前天和昨天的日期的代碼

    在PHP里得到前天和昨天的日期的代碼...
    2007-08-08

最新評論

凉城县| 榕江县| 集安市| 武穴市| 中山市| 五原县| 沁源县| 高淳县| 上高县| 同仁县| 湟源县| 泰顺县| 蒙山县| 宜阳县| 阜南县| 嘉兴市| 德保县| 山阴县| 德州市| 民和| 涟水县| 宁武县| 昌宁县| 宽城| 凤阳县| 马尔康县| 陵水| 拉萨市| 梨树县| 札达县| 定结县| 威信县| 玉溪市| 浪卡子县| 元谋县| 桂平市| 敦煌市| 阿鲁科尔沁旗| 扎兰屯市| 泌阳县| 留坝县|