PHP code example of xwzgit / wechat-bus

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

    

xwzgit / wechat-bus example snippets


    第三方平台会推送事件给服务器:
    常规component_verify_ticket校验、公众号授权、取消授权、更改授权系信息
    
    //实例化ticket校验类
    $ticket = new Ticket(config('weChatBus'));
    
    //消息加解密处理
    $arrContent = $ticket->verifyTicket(); //消息处理(解密)
    
    //若无异常抛出,记录ticket返回success字符串

    $verifyTicket = 获取微信服务器定时推送的最新ticket,通过ticket获取componentToken

    //第三方平台componentAccessTokne获取
    $response = OpenApiServer::componentAccessToken(config('weChatBus'),$verifyTicket)
    $response返回格式
    {
       "component_access_token": "61W3mEpU66027wgNZ_MhGHNQDHnFATkDa9-2llqrMBjUwxRSNPbVsMmyD-yq8wZETSoE5NQgecigDrSHkPtIYA",
       "expires_in": 7200,
       "errcode":0,
    }
    
    //预授权码获取
    $response = OpenApiServer::preAuthCode(config('weChatBus'),$comAccToken)
    $response返回格式
    {
        "errcode":0,
        "pre_auth_code": "Cx_Dk6qiBE0Dmx4EmlT3oRfArPvwSQ-oa3NL_fwHM7VI08r52wazoZX2Rhpz1dEw",
        "expires_in": 600
    }
    //获取第三方平台授权地址
    $response = OpenApiServer::createAuthUrl($result['pre_auth_code']);
    (如果需要记录授权发起人uid的话,可以在授权地址后追加uid $authUrl.='?userName='.$userName;
    在授权回调的时候进行username获取)
    $response返回格式
    {
        "errcode":0,
        "authUrl": "http://***",
    }