PHP code example of takatost / laravel_wechat_open_platform

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

    

takatost / laravel_wechat_open_platform example snippets


  LaravelWechatOP\ServiceProvider::class,
  

  'WechatOP' => LaravelWechatOP\WechatOP::class,
  
shell
  php artisan vendor:publish
  

$callbackUrl = 'http://for.bar/callback'; // 授权回调地址
$response = WechatOP::oauth()->redirect($callbackUrl);  // 或 $response = app('wechat_op')->oauth->redirect($authCallbackUrl);
// 获取跳转地址 $redirectUrl = $response->getTargetUrl();

return $response;

$server = WechatOP::server();
$server->setMessageHandler(function($message) {
        switch ($message->get('InfoType')) {
            case "component_verify_ticket":
                // 保存开放平台 ticket
                env('wechat_op')->saveTicket($message->get('ComponentVerifyTicket'));
                break;
            case "unauthorized":                
                // 公众号取消授权记录
                break;
            default:
                break;
        }
    });
    
return $server->serve();