Current Location: Home> Latest Articles> 【2024 Guide】PHP WeChat Mini Program Development with EasyWeChat: Quick Start Tutorial

【2024 Guide】PHP WeChat Mini Program Development with EasyWeChat: Quick Start Tutorial

M66 2025-06-10

Introduction to EasyWeChat and Project Setup

As mobile internet continues to expand rapidly, WeChat Mini Programs have emerged as a popular choice among businesses and developers due to their lightweight, installation-free experience. For PHP developers, leveraging a powerful framework like EasyWeChat can greatly streamline the development process.

EasyWeChat is a well-established open-source PHP SDK that provides extensive support for WeChat features. It simplifies the integration of multiple services including Mini Programs, official accounts, and more. In this tutorial, we’ll walk through installing EasyWeChat and building a basic WeChat Mini Program.

Installing EasyWeChat

The simplest way to install EasyWeChat is via Composer. Run the following command in your project directory:

composer require overtrue/wechat

After installation, you’ll need to configure your Mini Program credentials in the config/wechat.php file:

return [
    'app_id' => 'your-app-id',
    'secret' => 'your-app-secret',
    // other config options...
];

Creating the Controller and Initializing the Mini Program

Now let’s create a controller to handle your Mini Program logic. Here’s a basic example:

<?php

namespace App\Http\Controllers;

use EasyWeChat\Factory;

class MiniProgramController extends Controller
{
    public function index()
    {
        $config = [
            'app_id' => config('wechat.app_id'),
            'secret' => config('wechat.secret'),
        ];

        $app = Factory::miniProgram($config);

        // Retrieve user OpenID
        $openid = $app->auth->session($_GET['code'])['openid'];

        // Fetch user info using OpenID
        $user = $app->user->get($openid);

        // Business logic processing...

        return view('mini_program.index', compact('user'));
    }
}

Core Modules Overview

In this example, we used EasyWeChat's auth and user modules to handle authentication and user data retrieval—both commonly used in Mini Program login flows.

Besides these, EasyWeChat also supports other practical modules, such as:

  • Payment module – Integrate WeChat Pay for e-commerce or service billing.
  • Message module – Send template messages to notify users.
  • Customer service module – Manage customer interactions efficiently.

Conclusion

Using EasyWeChat, PHP developers can build and debug WeChat Mini Programs with ease. Thanks to its well-organized API structure and modular design, it significantly enhances both development speed and maintainability. Once you're familiar with the basics, you can continue to explore and integrate advanced WeChat features into your application confidently.