unificationengine/ue-php-sdk

此包最新版本(1.5.1)没有可用的许可信息。

UnificationEngine PHP SDK

1.5.1 2016-03-26 13:00 UTC

This package is not auto-updated.

Last update: 2024-09-20 17:27:39 UTC


README

PHP客户端SDK,用于UnificationEngine

使用Composer/Packagist进行安装

$ composer require unificationengine/ue-php-sdk

使用方法

use UnificationEngine\Models\UEApp;
$app = new UEApp("APP_KEY","APP_SECRET");

创建用户

use UnificationEngine\Models\UEApp;
use UnificationEngine\Models\UEUser;

//Use our app
$app = new UEApp("APP_KEY","APP_SECRET");

//Creating a new user
$user = $app->create_user();

//Using existing user using key and secret
$user = new UEUser("USER_KEY","USER_SECRET");

//Using existing user using it's uri
$user = new UEUser("user://USER_KEY:USER_SECRET@");

列出用户

$users = $app->list_users();

注意:出于安全原因,列出用户没有列出user_secret。因此,除非你将其密钥保存在某处,否则你不能使用列表中的用户。

删除用户

$user = $app->create_user();
$app->delete_user($user) //true

为用户添加连接

$connection = $user->add_connection("connection_name", "service", "service_access_token", $optional_params);
//connection is an instance of UEConnection
  • connection_name必须在每个连接中是唯一的。
  • service必须是开发者门户中连接器的方案。
  • service_access_token必须从提供方有效并正常工作。
  • $optional_params应该是一个包含“key”,“value”对的数组。

列出用户连接

$connections = $user->list_connections()
// connections is an array of UEConnection objects

删除用户连接

$user->remove_connection($connection_name) //true | false

测试连接

//return true if working, false otherwise
$user->test_connection($service_url) //eg: facebook://accesstoken@facebook.com

使用连接发送消息

$app  = new UEApp("APP_KEY","APP_SECRET");

//Create a new user
$user = $app->create_user();


//Or use an existing user
$user = new UEUser("USER_KEY","USER_SECRET");


//Add a connection. (throws an error if the connection is not added)
$connection = $user->add_connection("FB","facebook","FACEBOOK_ACCESS_TOKEN");
//                                    |       |
// Connection Name  ------------------+       |
// Connector Scheme  -------------------------+



//Message Options
$options = array(
    "receivers" => array(
        array(
            "name"=>"Page",
            "id"=>"283031198486599"
        ),
        array(
            "name"=> "Me"
        )
    ),
    "message"=>array(
        "subject"=>"test",
        "body"=> "ABC",
        "image"=>"http://politibits.blogs.tuscaloosanews.com/files/2010/07/sanford_big_dummy_navy_shirt.jpg",
        "link"=>array(
            "uri"=> "http://google.com",
            "description"=> "link desc",
            "title"=>"link title"
        )
    )
);



//Send the message and get their uris
$uris = $connection->send_message($options);

print_r($uris);