Skip to content

Latest commit

 

History

History
51 lines (40 loc) · 1.56 KB

7.0-GENERATE-INSTALL-URL.md

File metadata and controls

51 lines (40 loc) · 1.56 KB

生成应用安装URL

企业微信: 企业授权应用文档

1. 生成应用安装url

<?php
use Zwei\WorkWechat\Suites\SuiteApi;

$suiteId        = '';
$suiteSecret    = '';
$suiteTicket    = '';
$suiteApi       = new SuiteApi();
// 获取第三方应用凭证
$result         = $suiteApi->getSuiteAccessToken($suiteId, $suiteSecret, $suiteTicket);
$suiteAccessToken = $result['suite_access_token'];

// 获取预授权码
$result = $suiteApi->getPreAuthCode($suiteAccessToken);
$preAuthCode = $result['pre_auth_code'];
// 授权成功 会进入回调URI
$redirectUri = '';

// 生成应用安装URL
$appInstallUrl = $suiteApi->generateAppInstallUrl($suiteId, $preAuthCode, $redirectUri, $state);

2. 授权成功 会进入回调URI

用户确认授权后,会进入回调URI(即redirect_uri),并在URI参数中带上临时授权码、过期时间以及state参数。第三方服务商据此获得临时授权码。回调地址为

redirect_uri?auth_code=xxx&expires_in=600&state=xx

企业微信: 临时授权码换取永久授权码文档

你应该把永久授权码和授权企业信息保存起来

<?php
use Zwei\WorkWechat\Suites\SuiteApi;
$suiteApi  = new SuiteApi();

// 检测是否安装成功
if (isset($_GET['auth_code'])) {
    // 临时授权码换取永久授权码
    $authCode = $_GET['auth_code'];
    $result = $suiteApi->getPermanentCode($suiteAccessToken, $authCode);
    echo '<pre>';
    print_r($result);
    exit;
}