獲取微信用戶在微信小店的訂單


獲取用戶在微信小店的訂單

1. 網頁授權得到openid

2.拉取30天內的訂單

3.循環匹配訂單的openid與當前用戶openid是否一致

    
    //同步訂單列表
    public function order(){
        $openid = "";
        Vendor('Weixin.weixinclass');
        $weixin = new \weixin();
        if (!isset($_GET["code"])){
            $redirect_url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
            $jumpurl = $weixin->oauth2_authorize($redirect_url, "snsapi_base", "123");
            Header("Location: $jumpurl");
            exit();
        }else{
            // var_dump($_GET);
            $access_token_oauth2 = $weixin->oauth2_access_token($_GET["code"]);
            $openid = $access_token_oauth2['openid'];

            $curtime = time();
            $orderArr = $weixin->get_detail_by_filter('{ "begintime": '.($curtime - 2592000).',  "endtime": '.$curtime.'}'); //最近30天
            $list = array();
            $express = array('Fsearch_code'=>"郵政EMS",'002shentong'=>"申通快遞",'066zhongtong'=>"中通速遞",'056yuantong'=>"圓通速遞",'042tiantian'=>"天天快遞",'003shunfeng'=>"順豐速運",'059Yunda'=>"韻達快運",'064zhaijisong'=>"宅急送",'020huitong'=>"匯通快運",'zj001yixun'=>"易迅快遞");
            foreach ($orderArr["order_list"] as $index => $item){
                if($item["buyer_openid"] == $openid){
                    $item["product_sku"] = str_replace("$","",$item["product_sku"]);
                    $item["express"] = $express[$item["delivery_company"]];
                    $list[] = $item;
                }
            }
            // var_dump($list);
            $this->assign('title', "微信訂單");
            $this->assign('list', $list);
            $this->display();
        }
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM