apility/24sevenoffice

24SevenOffice 的简单独立连接器

v1.0.1 2019-10-09 07:44 UTC

This package is auto-updated.

Last update: 2024-09-09 18:28:44 UTC


README

这是一个为 ERP 系统 24SevenOffice 提供的简单独立的 PHP webservice 连接器。

完整文档

developer.24sevenoffice.com 上查看所有服务的完整文档。

安装

composer require apility/24sevenoffice

基本用法

验证并获取匹配搜索的公司列表

<?php

use Apility\T4SevenOffice\T4SevenOffice;

T4SevenOffice::setCredentials(
  'user@company.com', // username
  'yourpassword123', // password
  '00000000-0000-0000-0000-000000000000', // applicationId
  '00000000-0000-0000-0000-000000000000' // identityId (optional)
);

// By default, this is set to false, since you most likely would 
// like to save the sessionId from 24SevenOffice some other place
T4SevenOffice::setUsePhpSession(true);

try {
  
  T4SevenOffice::authenticateService();
  
  $companyService = T4SevenOffice::companyService();
  
  $companies = $companyService->GetCompanies([
    'searchParams' => ['CompanyName' => 'Test'],
    'returnProperties' => ['Name', 'Id']
  ]);
  
  var_dump($companies);
  
} catch (Exception $e) {
  die('24SevenOffice Exception: '.$e->getMessage());
}

保留会话

为了避免每次都通过 webservice 进行验证(并提高性能),您可以将 24SevenOffice 的 sessionId 保存下来,并在其有效期间使用它。

您可以使用 PHP Session 来实现这一点

<?php

// By default, this is set to false
T4SevenOffice::setUsePhpSession(true);

或者自行处理 sessionId

<?php

// Saved from last auth
$sessionId = 'demosw1avyg2h4opyi0demo';

T4SevenOffice::setSessionId($sessionId);

T4SevenOffice::authenticateService();

if ($sessionId !== T4SevenOffice::getSessionId) {
  // Session from last time is no longer valid, and a new one has been created
  // TODO: Save the new sessionId for next time
}

列出所有身份

<?php

T4SevenOffice::setCredentials(
  'user@company.com', // username
  'yourpassword123', // password
  '00000000-0000-0000-0000-000000000000' // applicationId
);

$authService = T4SevenOffice::authenticateService();
  
$identities = $authService->GetIdentities();
  
var_dump($identities);