五月天激情丁香,国产精品2019,国产成人精品亚洲2020,国产精品免费视频一区二区三区,开心久久婷婷综合中文字幕,天堂视频在线观看免费完整版

代授權方實現業務

授權方已經把公眾號、小程序授權給你的開放平臺第三方平臺了,接下來的代授權方實現業務只需一行代碼即可獲得授權方實例。

實例化

<?php
$config = [
    // 開放平臺第三方平臺 APPID
    'appId' => 'wxefe41fdeexxxxxx', 

    // 開放平臺第三方平臺 Token
    'token' => 'dczmnau31ea9nzcnxxxxxxxxx',

    // 開放平臺第三方平臺 AES Key
    'aesKey' => 'easyswoole',

    // 開放平臺第三方平臺 Secret
    'secret' => 'your-AppSecret'
];

// 開放平臺
$openPlatform = \EasySwoole\WeChat\Factory::openPlatform($config);

獲取授權方實例

// 代公眾號實現業務
$officialAccount = $openPlatform->officialAccount(string $appId, string $refreshToken);

// 代小程序實現業務
$miniProgram = $openPlatform->miniProgram(string $appId, string $refreshToken);
  • $appId 為授權方公眾號 APPID,非開放平臺第三方平臺 APPID
  • $refreshToken 為授權方的 refresh_token,可通過 獲取授權方授權信息 接口獲得。

幫助授權方管理開放平臺賬號

<?php
// 代公眾號實現業務
$account = $officialAccount->account;

// 代小程序實現業務
$account = $miniProgram->account;

// 創建開放平臺賬號
// 并綁定公眾號或小程序
$result = $account->create();

// 將公眾號或小程序綁定到指定開放平臺帳號下
$result = $account->bindTo($openAppId);

// 將公眾號/小程序從開放平臺帳號下解綁
$result = $account->unbindFrom($openAppid);

// 獲取公眾號/小程序所綁定的開放平臺帳號
$result = $account->getBinding();

授權第三方平臺注冊的開放平臺帳號只可用于獲取用戶 unionid 實現用戶身份打通。第三方平臺不可操作(包括綁定/解綁)通過 open.weixin.qq.com 線上流程注冊的開放平臺帳號。公眾號只可將此權限集授權給一個第三方平臺,授權互斥。

代碼示例(在 EasySwoole 框架中使用)

使用示例 1:在 App\HttpController\Router.php (即路由)中使用:

示例代碼如下:

<?php
namespace App\HttpController;

use EasySwoole\Http\AbstractInterface\AbstractRouter;
use EasySwoole\Http\Request;
use EasySwoole\Http\Response;
use FastRoute\RouteCollector;

class Router extends AbstractRouter
{
    function initialize(RouteCollector $routeCollector)
    {
        // 假設你的公眾號消息與事件接收 URL 為:https://easyswoole.wechat.com/callback?appId=Xxxx ...
        $routeCollector->post('/callback', function (Request $request, Response $response) {

            $appId = $request->getQueryParam('appId');

            // $openPlatform 為你實例化的開放平臺對象,此處省略實例化步驟
            $officialAccount = $openPlatform->officialAccount($appId);

            // 這里的 server 為授權方的 server,而不是開放平臺的 server,請注意!!!
            $server = $officialAccount->server;

            $server->push(function (\EasySwoole\WeChat\Kernel\Contracts\MessageInterface $message) {
                return new \EasySwoole\WeChat\Kernel\Messages\Text('Welcome!');
            });

            // $psr7esponse 是一個顯式實現了 PSR-7 的對象,用戶只需要處理該對象即可正確響應給微信
            $psr7Response = $server->serve($request); // Done!

            $response->withStatus($psr7Response->getStatusCode());

            // PSR-7 的 Header 并不是單純的 k => v 結構
            foreach ($psr7Response->getHeaders() as $name => $values) {
                $response->withHeader($name, implode(", ", $values));
            }
            $response->write($psr7Response->getBody()->__toString());

            return false;
        });

        // 調用授權方業務例子
        $routeCollector->get('/how-to-use', function (Request $request, Response $response) {

            $officialAccount = $openPlatform->officialAccount('已授權的公眾號 APPID', 'Refresh-token');

            // 獲取用戶列表:
            $officialAccount->user->list();

            $miniProgram = $openPlatform->miniProgram('已授權的小程序 APPID', 'Refresh-token');

            // 根據 code 獲取 session
            $miniProgram->auth->session('js-code');

            // 其他同理

            return false;
        });
    }
}

使用示例 2:在 App\HttpController\Index.php (即控制器類)中使用,用戶可在自定義其他控制器中實現:

假設你的開放平臺第三方平臺設置的授權事件接收 URL 為: https://easyswoole.wechat.com/openPlatform (其他事件推送同樣會推送到這個 URL

示例代碼如下:

首先在 App\HttpController\Router.php 中定義路由:

<?php
namespace App\HttpController;

use EasySwoole\Http\AbstractInterface\AbstractRouter;
use FastRoute\RouteCollector;
use EasySwoole\WeChat\OpenPlatform\Server\Guard;

class Router extends AbstractRouter
{
    function initialize(RouteCollector $routeCollector)
    {
        // 假設你的公眾號消息與事件接收 URL 為:https://easyswoole.wechat.com/callback?appId=Xxxx ...
        $routeCollector->post('/callback', '/Index/callback');

        // 調用授權方業務例子
        $routeCollector->get('/how-to-use', '/Index/how_to_use');
    }
}

然后在 App\HttpController\Index.php 控制器中處理事件:

<?php

namespace App\HttpController;

use EasySwoole\Http\AbstractInterface\Controller;
use EasySwoole\WeChat\Kernel\Messages\Message;

class Index extends Controller
{
    // 假設你的公眾號消息與事件接收 URL 為:https://easyswoole.wechat.com/callback?appId=Xxxx ...
    public function callback()
    {
        $appId = $this->request()->getQueryParam('appId');

        // $openPlatform 為你實例化的開放平臺對象,此處省略實例化步驟
        $officialAccount = $openPlatform->officialAccount($appId);

        // 這里的 server 為授權方的 server,而不是開放平臺的 server,請注意!!!
        $server = $officialAccount->server;

        $server->push(function (\EasySwoole\WeChat\Kernel\Contracts\MessageInterface $message) {
            return new \EasySwoole\WeChat\Kernel\Messages\Text('Welcome!');
        });

        /** @var \Psr\Http\Message\ServerRequestInterface $psr7Request */
        $psr7Request = $this->request();

        // $psr7esponse 是一個顯式實現了 PSR-7 的對象,用戶只需要處理該對象即可正確響應給微信
        $psr7Response = $server->serve($psr7Request);

        $this->response()->withStatus($psr7Response->getStatusCode());

        // PSR-7 的 Header 并不是單純的 k => v 結構
        foreach ($psr7Response->getHeaders() as $name => $values) {
            $this->response()->withHeader($name, implode(", ", $values));
        }
        $this->response()->write($psr7Response->getBody()->__toString());
    }

    // 調用授權方業務例子
    public function how_to_use()
    {
        $officialAccount = $openPlatform->officialAccount('已授權的公眾號 APPID', 'Refresh-token');

        // 獲取用戶列表:
        $officialAccount->user->list();

        $miniProgram = $openPlatform->miniProgram('已授權的小程序 APPID', 'Refresh-token');

        // 根據 code 獲取 session
        $miniProgram->auth->session('js-code');

        // 其他同理
    }
}
主站蜘蛛池模板: 国产成人精品日本亚洲专一区 | 久久精品久久精品久久 | 精品不卡一区中文字幕 | 国产亚洲第一精品社区麻豆 | 激情午夜婷婷 | 五月婷婷一区 | 欧美日韩成人高清色视频 | 久久99影院| 日韩视频第1页 | 99久久国产免费中文无字幕 | 四虎永久在线精品 | 国产69精品久久久久99尤物 | 58av国产精品| 国内免费视频成人精品 | 欧美成人一区二区三区在线视频 | 你懂的视频在线观看资源 | 91精选国产 | 玖玖在线国产精品 | 国产精品成人一区二区 | 欧美午夜性视频 | 欧美日韩高清在线观看 | 久久久久这里只有精品 | 美女视频在线观看网站 | 国产欧美日韩精品在线 | 7799国产精品久久久久99 | 精品伊人久久久久7777人 | 国产va精品免费观看 | 蜜臀在线播放 | 欧美成人精品一区二三区在线观看 | 久久99热精品免费观看欧美 | 亚洲欧美日韩综合一区久久 | 国产末成年女av片 | 欧美黄色视屏 | 天天干夜夜做 | 91久久精品日日躁夜夜躁欧美 | 国产亚洲精品视频中文字幕 | 久久国产中文字幕 | 全亚洲最大的免费影院 | 国产视频高清在线 | 前女友俱乐部 | 激情综合色综合啪啪开心 |