ivanhoe / ivanhoe-sdk
PHP sdk,用于替换联盟链接
1.2
2016-09-12 11:36 UTC
Requires
- php: >=5.3.0
Suggests
- ext-curl: *
This package is not auto-updated.
Last update: 2024-09-23 12:56:01 UTC
README
##安装
$ composer require ivanhoe/ivanhoe-sdk
基本用法
创建用户会话并获取子 ID
$httpClient = new \Ivanhoe\SDK\CurlClient(); $sessionResource = new Ivanhoe\SDK\SessionResource($httpClient); $subId = $sessionResource->setCredentials(['id', 'password']) ->getSubId();
此方法会将用户数据发送到 Ivanhoe 服务器并返回一个生成的子 ID。但您可以通过传递自定义的 body 参数到 SessionResource::getSubId 来覆盖用户信息。可用的参数有
hostname
- 带协议的您的网站主机名。
user_agent
- 有效的用户代理。
user_ip
- 有效的 ipv4 或 ipv6。
referrer
- 流量来源。
document_path
.
language
- 表示用户语言的两位字符。
google_client_id
- 从 [_ga] cookie 中获取的 Google 分析客户端 ID。可以在辅助分析中获取。
示例
$httpClient = new \Ivanhoe\SDK\CurlClient(); $sessionResource = new Ivanhoe\SDK\SessionResource($httpClient); $subId = $sessionResource->setCredentials(['id', 'password']) ->getSubId([ 'hostname' => 'http://test.com', // google analytics profile id // https://developers.google.com/analytics/devguides/collection/analyticsjs/cookies-user-id 'google_client_id' => Ivanhoe\SDK\Analytics::getProfileId(), ]);
设置选项
您可以在 CurlClient::setOpts 方法上设置 curl 选项。键是 curl 选项常量。
$httpClient = new \Ivanhoe\SDK\CurlClient(); $httpClient->setOpts([ CURLOPT_FRESH_CONNECT => true ]);