public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     $session = $request->getSession();
     if ($request->getClientIp() == '127.0.0.1') {
         $session->set('open_id', 'o2-sBj0oOQJCIq6yR7I9HtrqxZcY');
         $session->set('user_id', 1);
     } else {
         if ($session->get('open_id') === null && $request->attributes->get('_route') !== '_callback' && stripos($request->attributes->get('_controller'), 'DefaultController') !== false) {
             $app_id = $this->container->getParameter('wechat_appid');
             $session->set('redirect_url', $request->getUri());
             $state = '';
             $callback_url = $request->getUriForPath('/callback');
             //$callback_url = $this->router->generate('_callback','');
             $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" . $app_id . "&redirect_uri=http://app.jingsocial.com/openid/dynamicOauth?wechat=" . $callback_url . "&response_type=code&scope=snsapi_userinfo&state=hello&connect_redirect=1#wechat_redirect";
             //$url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$app_id."&redirect_uri=".$callback_url."&response_type=code&scope=snsapi_userinfo&state=$state#wechat_redirect";
             $event->setResponse(new RedirectResponse($url));
         } else {
             $appId = $this->container->getParameter('wechat_appid');
             $appSecret = $this->container->getParameter('wechat_secret');
             $wechat = new Wechat\Wechat($appId, $appSecret);
             $wx = (object) $wechat->getSignPackage();
             //$session->set('wechat_title', $this->container->getParameter('wechat_title'));
             //$session->set('wechat_desc', $this->container->getParameter('wechat_desc'));
             $session->set('wechat_img_url', 'http://' . $request->getHost() . $this->container->getParameter('wechat_img_url'));
             $session->set('wx_share_url', $request->getUriForPath('/'));
             $session->set('wx_app_id', $wx->appId);
             $session->set('wx_timestamp', $wx->timestamp);
             $session->set('wx_nonce_str', $wx->nonceStr);
             $session->set('wx_signature', $wx->signature);
         }
     }
 }
 public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     $session = $request->getSession();
     if ($request->getClientIp() == '127.0.0.1') {
         $session->set('open_id', 'o5mOVuGapiB3tzYysVcE4xstN3s4');
         $session->set('user_id', 1);
     }
     if ($session->get('open_id') === null && $request->attributes->get('_route') !== '_callback' && stripos($request->attributes->get('_controller'), 'DefaultController') !== false) {
         $app_id = $this->container->getParameter('wechat_appid');
         $session->set('redirect_url', $request->getUri());
         $state = '';
         $callback_url = $request->getUriForPath('/callback');
         //$callback_url = $this->router->generate('_callback','');
         $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" . $app_id . "&redirect_uri=" . $callback_url . "&response_type=code&scope=snsapi_userinfo&state={$state}#wechat_redirect";
         $event->setResponse(new RedirectResponse($url));
     }
     if ($request->getClientIp() != '127.0.0.1') {
         $appId = $this->container->getParameter('wechat_appid');
         $appSecret = $this->container->getParameter('wechat_secret');
         $wechat = new Wechat\Wechat($appId, $appSecret);
         $wx = (object) $wechat->getSignPackage();
         $session->set('wx_app_id', $wx->appId);
         $session->set('wx_timestamp', $wx->timestamp);
         $session->set('wx_nonce_str', $wx->nonceStr);
         $session->set('wx_signature', $wx->signature);
         $session->set('wx_share_url', $request->getUriForPath('/'));
         $session->set('wx_share_success_url', null);
     }
 }
Exemple #3
0
 public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     $session = $request->getSession();
     //pc版
     if (stripos($request->attributes->get('_route'), '_pc') !== false && stripos($request->attributes->get('_controller'), 'DefaultController') !== false) {
     } elseif (stripos($request->attributes->get('_controller'), 'DefaultController') !== false) {
         if ($request->getClientIp() == '127.0.0.1') {
             $session->set('open_id', 'o2-sBj0oOQJCIq6yR7I9HtrqxZcY');
             $session->set('user_id', 1);
         } else {
             if ($session->get('open_id') === null && $request->attributes->get('_route') !== '_callback') {
                 $app_id = $this->container->getParameter('wechat_appid');
                 $session->set('redirect_url', $request->getUri());
                 $state = '';
                 $callback_url = $request->getUriForPath('/callback');
                 $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" . $app_id . "&redirect_uri=" . $callback_url . "&response_type=code&scope=snsapi_userinfo&state={$state}#wechat_redirect";
                 $event->setResponse(new RedirectResponse($url));
             }
             $appId = $this->container->getParameter('wechat_appid');
             $appSecret = $this->container->getParameter('wechat_secret');
             $wechat = new Wechat\Wechat($appId, $appSecret);
             $wx = (object) $wechat->getSignPackage();
             $session->set('wx_app_id', $wx->appId);
             $session->set('wx_timestamp', $wx->timestamp);
             $session->set('wx_nonce_str', $wx->nonceStr);
             $session->set('wx_signature', $wx->signature);
             $session->set('wx_share_url', $request->getUriForPath('/'));
             $session->set('wx_title', '搭出不一\\"Young\\"');
             $session->set('wx_desc', '年轻的Show场,由你搭配不一样的时尚');
             $session->set('wx_img_url', 'http://' . $request->getHost() . '/bundles/app/default/m/images/share.jpg');
         }
     }
 }
Exemple #4
0
 public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     $session = $request->getSession();
     if ($request->getClientIp() == '127.0.0.1') {
         $session->set('open_id', 'o5mOVuGapiB3tzYysVcE4xstN3s4');
         $session->set('user_id', 1);
     } else {
         if ($session->get('open_id') === null && $request->attributes->get('_route') !== '_callback' && stripos($request->attributes->get('_controller'), 'DefaultController') !== false) {
             $app_id = $this->container->getParameter('wechat_appid');
             $session->set('redirect_url', $request->getUri());
             $state = '';
             $callback_url = $request->getUriForPath('/callback');
             //$callback_url = $this->router->generate('_callback','');
             $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" . $app_id . "&redirect_uri=" . $callback_url . "&response_type=code&scope=snsapi_userinfo&state={$state}#wechat_redirect";
             $event->setResponse(new RedirectResponse($url));
         }
         $appId = $this->container->getParameter('wechat_appid');
         $appSecret = $this->container->getParameter('wechat_secret');
         $wechat = new Wechat\Wechat($appId, $appSecret);
         $wx = (object) $wechat->getSignPackage();
         $session->set('wx_app_id', $wx->appId);
         $session->set('wx_timestamp', $wx->timestamp);
         $session->set('wx_nonce_str', $wx->nonceStr);
         $session->set('wx_signature', $wx->signature);
     }
     if (stripos($request->attributes->get('_controller'), 'DefaultController') !== false) {
         if (null == $request->get('store_id')) {
             $store_id = null == $session->get('store_id') ? 1 : $session->get('store_id');
         } else {
             $store_id = $request->get('store_id');
         }
         $session->set('store_id', $store_id);
         $store = $this->em->getRepository('AppBundle:Store')->find($session->get('store_id'));
         if ($store !== null) {
             $session->set('storeImg', $store->getPageHeaderImg());
             $session->set('storeDescription', $store->getDescription());
             $session->set('pageTitle', $store->getTitle());
             $session->set('storeInfo', $store->getInfo());
             $session->set('storeName', $store->getStoreName());
             $session->set('storeAddress', $store->getAddress());
             $session->set('storeTel', $store->getTel());
             $session->set('wechat_title', $store->getWxTitle());
             $session->set('wechat_desc', $store->getWxDesc());
             $session->set('wechat_img_url', $store->getWxImg());
             $session->set('wx_share_url', 'http://' . $request->getHost() . $this->router->generate('_index', array('store_id' => $store->getId())));
         }
         #店铺关闭状态
         if ((null == $store || $store->getIsActive() == 0) && $request->attributes->get('_route') != '_close') {
             $event->setResponse(new RedirectResponse($this->router->generate('_close')));
         }
     }
 }
Exemple #5
0
 /**
  * @Route("/sign", name="_sign")
  */
 public function signAction(Request $request)
 {
     if (null == $request->get('url')) {
         return new Response('');
     }
     //$url = urldecode($request->get('url'));
     $appId = $this->container->getParameter('wechat_appid');
     $appSecret = $this->container->getParameter('wechat_secret');
     $wechat = new Wechat\Wechat($appId, $appSecret);
     $wx = (array) $wechat->getSignPackage(urldecode($request->get('url')));
     //var_dump($wx);
     $wx['shareTitle'] = '你有一个来自 NET-A-PORTER 颇特女士的下午茶邀请';
     $wx['shareDesc'] = '邀请全城摩登客开启一段舌尖与视觉碰撞的时尚之旅';
     $wx['shareUrl'] = 'http://' . $request->getHost() . '/';
     $wx['imgUrl'] = 'http://' . $request->getHost() . '/images/share.jpg';
     return new Response(json_encode($wx));
 }
Exemple #6
0
 /**
  * @Route("/sign", name="_sign")
  */
 public function signAction(Request $request)
 {
     if (null == $request->get('url')) {
         return new Response('');
     }
     //$url = urldecode($request->get('url'));
     $appId = $this->container->getParameter('wechat_appid');
     $appSecret = $this->container->getParameter('wechat_secret');
     $wechat = new Wechat\Wechat($appId, $appSecret);
     $wx = (array) $wechat->getSignPackage(urldecode($request->get('url')));
     //var_dump($wx);
     $wx['shareTitle'] = '谁来一起coffe time?和互联网大咖面对面,机会千载难逢!';
     $wx['shareDesc'] = '谁来一起coffe time?和互联网大咖面对面,机会千载难逢!';
     $wx['shareUrl'] = 'http://' . $request->getHost() . '/';
     $wx['imgUrl'] = 'http://' . $request->getHost() . '/images/share.jpg';
     return new Response(json_encode($wx));
 }