PHP code example of violet250 / laravel-wechat

1. Go to this page and download the library: Download violet250/laravel-wechat 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/ */

    

violet250 / laravel-wechat example snippets


  Overtrue\LaravelWechat\ServiceProvider::class,
  

  'Wechat' => 'Overtrue\LaravelWechat\Facade',
  

  $app->register(Overtrue\LaravelWechat\ServiceProvider::class);
  

WECHAT_APPID
WECHAT_SECRET
WECHAT_TOKEN
WECHAT_AES_KEY

WECHAT_LOG_LEVEL
WECHAT_LOG_FILE

WECHAT_OAUTH_SCOPES
WECHAT_OAUTH_CALLBACK

WECHAT_PAYMENT_MERCHANT_ID
WECHAT_PAYMENT_KEY
WECHAT_PAYMENT_CERT_PATH
WECHAT_PAYMENT_KEY_PATH
WECHAT_PAYMENT_DEVICE_INFO
WECHAT_PAYMENT_SUB_APP_ID
WECHAT_PAYMENT_SUB_MERCHANT_ID

$app->configure('wechat');

Route::any('/wechat', 'WechatController@serve');

 

namespace App\Http\Controllers;

use Log;

class WechatController extends Controller 
{

    /**
     * 处理微信的请求消息
     *
     * @return string
     */
    public function serve()
    {
        Log::info('request arrived.');

        $wechat = app('wechat');
        $wechat->server->setMessageHandler(function($message){
            return "欢迎关注 overtrue!";
        });

        Log::info('return response.');

        return $wechat->server->serve();
    }
}

 

namespace App\Http\Controllers;

use EasyWeChat\Foundation\Application;

class WechatController extends Controller 
{

    public function demo(Application $wechat)
    {
        // $wechat 则为容器中 EasyWeChat\Foundation\Application 的实例
    }
}

'EasyWeChat' => Overtrue\LaravelWechat\Facade::class,

  $wechatServer = EasyWeChat::server(); // 服务端
  $wechatUser = EasyWeChat::user(); // 用户服务
  // ... 其它同理
shell
  php artisan vendor:publish