目录
2. [代码]页面执行代码 
首页 php教程 PHP源码 微信 微小店API 二次开发

微信 微小店API 二次开发

May 26, 2016 am 08:19 AM

通过微信微小店API控制,微信订单处理。使其用户可以在会员卡中查看订单信息。

1. [文件]     weixiaodian.php

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

<?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){

             //http://www.php.cn/

             //{"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) );

        }

         

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

        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;] = "顺丰速运";

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

            $this->Logistics[&#39;064zhaijisong&#39;] = "宅急送";

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

            $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) );

        }

         

        //查询全部订单

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

        }

         

        //设置订单发货

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

        }

         

        //关闭订单

        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. [代码]页面执行代码

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

<?php

    include_once &#39;class/weixiaodian.php&#39;;

     

    $wXd = new wXd();

     

    echo "<pre class="brush:php;toolbar:false">";

     

    //查询全部商品

    $wXd->gStateProduct();

     

    //获取订单信息

    $wXd->gOrderInfo(&#39;12963133879983601645&#39;);

     

    //关闭订单

    $wXd->sOrderClose(&#39;12963133879983600740&#39;);

     

    //发货订单设置

    $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 "

";
登录后复制

                   


                   

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

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

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
2 周前 By 尊渡假赌尊渡假赌尊渡假赌
仓库:如何复兴队友
4 周前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)