communify / communify-php
Communify PHP集成包。
dev-master
2020-03-12 18:58 UTC
Requires
- php: >=5.3.0
- guzzle/guzzle: ~3.7
- mustache/mustache: ~2.5
Requires (Dev)
- phpunit/phpunit: 4.3
This package is auto-updated.
Last update: 2024-09-11 08:13:59 UTC
README
Communify SDK for PHP 允许PHP开发者在其PHP代码中使用[Communify Web Services][communify]。您可以通过[通过Composer安装SDK][docs-installation]或从我们的[最新版本][latest-release]下载单个zip或phar文件来在几分钟内开始使用。
1. 功能
- 单点登录 (S2O)
- 搜索引擎优化 (SEO)
- 购买后发送电子邮件 (EAP)
2. 开始使用
- 注册Communify账号
- 最低要求
- 获取您的AccountId
- 安装SDK
2.1. 注册Communify账号
访问 http://communify.com,创建您的账号,并在会员偏好设置中启用单点登录登录。要启用单点登录,请转到设置/会员。
2.2. 获取您的AccountId
转到设置/集成以获取它
<di id="communify-widget-id" data-account-slug="[ACCOUNT SLUG]" data-account-id="[ACCOUNT ID]"><div ui-view class="communify-widget"></div></div>
2.3. 最低要求
- PHP版本:>= 5.3.0
- Guzzle:3.7
- Mustache:2.5
2.4. 安装SDK
2.4.1. 使用composer
修改composer.json
{
"require": {
"communify/communify-php": "dev-master",
}
}
```
Execute composer update.
#### 2.4.2. Without using composer
Download SDK: https://s3-us-west-2.amazonaws.com/communify-ops/releases/master/communify_sdk.zip. Add communify_sdk folder at project, and include autload.php to use Communify SDK.
## 3. Examples
### 3.1. Single Sign On (S2O)
Use this code. Metas have to been rendered at <head></head> tag.
```php
$accountId = '[ACCOUNT ID]';
$data = array(
'email' => '[USER EMAIL]',
'name' => '[USER NAME]',
'surname' => '[USER SURNAME]',
'file_url' => '[USER PROFILE IMAGE URL]',
'background_url' => '[USER BACKGROUND IMAGE URL]',
'language_id' => '[LANG ID]'
);
echo \Communify\S2O\S2OClient::factory()->login($accountId, $data)->metas();
```
#### 3.1.1. Single Sign On (S2O) and Wordpress
```php
function getAvatarUrl($id)
{
$avatar = get_avatar($id);
preg_match("/src=\"(.*?)\"/i", $avatar, $matches);
$url = $matches[1];
$urlArray = parse_url($url);
return 'http://'.$urlArray['host'].$urlArray['path'];
}
$currentUser = wp_get_current_user();
$accountId = '[ACCOUNT ID]';
if($currentUser->ID != 0)
{
$data = array(
'email' => $currentUser->user_email,
'name' => $currentUser->user_firstname,
'surname' => $currentUser->user_lastname,
'file_url' => getAvatarUrl($currentUser->ID)
);
echo \Communify\S2O\S2OClient::factory()->login($accountId, $data)->metas();
}
```
### 3.2. Search Engine Optimization (SEO)
```php
$accountId = '[ACCOUNT ID]';
$data = array(
'limit' => '10',
'order_by' => 'date'
);
echo \Communify\SEO\SEOClient::factory()->widget($accountId, $data)->html();
```
### 3.3. Email After Purchase (EAP)
Considerations:
* All product lines have same user
* All product lines have same order_id
* Some product line fields are mandatories: orderId, price, productId, userEmail.
```php
$accountId = '[ACCOUNT ID]';
$productLine1 = array(
'order_id' => [ORDER ID],
'price' => [PRICE],
'product_id' => [PRODUCT/TOPIC ID],
'product_name' => [PRODUCT/TOPIC NAME],
'title' => [PRODUCT/TOPIC TITLE],
'location_url' => [PRODUCT/TOPIC URL]
'title_to_display' => [PRODUCT/TOPIC TITLE TO DISPLAY],
'description' => [PRODUCT/TOPIC DESCRIPTION],
'site_image_url' => [PRODUCT/TOPIC IMAGE URL],
'category_slug' => [CATEGORY SLUG],
'category_name' => [CATEGORY NAME],
'category_description' => [CATEGORY DESCRIPTION],
'user_name' => [CUSTOMER NAME],
'user_surname' => [CUSTOMER SURNAME],
'user_email' => [CUSTOMER EMAIL],
);
$order = array($productLine1, [$productLine2, ...]);
\Communify\EAP\EAPClient::factory()->setOrder($accountId, $order);
```