public function indexAction() { // // 判断当前URL是否传入了code和state值 $checkBrower = C('WECHAT_BROWER'); if ($checkBrower == true) { $code = I('get.code', 'defaultCode'); $state = I('get.state', ''); //无授权code,则跳转获取 if ($code == 'defaultCode' || $state == '' || $code == session('code')) { goto_auth(); return; } //通过微信返回的CODE值,获取用户信息 $userInfo = get_user_info($code); $userToken = $userInfo['access_token']; $this->openid = $userInfo['openid']; session('openid', $this->openid); session('openidTime', time()); // //判断用户权限,未注册跳转到提示页面 // $customerInfo = get_customer_info($this->openid); // $customerType = $customerInfo['subscribe_state']; // if($customerType == 0) // { //// 转到注册界面 //// $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://"; //// $url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; //// $url = U('Register/Index/index'); // //转至提示如果成为分销商的界面 // $id = 1; // $reply = new ReplyModel(); // $reply->setId($id); // $replyInfo = $reply->getInfoById(); // redirect($replyInfo['url']); // } session('code', $code); //获取调用收货地址配置信息 //获取调用微信JSSDK签名信息 $jssdk = new JSSDKController(); $jssdk->setCode($code); $jssdk->setState($state); $jssdk->setUserToken($userToken); // echo 'pay中当前code值' . $code . "<br />"; // echo 'pay中当前state值' . $state . "<br />"; // echo 'pay中当前userToken值' . $userToken . '<br />'; $addressPackage = $jssdk->getAddressPackage(); $signPackage = $jssdk->getSignPackage(); } $openid = get_openid(); $this->assign('openid', $openid); $title = '确认订单'; $this->assign('title', $title); //获取get信息,去除html过滤.数据类型为JSON格式的字符串 $ids = I('get.ids', ''); //字符串转为数组 $this->assign('ids', $ids); $ids = explode("-", $ids); $shoppingCart = new ShoppingCartModel(); $counts = $shoppingCart->getCounts($ids, $openid); $this->assign('counts', implode('-', $counts)); //取用户收货地址信息 $address = new CustomerAddressModel(); $address->setOpenid($openid); $customerAddress = $address->getLastUseAdderss(); $this->assign('address', $customerAddress); //设置GET收货地址管理的URL $customerAddress['chooseAddressUrl'] = U('Address/chooseAddress'); $this->assign('address', $customerAddress); //取收货地址信息HTML $this->assign('indexAddress', $this->fetch('indexAddress')); /* 进行数据处理,添加商品详情,按不同来源、物流方式进行分组,并将分组后数组的信息返回 */ $data = $this->dataAccess($ids, $counts); $product = $data[0]; $totalInfo = $data[1]; //传用户id,优惠券表里取对应的优惠券 $couponM = D('Coupon'); $coupon = $couponM->getCoupon($openid); $freightM = D('System/Config'); $freight = $freightM->freightCount(); //取运费的五个字段 $this->assign('freight', $freight); //给出收货地址URL信息 $data['addUrl'] = U('OrderForm/Address/add?openid=' . $openid); $data['editUrl'] = U('OrderForm/Address/edit?openid=' . $openid); $data['saveAddressUrl'] = U('OrderForm/Address/save'); $data['uploadImageUrl'] = U('OrderForm/Address/uploadImage'); $data['updateAddressUrl'] = U('OrderForm/Address/updateAddress'); $data['deleteUrl'] = U('OrderForm/Address/delete'); $this->assign('data', $data); //给出可以定制的header信息 $this->assign('header', $this->fetch('indexHeader')); $this->assign('coupon', $coupon); $this->assign('total', $totalInfo); //地址下面的条纹图片路径 $guoduUrl = add_root_path('/theme/wemall/images/guodu.png'); $this->assign('guoduUrl', $guoduUrl); $this->assign('css', $this->fetch('indexCss')); $this->assign('signPackage', $signPackage); $this->assign('addressPackage', $addressPackage); $updateUrl = U('Index/payNow'); $this->assign('url', $updateUrl); $wxJs = $this->fetch('wxJs'); $this->assign('wxJs', $wxJs); $js = $this->fetch('js'); $this->assign('js', $js); $this->assign('product', $product); //送入首页URL $indexUrl = U('Home/Index/index'); $this->assign('indexUrl', $indexUrl); //定制底部菜单 $this->assign('footer', $this->fetch('footer')); $this->assign('YZBody', $this->fetch('index')); $this->display(YZ_TEMPLATE); }
function get_openid($openid = NULL) { return 'oZuoxtwdQiGC6K_aA1zyh2HVQ5Sg'; $openid = session('openid'); $openidTime = session('openidTime'); if ($openid != false && $openidTime != false && time() - $openidTime < 60) { return $openid; } $code = I('code', ''); $isWeixinBrowser = isWeixinBrowser(); if ($isWeixinBrowser) { if ($openid == false && ($code == '' || $code == session('code'))) { goto_auth(); } else { session('code', $code); //缓存code防止二次使用 $userInfo = get_user_info($code); $openid = $userInfo['openid']; session('openid', $openid); session('openidTime', time()); //将抓取到的信息存库 $map['openid'] = $openid; $customer = M('Customer'); $res = $customer->where($map)->find(); if ($res == false) { $customer->data($userInfo)->add(); } else { $userInfo['id'] = $res['id']; $customer->data($userInfo)->save(); } } } if (empty($openid)) { return false; } return $openid; }
function getOpenid() { $openid = session('openid'); if ($openid == null) { $this->code = I('get.code', ''); $this->state = I('get.state', ''); //如果存在code,证明是二次访问。 if ($this->code != '' && $this->code != null && $this->code != S('code')) { S('code', $this->code, 300); //缓存300秒 $user = get_user_token($this->code); //获取有户token相关信息 if ($user['openid'] != null) { session('openid', $user['openid']); session('userToken', $user['access_token']); session('openidTime', time()); $key = $user['openid'] . "Token"; S($key, $this['userToken'], $user['expires_in']); } else { var_dump($user); throw_exception('获取用户信息失败'); } } else { goto_auth(); die; } } else { return $openid; } }