获取微信用户在微信小店的订单

获取用户在微信小店的订单

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

 

上一篇:阶段5 3.微服务项目【学成在线】_day16 Spring Security Oauth2_07-SpringSecurityOauth2研究-Oauth2授权码模式-资源服务授权测试


下一篇:阶段5 3.微服务项目【学成在线】_day16 Spring Security Oauth2_08-SpringSecurityOauth2研究-解决swagger-ui无法访问