国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

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

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

Jan 03, 2017 am 09:17 AM

本文實(shí)例講述了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 = &#39;0&#39;){
      $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 &#39;<pre class="brush:php;toolbar:false">&#39;; 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[&#39;DOCUMENT_ROOT&#39;]."/jSon_file/access_token_".$this->ID.".json";
      //print_r($Path);
      if(!file_exists($Path)){
        touch($Path);
        chmod($Path,0777);
      }
      $data[&#39;expire_time&#39;] = time() + 7000;
      $data[&#39;access_token&#39;] = $accesstoken;
      $fp = fopen($Path, "w");
      fwrite($fp, json_encode($data));
      fclose($fp);
    }
    //讀取ACCESSTOKEN
    public function gAccessToken(){
      $Path = $_SERVER[&#39;DOCUMENT_ROOT&#39;]."/jSon_file/access_token_".$this->ID.".json";
      if(!file_exists($Path)){
        $data[&#39;expire_time&#39;] = 0;
        $data[&#39;access_token&#39;] = &#39;&#39;;
      }
      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,&#39;{"status": &#39;.$state.&#39;}&#39;);
       //echo "<pre class="brush:php;toolbar:false">";
       print_r( json_decode($ResData) );
    }
    //設(shè)置微小店物流支持列表
    public function sLogisticsList(){
      $this->Logistics[&#39;Fsearch_code&#39;] = "郵政EMS";
      $this->Logistics[&#39;002shentong&#39;] = "申通快遞";
      $this->Logistics[&#39;066zhongtong&#39;] = "中通速遞";
      $this->Logistics[&#39;056yuantong&#39;] = "圓通速遞";
      $this->Logistics[&#39;042tiantian&#39;] = "天天快遞";
      $this->Logistics[&#39;003shunfeng&#39;] = "順豐速運(yùn)";
      $this->Logistics[&#39;059Yunda&#39;] = "韻達(dá)快運(yùn)";
      $this->Logistics[&#39;064zhaijisong&#39;] = "宅急送";
      $this->Logistics[&#39;020huitong&#39;] = "匯通快運(yùn)";
      $this->Logistics[&#39;zj001yixun&#39;] = "易迅快遞";
    }
    //獲取訂單詳情
    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,&#39;{"order_id": "&#39;.$order.&#39;"}&#39;);
      //$url = "https://api.weixin.qq.com/merchant/order/getbyfilter?access_token=".$this->AccessToken;
      //$ResData = $this->cUrlRequest($url,&#39;{"status": 2}&#39;);
      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(&#39;begintime&#39; => $firstday,&#39;endtime&#39; => 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" => &#39;0&#39;)){
      $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" => &#39;0&#39;);
        $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,&#39;{"order_id": "&#39;.$order.&#39;"}&#39;);
      print_r( json_decode($ResData) );
    }
}

2. 頁面執(zhí)行代碼

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

以上就是php版微信小店API二次開發(fā)及使用示例的內(nèi)容,更多相關(guān)內(nèi)容請關(guān)注PHP中文網(wǎng)(m.miracleart.cn)!


本站聲明
本文內(nèi)容由網(wǎng)友自發(fā)貢獻(xiàn),版權(quán)歸原作者所有,本站不承擔(dān)相應(yīng)法律責(zé)任。如您發(fā)現(xiàn)有涉嫌抄襲侵權(quán)的內(nèi)容,請聯(lián)系admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費(fèi)脫衣服圖片

Undresser.AI Undress

Undresser.AI Undress

人工智能驅(qū)動(dòng)的應(yīng)用程序,用于創(chuàng)建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用于從照片中去除衣服的在線人工智能工具。

Clothoff.io

Clothoff.io

AI脫衣機(jī)

Video Face Swap

Video Face Swap

使用我們完全免費(fèi)的人工智能換臉工具輕松在任何視頻中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費(fèi)的代碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

功能強(qiáng)大的PHP集成開發(fā)環(huán)境

Dreamweaver CS6

Dreamweaver CS6

視覺化網(wǎng)頁開發(fā)工具

SublimeText3 Mac版

SublimeText3 Mac版

神級(jí)代碼編輯軟件(SublimeText3)

熱門話題

Laravel 教程
1601
29
PHP教程
1502
276