365体育备用网址报道10.2.3我的订单查询_365体育备用网址官网资讯

微信小店的后台中提供订单查询功能,但那是给商家看的,如果用户需要察看自己的订单,则要使用微信小店的接口来开拓实现。这需要用到依据订单状态/创建时间猎取订单详情接口。
依据订单状态/创建时间猎取订单详情接口如下所示:
https://api.weixin.qq.com/merchant/order/getbyid?access_token=ACCESS_TOKEN
该接口的POST数据格式如下,参数说明如表10-3所示。

{
    "status": 2, 
    "begintime": 1397130460, 
    "endtime": 1397130470
}

表10-3订单查询接口参数说明
返回数据格式如下,参数说明如表10-4所示。

{
    "errcode": 0,
    "errmsg": "success",
    "order_list": [
        {
          "order_id": "7197417460812533543",
          "order_status": 6,
          "order_total_price": 6,
          "order_create_time": 1394635817,
          "order_express_price": 5,
          "buyer_openid": "oDF3iY17NsDAW4UP2qzJXPsz1S9Q",
          "buyer_nick": "likeacat",
          "receiver_name": "方倍",
          "receiver_province": "广东省",
          "receiver_city": "广州市",
          "receiver_address": "华景路一号南方通信大厦5楼",
          "receiver_mobile": "123456",
          "receiver_phone": "123456",
          "product_id": "pDF3iYx7KDQVGzB7kDg6Tge5OKFo", 
          "product_name": "《微信公众平台开拓最佳实践》",
          "product_price": 1,
          "product_sku": "10000983:10000995;10001007:10001010",
          "product_count": 1,
          "product_img": "http://mmbiz.qpic.cn/mmbiz/4whpV1VZl2icND8WwMThBEcehjhDv2icY4GrDSG5RLM3B2qd9kOicWGVJcsAhvXfibhWRNoGOvCfMC33G9z5yQr2Qw/0",
          "delivery_id": "1900659372473",
          "delivery_company": "059Yunda", 
          "trans_id": "1900000109201404103172199813"
        },
        {
          "order_id": "7197417460812533569",
          "order_status": 8,
          "order_total_price": 1,
          "order_create_time": 1394636235,
          "order_express_price": 0,
          "buyer_openid": "oDF3iY17NsDAW4UP2qzJXPsz1S9Q",
          "buyer_nick": "likeacat",
          "receiver_name": "张三",
          "receiver_province": "广东省",
          "receiver_city": "广州市",
          "receiver_address": "华景路一号南方通信大厦5楼",
          "receiver_mobile": "123456",
          "receiver_phone": "123456",
          "product_id": "pDF3iYx7KDQVGzB7kDg6Tge5OKFo", 
          "product_name": "《教爸爸妈妈用微信》",
          "product_price": 1,
          "product_sku": "1075741873:1079742377",
          "product_count": 1,
          "product_img": "http://mmbiz.qpic.cn/mmbiz/4whpV1VZl2icND8WwMThBEcehjhDv2icY4GrDSG5RLM3B2qd9kOicWGVJcsAhvXfibhWRNoGOvCfMC33G9z5yQr2Qw/0",
          "delivery_id": "1900659372473",
          "delivery_company": "059Yunda", 
             "trans_id": "1900000109201404103172199813"
        }
    ]
}

表10-4 订单查询接口返回内容参数说明
为了在微信中实现订单查询,需要先将一个菜单设置为“订单查询”按钮,该菜单的类型为“click”,key为“WDDD”。
菜单的实博马娱乐城开户码如下所示:

 1 require_once('weixin.class.PHP');
 2 $weixin = new class_weixin();
 3 
 4 $button[] = array('type' => "view",
 5                   'name' => urlencode("微信小店"),
 6                   'url'  => "http://mp.weixin.qq.com/bizmall/mallshelf?id=&t=mall/list&biz=MzANDQxNDUwNQ==&shelf_id=1&showwxpaytitle=1#wechat_redirect",
 7                  );
 8 $button[] = array('name' => urlencode("大众娱乐城备用网"),
 9                   'sub_button' => array(array('type' => "click",
10                                               'name' => urlencode("我的订单"),
11                                               'key'  => urlencode("WDDD")
12                                               ),
13                                         )
14                   );
15 $menu = urldecode(json_encode(array('button' => $button)));
16 var_dump($weixin->create_menu($menu));

当用户点击“我的订单”按钮时,微信接口将接收到这一点击事情通知,并且调用微信小店的订单查询接口来查询当前用户的订单信息,实博马娱乐城开户码如下所示。

  1 //接收事情消息
  2 private function receiveEvent($object)
  3 {
  4     $content = "";
  5     switch ($object->Event)
  6     {
  7         case "subscribe":
  8             $content = "欢迎关切方倍工作室";
  9             break;
 10         case "CLICK":
 11             switch ($object->EventKey)
 12             {
 13                 case "WDDD":
 14                     require_once('weixin.class.php');
 15                     $weixin = new class_weixin();
 16                     $openid = strval($object->FromUserName);
 17                     $orderArr = $weixin->get_detail_by_filter("{}");
 18                     if ($orderArr["errcode"] == -1){
 19                         $weixin->send_custom_message($openid, "text", "系统繁忙,请稍后再试!");
 20                     }
 21                     else if (count($orderArr["order_list"]) == 0){
 22                         $weixin->send_custom_message($openid, "text", "没有查询到订单记载!");
 23                     }else{
 24                         $data = array();
 25                         $data[] = array("title"=>urlencode("我的订单"), "description"=>"", "picurl"=>"", "url" =>"");
 26                         foreach ($orderArr["order_list"] as $index => $item){
 27                             if($item["buyer_openid"] == $openid){
 28                                 $title = "编号:".$item["order_id"]."\n时间:".date("Y-m-d H:i:s",$item["order_create_time"])
 29                                         ."\n名称:".$item["product_name"]."\n总价:¥".($item["product_price"] / 100)." × ".$item["product_count"]." + ¥".($item["order_express_price"] / 100)." = ¥".($item["order_total_price"] / 100);
 30                                 switch ($item["order_status"])
 31                                 {
 32                                     case 2:
 33                                       $orderstatus = "待发货";
 34                                       break;
 35                                     case 3:
 36                                       $orderstatus = "已发货";
 37                                       break;
 38                                     case 5:
 39                                       $orderstatus = "已完成";
 40                                       break;
 41                                     case 8:
 42                                       $orderstatus = "维权中";
 43                                       break;
 44                                     default:
 45                                       $orderstatus = "未知状态码".$item["order_status"];
 46                                       break;
 47                                 }
 48                                 $title .= "\n状态:".$orderstatus;
 49                                 $url = "";
 50                                 if ($item["order_status"] == 3 && !empty($item["delivery_company"])){
 51                                     switch ($item["delivery_company"])
 52                                     {
 53                                         case "Fsearch_code":
 54                                           $expressName = "邮政EMS";
 55                                           break;
 56                                         case "002shentong":
 57                                           $expressName = "申通快递";
 58                                           break;
 59                                         case "066zhongtong":
 60                                           $expressName = "中通速递";
 61                                           break;
 62                                         case "056yuantong":
 63                                           $expressName = "圆通速递";
 64                                           break;
 65                                         case "042tiantian":
 66                                           $expressName = "天天快递";
 67                                           break;
 68                                         case "003shunfeng":
 69                                           $expressName = "顺丰速运";
 70                                           break;
 71                                         case "059Yunda":
 72                                           $expressName = "韵达快运";
 73                                           break;
 74                                         case "064zhaijisong":
 75                                           $expressName = "宅急送";
 76                                           break;
 77                                         case "020huitong":
 78                                           $expressName = "汇通快运";
 79                                           break;
 80                                         case "zj001yixun":
 81                                           $expressName = "易迅快递";
 82                                           break;
 83                                         default:
 84                                           $expressName = "未知物流澳门葡京娱乐 国际,ID:".$item["delivery_company"];
 85                                           break;
 86                                     }
 87                                     $title .= "\n物流:".$expressName." ".$item["delivery_id"];
 88                                     if(preg_match("/^\d{3}[A-Za-z]{2,10}$/",$item["delivery_company"])){
 89                                         $companyEn = trim(substr($item["delivery_company"],3,strlen($item["delivery_company"])));
 90                                         $url = "http://m.kuaidi100.com/result.jsp?com=".strtolower($companyEn)."&nu=".$item["delivery_id"];
 91                                     }
 92                                 }
 93                                 $data[] = array("title"=>urlencode($title), "description"=>"", "picurl"=>"", "url" =>$url);
 94                             }
 95                             if (count($data) >=9){break;}
 96                         }
 97 
 98                         if (count($data) == 1){
 99                             $result = $weixin->send_custom_message($openid, "text", "没有查询到你的订单记载!");
100                         }else{
101                             $result = $weixin->send_custom_message($openid, "news", $data);
102                         }
103                     }
104                     $content = "";
105                     break;
106                 default:
107                     $content = "空菜单响应!";
108                     break;
109             }
110             break;
111     }
112     if(is_array($content)){
113         if (isset($content[0])){
114             $result = $this->transmitNews($object, $content);
115         }else if (isset($content['MusicUrl'])){
116             $result = $this->transmitMusic($object, $content);
117         }
118     }else{
119         $result = $this->transmitText($object, $content);
120     }
121     return $result;
122 }

上述代码中和订单查询通知相关部分简要说明如下:
第13行:推断是否收到订单查询事情通知。
第14行~第17行:引用微信小店SDK,猎取当前的一切订单信息。
第18行~第23行:用于查询订单接口的异常推断。
第24行~第96行:遍历订单详细中的一切订单列表,将当前用户的订单内容填充到微信图文消息中。
第98行~第102行:使用客服接口将订单详情通过图文消息方式发送。
最后,我的订单查询实现如图10-28所示。

图10-28我的订单查询结果

------分隔线----------------------------

公布评论 (156人察看0条评论)
请自觉遵守互联网相关的政策法规,严禁公布色情、暴力、反动的言论。
用户名: 验证码: 点击我更换网上轮盘娱乐场
最新评论