WeChat Third Party Platform Web-wide Publishing Detection

Keywords: Redis SDK Laravel network

  • First thanks easyWechat Author, provides a very useful SDK!

  • Next thanks Feishan Snow Leopard Although I took a lot of detours after reading this post (I was too foolish), without this post, I just looked at the WeChat documents and had no idea at all.

  • Finally, greet the author of the WeChat document!!!

  • WeChat posted the detected documents on the whole network and read them several times. Maybe in the state of Fuck The Writer Of The WeChat Document, I don't know what the documents are saying at all...

  • Solution steps:

  • First, WeChat will verify the item returning Api text messages. When verifying this item, there will be authorized code s, which can get authorization information and need to be saved. It will be used when verifying returning normal text messages and sending event messages, which is more critical.

  • I made some adjustments according to the code in the post of Feishan Snow Leopard. Finally, at 2:30 a.m., it was detected and passed by the WeChat full-web publishing.

// Since the framework used by the project is laravel, the following code is based on laravel
// http://www.example.com/Receiver/$APPID$
// $app_id is the public number or applet APPID from WeChat

// Route:
Route::any('Receiver/{appid}', 'Controller@Method');   // Receive events and messages from WeChat


public function receiver($app_id)
{
    $this->app_id = $app_id;

    // $official = $this->initOfficialAccount();
    $openPlatform = $this->openPlatform;
    $server           = $openPlatform->server;

    $server->push(EventHandler::class, Message::EVENT); // In testing, this is useless

    $msg = $server->getMessage();
    if ($msg['MsgType'] == 'text') {
        if ($msg['Content'] == 'TESTCOMPONENT_MSG_TYPE_TEXT') {
            $curOfficialAccount = $openPlatform->officialAccount($app_id, Redis::get($app_id));
            $curOfficialAccount->customer_service->message($msg['Content'] . '_callback')
                ->from($msg['ToUserName'])->to($msg['FromUserName'])->send();
            die;
        } elseif (strpos($msg['Content'], 'QUERY_AUTH_CODE') == 0) {
            echo '';
            $code           = substr($msg['Content'], 16);
            $authorizerInfo = $openPlatform->handleAuthorize($code)['authorization_info'];
            Redis::set(
                 $authorizerInfo['authorizer_appid'], 
                 $authorizerInfo['authorizer_refresh_token']
            );
            Redis::expire($authorizerInfo['authorizer_appid'], 20);
            $curOfficialAccount = $openPlatform->officialAccount(
                 $authorizerInfo['authorizer_appid'], 
                 $authorizerInfo['authorizer_refresh_token']
            );
            $curOfficialAccount->customer_service->message($code . "_from_api")
                        ->from($msg['ToUserName'])->to($msg['FromUserName'])->send();
        }
    } elseif ($msg['MsgType'] == 'event') {
        $curOfficialAccount = $openPlatform->officialAccount($app_id, Redis::get($app_id));
        $curOfficialAccount->customer_service->message($msg['Event'] . 'from_callback')
            ->to($msg['FromUserName'])->from($msg['ToUserName'])->send();
        die;
    }

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

There's still room for code optimization, but when it's detected, it's completely runnable

Thanks again easyWechat Provides a very useful SDK!

In other words, when can the OSC give this md a good finish, it will not be used at all

Posted by renesis on Fri, 03 Apr 2020 18:22:05 -0700