PHP code example of wechat-app / session-bundle

1. Go to this page and download the library: Download wechat-app/session-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wechat-app / session-bundle example snippets



// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Sensio\Bundle\BuzzBundle\SensioBuzzBundle(),
        new Snc\RedisBundle\SncRedisBundle(),
        new WechatApp\SessionBundle\WechatAppSessionBundle(),
        // ...
    );
}

// src/DemoBundle/Controller/DemoController.php
namespace DemoBundle\Controller;

use AppBundle\Controller\BaseController;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Request;
use WechatApp\SessionBundle\Controller\SessionAuthController;

/**
 * @Route("/demo")
 */
class DemoController extends Controller implements SessionAuthController
{
    /**
     * @Route("/test")
     */
    public function testAction(Request $request) 
    {
        // 从 Request 的 header 的属性中获取当前请求的微信用户信息
       $key = $this->getParameter('wechat_app_session.user_in_request_key');
       return $this->json($request->attributes->get($key));
    }
}