sgoendoer/sonic

SOcial Network InterConnect SDK

0.5.1 2018-05-27 17:37 UTC

README

SOcial Network InterConnect

Sonic SDK 提供了一套完整的工具集,用于简化 Sonic 协议集成到新的和现有的在线社交网络(OSN)平台中。它用 PHP 5.6 编写,完全兼容 PHP 7.0。Sonic SDK 可以通过 Composer 安装或直接从 GitHub 获取。

系统要求

  • PHP 5.6+ 或 PHP 7.0+
  • OpenSSL 1.0.0+
  • cURL 7.20.0+
  • composer

变更日志

0.5.1

0.5.0

  • 重新工作资源迁移
  • 重新工作资源功能
  • 重新工作资源链接
  • 将资源流重命名为活动
  • 标记资源人员为弃用
  • 添加资源图像
  • 改进和修复

0.3.0

  • 添加访问控制功能
  • 添加代码示例
  • 各种修复和改进

0.2.5

  • 添加功能协商功能
  • 各种修复和改进

0.2.0

  • 添加迁移功能
  • 添加搜索功能
  • 各种修复和改进

0.1.9

  • 添加单元测试
  • 添加日志支持
  • 代码清理
  • 删除未使用的类/函数
  • 各种修复和改进

0.1.0

  • 初始发布

安装

使用 composer 安装

$ composer require sgoendoer/sonic

或者配置你的 composer.json 如下

"require": {
	"sgoendoer/sonic": "0.5.1"
}

然后运行

$ composer update

配置

对于 Sonic 类的配置,可以使用 sgoendoer\Sonic\Config\Configuration 填充所需的值。未明确设置的值将保持其默认值。

Configuration::setTimezone('Europe/Berlin')
Configuration::setVerbose(1);

配置值

初始化

<?php

require_once(__DIR__ . '/vendor/autoload.php');

use sgoendoer\Sonic\Sonic;

use sgoendoer\Sonic\Config\Configuration;

use sgoendoer\Sonic\Identity\EntityAuthData;
use sgoendoer\Sonic\Identity\SocialRecord;
use sgoendoer\Sonic\Identity\SocialRecordManager;

try {
	// Sonic requires the \Sonic\Identity\SocialRecord of the Sonic platform for
	// initialization. Here, we import one from a String resource using
	// \Sonic\Identity\SocialRecordManager
	
	$platformSR = '{"socialRecord":{"@context": --truncated-- }';
	
	$sr = SocialRecordManager::importSocialRecord($platformSR);
	$platformSocialRecord = $sr['socialRecord'];
	$platformAccountKeyPair = $sr['accountKeyPair'];
	$platformPersonalKeyPair = $sr['personalKeyPair'];
	
	// We do the same for a user "Alice's" \Sonic\Identity\SocialRecord
	
	$aliceSR = '{"socialRecord":{"@context": --truncated -- }';
	
	$sr = SocialRecordManager::importSocialRecord($aliceSR);
	$userSocialRecord = $sr['socialRecord'];
	$userAccountKeyPair = $sr['accountKeyPair'];
	$userPersonalKeyPair = $sr['personalKeyPair'];
	
	// Before we can initialize the Sonic SDK, we need to pass a few configuration parameters.
	// Parameters we don't set explicitly will be set to default values.
	
	Configuration::setTimezone('Europe/Berlin');
	Configuration::setVerbose(1);
	
	// Now, we can initialize the Sonic SDK. The SDK's context will be set to "platform"
	// automatically
	
	$sonic = Sonic::initInstance(new EntityAuthData(
									$platformSocialRecord,
									$platformAccountKeyPair,
									$platformPersonalKeyPair));
											
	// From this point on, the Sonic SDK is fully initialized. Anyhow, the context must be
	// set to "user" in order to perform requests in the context of a user:
	
	Sonic::setUserAuthData(
		new EntityAuthData($userSocialRecord, $userAccountKeyPair));
	Sonic::setContext(Sonic::CONTEXT_USER);
	
	// Now we can perform a request to another user's profile using a GlobalID
	
	$globalID = '28B6TE8T9NUO202C5NZIUTNQSP88E70B8JAWH4FQ58OJOB8LIF';
	
	$response = (new ProfileRequestBuilder($globalID))
				->createGETProfile()
				->dispatch();
	$profile = ProfileObjectBuilder::buildFromJSON($response->getPayload());
	
	echo $profile->getJSONString() . "\n\n";
} catch (\Exception $e) {}
?>

文档

代码示例

更多示例,包括代码解释,可以在 这里 找到

提交错误和功能请求

错误和功能请求在 GitHub 上跟踪