本文整理汇总了PHP中Idno\Core\Webservice::post方法的典型用法代码示例。如果您正苦于以下问题:PHP Webservice::post方法的具体用法?PHP Webservice::post怎么用?PHP Webservice::post使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Idno\Core\Webservice
的用法示例。
在下文中一共展示了Webservice::post方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postContent
function postContent()
{
$this->adminGatekeeper();
$request = $this->getInput('request');
$key = $this->getInput('key');
$username = $this->getInput('username');
$json = $this->getInput('json');
$follow_redirects = $this->getInput('follow_redirects');
$method = $this->getInput('method', 'GET');
$url = \Idno\Core\Idno::site()->config()->getURL();
if (strripos($url, '/') == strlen($url) - 1) {
$url = substr($url, 0, strlen($url) - 1);
}
$url .= $request;
$client = new Webservice();
if ($method == 'POST') {
$result = $client->post($url, $json, array('X-KNOWN-USERNAME: ' . $username, 'X-KNOWN-SIGNATURE: ' . base64_encode(hash_hmac('sha256', $request, $key, true))));
} else {
$result = $client->get($url, null, array('X-KNOWN-USERNAME: ' . $username, 'X-KNOWN-SIGNATURE: ' . base64_encode(hash_hmac('sha256', $request, $key, true))));
}
$response = Webservice::getLastResponse();
$sent_request = Webservice::getLastRequest() . $json;
$api_request = array('request' => $request, 'key' => $key, 'username' => $username, 'json' => $json, 'sent_request' => $sent_request, 'response' => gzencode($response, 9), 'method' => $method);
\Idno\Core\Idno::site()->session()->set('api_request', $api_request);
$this->forward(\Idno\Core\Idno::site()->config()->getURL() . 'admin/apitester/');
}
示例2: publish
/**
* If this idno installation has a PubSubHubbub hub, send a publish notification to the hub
* @param string $url
* @return array
*/
static function publish($url)
{
if ($hub = \Idno\Core\site()->config()->hub) {
return \Idno\Core\Webservice::post($hub, ['hub.mode' => 'publish', 'hub.url' => $url]);
}
return false;
}
示例3: getAccessToken
public function getAccessToken($endpointUrl, $grant_type = 'authorization_code', array $parameters)
{
if ($parameters['state'] != \Idno\Core\site()->plugins()->get('AppNet')->getState()) {
throw new \Exception('State value not correct, possible CSRF attempt.');
}
unset($parameters['state']);
$parameters['client_id'] = $this->key;
$parameters['client_secret'] = $this->secret;
$parameters['grant_type'] = $grant_type;
return \Idno\Core\Webservice::post(\IdnoPlugins\AppNet\Main::$TOKEN_ENDPOINT, $parameters);
}
示例4: testAuthenticated
public function testAuthenticated()
{
$user = \Tests\KnownTestCase::user();
$result = \Idno\Core\Webservice::post(\Idno\Core\Idno::site()->config()->url . 'status/edit', ['body' => "Making a nice test post via the api"], ['Accept: application/json', 'X-KNOWN-USERNAME: ' . $user->handle, 'X-KNOWN-SIGNATURE: ' . base64_encode(hash_hmac('sha256', '/status/edit', $user->getAPIkey(), true))]);
print_r($result);
$content = json_decode($result['content']);
$response = $result['response'];
$this->assertTrue(empty($result['error']));
$this->assertTrue(!empty($content));
$this->assertTrue(!empty($content->location));
$this->assertTrue($response == 200);
}
示例5: testUpload
public function testUpload()
{
$user = \Tests\KnownTestCase::user();
$result = \Idno\Core\Webservice::post(\Idno\Core\Idno::site()->config()->url . 'photo/edit', ['title' => 'A Photo upload', 'body' => "Uploading a pretty picture via the api", 'photo' => \Idno\Core\WebserviceFile::createFromCurlString("@" . dirname(__FILE__) . "/" . self::$file . ";filename=Photo.jpg;type=image/jpeg")], ['Accept: application/json', 'X-KNOWN-USERNAME: ' . $user->handle, 'X-KNOWN-SIGNATURE: ' . base64_encode(hash_hmac('sha256', '/photo/edit', $user->getAPIkey(), true))]);
print_r($result);
$content = json_decode($result['content']);
$response = $result['response'];
$this->assertTrue(empty($result['error']));
$this->assertTrue(!empty($content));
$this->assertTrue(!empty($content->location));
$this->assertTrue($response == 200);
}
示例6: postContent
function postContent()
{
$this->createGatekeeper();
// Logged-in only please
$email = $this->getInput('email');
$message = $this->getInput('message');
if (!empty($email) && !empty($message)) {
$results = Webservice::post('https://withknown.com/vendor-services/feedback/', array('url' => \Idno\Core\Idno::site()->config()->getURL(), 'title' => \Idno\Core\Idno::site()->config()->getTitle(), 'version' => \Idno\Core\Idno::site()->getVersion(), 'public' => \Idno\Core\Idno::site()->config()->isPublicSite(), 'hub' => \Idno\Core\Idno::site()->config()->known_hub, 'email' => $email, 'message' => $message));
\Idno\Core\Idno::site()->session()->addMessage("Thanks! We received your feedback.");
}
$this->forward(\Idno\Core\Idno::site()->config()->getURL() . 'account/settings/feedback/confirm/');
}
示例7: registerEventHooks
function registerEventHooks()
{
\Idno\Core\site()->syndication()->registerService('webhooks', function () {
return $this->hasWebhooks();
}, array('note', 'bookmark', 'event', 'article'));
if ($this->hasWebhooks()) {
if (!empty(\Idno\Core\site()->config()->webhook_syndication)) {
foreach (\Idno\Core\site()->config()->webhook_syndication as $hook) {
\Idno\Core\site()->syndication()->registerServiceAccount('webhooks', $hook['url'], $hook['title']);
}
}
if (\Idno\Core\site()->session()->isLoggedIn()) {
if (!empty(\Idno\Core\site()->session()->currentUser()->webhook_syndication)) {
foreach (\Idno\Core\site()->session()->currentUser()->webhook_syndication as $hook) {
\Idno\Core\site()->syndication()->registerServiceAccount('webhooks', $hook['url'], $hook['title']);
}
}
}
}
$hook_function = function (\Idno\Core\Event $event) {
$eventdata = $event->data();
if ($this->hasWebhooks()) {
$object = $eventdata['object'];
if (!empty($object) && $object instanceof Entity && !empty($eventdata['syndication_account'])) {
$payload = array();
$hook_url = $eventdata['syndication_account'];
if ($owner = $object->getOwner()) {
$payload['icon_url'] = $owner->getIcon();
$payload['username'] = $owner->getHandle();
}
$payload['content_type'] = $object->getActivityStreamsObjectType();
$payload['text'] = $object->getTitle() . ' <' . $object->getURL() . '>';
$payload['title'] = $object->getTitle();
$client = new Webservice();
$client->post($hook_url, json_encode($payload));
}
}
};
\Idno\Core\site()->addEventHook('post/note/webhooks', $hook_function);
\Idno\Core\site()->addEventHook('post/article/webhooks', $hook_function);
\Idno\Core\site()->addEventHook('post/bookmark/webhooks', $hook_function);
\Idno\Core\site()->addEventHook('post/event/webhooks', $hook_function);
}
示例8: getAccessToken
public function getAccessToken($endpointUrl, $grant_type = 'authorization_code', array $parameters)
{
if ($parameters['state'] != \Idno\Core\site()->plugins()->get('LinkedIn')->getState()) {
throw new \Exception('State value not correct, possible CSRF attempt.');
}
unset($parameters['state']);
$parameters['client_id'] = $this->key;
$parameters['client_secret'] = $this->secret;
$parameters['grant_type'] = $grant_type;
/**
* Note from the original OAuth 2 library:
*
* Passing an array to CURLOPT_POSTFIELDS will encode the data as multipart/form-data,
* while passing a URL-encoded string will encode the data as application/x-www-form-urlencoded.
* http://php.net/manual/en/function.curl-setopt.php
*
* ... Linked in API will only accept the latter at this stage.
*/
$result = \Idno\Core\Webservice::post(\IdnoPlugins\LinkedIn\Main::$TOKEN_ENDPOINT, http_build_query($parameters, null, '&'));
return json_decode($result['content']);
}
示例9: post
function post()
{
// Get parameters
$code = $this->getInput('code');
$me = $this->getInput('me');
$redirect_uri = $this->getInput('redirect_uri');
$state = $this->getInput('state');
$client_id = $this->getInput('client_id');
// Verify code
$response = Webservice::post('https://indieauth.com/auth', array('me' => $me, 'code' => $code, 'redirect_uri' => $redirect_uri, 'state' => $state, 'client_id' => $client_id));
if ($response['response'] == 200) {
parse_str($response['content'], $content);
if (!empty($content['me']) && (parse_url($content['me'], PHP_URL_HOST) == parse_url(\Idno\Core\site()->config()->getURL(), PHP_URL_HOST) || 'www.' . parse_url($content['me'], PHP_URL_HOST) == parse_url(\Idno\Core\site()->config()->getURL(), PHP_URL_HOST))) {
// Get user & existing tokens
$user = \Idno\Entities\User::getOne(array('admin' => true));
$indieauth_tokens = $user->indieauth_tokens;
if (empty($indieauth_tokens)) {
$indieauth_tokens = array();
}
// Generate access token and save it to the user
$token = md5(rand(0, 99999) . time() . $user->getUUID() . $client_id . $state . rand(0, 999999));
$indieauth_tokens[$token] = array('me' => $me, 'redirect_uri' => $redirect_uri, 'scope' => 'post', 'client_id' => $client_id, 'issued_at' => time(), 'nonce' => mt_rand(1000000, pow(2, 30)));
$user->indieauth_tokens = $indieauth_tokens;
$user->save();
if (\Idno\Core\site()->session()->isLoggedOn() && $user->getUUID() == \Idno\Core\site()->session()->currentUser()->getUUID()) {
\Idno\Core\site()->session()->refreshSessionUser($user);
}
// Output to the browser
$this->setResponse(200);
header('Content-Type: application/x-www-form-urlencoded');
echo http_build_query(array('access_token' => $token, 'scope' => 'post', 'me' => $me));
exit;
} else {
$this->setResponse(404);
echo "Client mismatch.";
}
}
}
示例10: getContent
function getContent()
{
$user = \Idno\Entities\User::getOne(array('admin' => true));
// This is for single user sites; will retrieve the main user
$code = $this->getInput('code');
if (!empty($code)) {
$client = new Webservice();
$response = Webservice::post('http://indieauth.com/auth', array('code' => $code, 'redirect_uri' => \Idno\Core\Idno::site()->config()->getURL(), 'client_id' => \Idno\Core\Idno::site()->config()->getURL()));
if ($response['response'] == 200) {
parse_str($response['content'], $content);
if (!empty($content['me']) && parse_url($content['me'], PHP_URL_HOST) == parse_url(\Idno\Core\Idno::site()->config()->getURL, PHP_URL_HOST)) {
$user = \Idno\Core\Idno::site()->session()->currentUser();
$user->indieauth_code = $code;
$user->save();
\Idno\Core\Idno::site()->session()->logUserOn($user);
} else {
\Idno\Core\Idno::site()->session()->addMessage("Couldn't log you in: the token hostname didn't match.");
}
} else {
\Idno\Core\Idno::site()->session()->addMessage("Uh oh! We got a " . $response['response'] . " response.");
}
}
}
示例11: makeCall
/**
* Makes a call to the hub
*
* @param $endpoint
* @param $contents
* @param bool $user
* @return array|bool
*/
function makeCall($endpoint, $contents, $user = false)
{
if (!$user) {
$user = site()->session()->currentUser();
}
if ($user instanceof User) {
if ($this->userIsRegistered($user)) {
$web_client = new Webservice();
$contents = json_encode($contents);
$time = time();
$details = $user->hub_settings;
$results = $web_client->post($this->server . $endpoint, array('content' => $contents, 'time' => $time, 'auth_token' => $details['token'], 'signature' => hash_hmac('sha1', $contents . $time . $details['token'], $details['secret'])));
return $results;
}
}
return false;
}
示例12: registerEventHooks
function registerEventHooks()
{
// Register syndication services
\Idno\Core\site()->syndication()->registerService('linkedin', function () {
return $this->hasLinkedIn();
}, ['note', 'article', 'image']);
if ($this->hasLinkedIn()) {
if (is_array(\Idno\Core\site()->session()->currentUser()->linkedin)) {
foreach (\Idno\Core\site()->session()->currentUser()->linkedin as $id => $details) {
if ($id != 'access_token') {
\Idno\Core\site()->syndication()->registerServiceAccount('linkedin', $id, $details['name']);
} else {
\Idno\Core\site()->syndication()->registerServiceAccount('linkedin', $id, 'LinkedIn');
}
}
}
}
// Push "notes" to LinkedIn
\Idno\Core\site()->addEventHook('post/note/linkedin', function (\Idno\Core\Event $event) {
$eventdata = $event->data();
$object = $eventdata['object'];
if ($this->hasLinkedIn()) {
if ($linkedinAPI = $this->connect($eventdata['syndication_account'])) {
if (!empty(\Idno\Core\site()->session()->currentUser()->linkedin[$eventdata['syndication_account']]['name'])) {
$name = \Idno\Core\site()->session()->currentUser()->linkedin[$eventdata['syndication_account']]['name'];
} else {
$name = 'LinkedIn';
}
$message = strip_tags($object->getDescription());
//$message .= "\n\n" . $object->getURL();
if (!empty($message) && substr($message, 0, 1) != '@') {
try {
$result = \Idno\Core\Webservice::post(self::$SHARE_URL . '?oauth2_access_token=' . $linkedinAPI->access_token, '
<share>
<comment>' . htmlentities($message) . '</comment>
<visibility>
<code>anyone</code>
</visibility>
</share>
', ["Content-Type: application/xml"]);
if ($result['response'] == 201) {
// Success
$link = "";
if (preg_match('/<update-url>(.*?)<\\/update-url>/', $result['content'], $matches)) {
$link = $matches[1];
}
$object->setPosseLink('linkedin', $link, $name);
$object->save();
} else {
if (preg_match('/<message>(.*?)<\\/message>/', $result['content'], $matches)) {
$message = $matches[1];
}
\Idno\Core\site()->logging->log("LinkedIn Syndication: " . print_r($result, true), LOGLEVEL_ERROR);
\Idno\Core\site()->session()->addErrorMessage("Linkedin returned error code: {$result['response']} - {$message}");
}
} catch (\Exception $e) {
\Idno\Core\site()->session()->addErrorMessage('There was a problem posting to LinkedIn: ' . $e->getMessage());
}
}
}
}
});
// Push "articles" to LinkedIn
\Idno\Core\site()->addEventHook('post/article/linkedin', function (\Idno\Core\Event $event) {
$eventdata = $event->data();
$object = $eventdata['object'];
if ($this->hasLinkedIn()) {
if ($linkedinAPI = $this->connect($eventdata['syndication_account'])) {
if (!empty(\Idno\Core\site()->session()->currentUser()->linkedin[$eventdata['syndication_account']]['name'])) {
$name = \Idno\Core\site()->session()->currentUser()->linkedin[$eventdata['syndication_account']]['name'];
} else {
$name = 'LinkedIn';
}
$result = \Idno\Core\Webservice::post(self::$SHARE_URL . '?oauth2_access_token=' . $linkedinAPI->access_token, '
<share>
<content>
<title>' . htmlentities(strip_tags($object->getTitle())) . '</title>
<submitted-url>' . htmlentities($object->getUrl()) . '</submitted-url>
</content>
<visibility>
<code>anyone</code>
</visibility>
</share>
', ["Content-Type: application/xml"]);
if ($result['response'] == 201) {
// Success
$link = "";
if (preg_match('/<update-url>(.*?)<\\/update-url>/', $result['content'], $matches)) {
$link = $matches[1];
}
$object->setPosseLink('linkedin', $link, $name);
$object->save();
} else {
if (preg_match('/<message>(.*?)<\\/message>/', $result['content'], $matches)) {
$message = $matches[1];
}
\Idno\Core\site()->session()->addErrorMessage("Linkedin returned error code: {$result['response']} - {$message}");
\Idno\Core\site()->logging->log("LinkedIn Syndication: " . print_r($result, true), LOGLEVEL_ERROR);
}
}
//.........这里部分代码省略.........
示例13: doMicropub
private function doMicropub($syndacct, $object, $params)
{
if ($details = $this->getAccountDetails($syndacct)) {
$headers = ['Authorization: Bearer ' . $details['access_token']];
Idno::site()->logging()->debug('sending micropub request', ['endpoint' => $details['micropub_endpoint'], 'params' => $params]);
$resp = Webservice::post($details['micropub_endpoint'], self::filterEmpty($params), $headers);
$header = $resp['header'];
$content = $resp['content'];
$status = $resp['response'];
$error = $resp['error'];
// status should be a 200 or a 300
if ($status >= 200 && $status < 400) {
if (preg_match('/Location:(.*)/i', $header, $matches)) {
$syndurl = trim($matches[1]);
$object->setPosseLink('indiesyndicate', $syndurl, $details['name'], $syndurl, $syndacct, ['icon' => $details['icon'], 'style' => $details['style']]);
$object->save();
Idno::site()->session()->addMessage("Syndicated to <a href=\"{$syndurl}\">{$syndurl}</a>.");
} else {
$msg = "Received {$status} from micropub endpoint but no Location header";
Idno::site()->logging()->log($msg, LOGLEVEL_ERROR);
Idno::site()->session()->addErrorMessage($msg);
}
} else {
if (empty($error) && !empty($content)) {
$error = $content;
}
$msg = "Error contacting micropub endpoint ({$status}): {$error}";
Idno::site()->logging()->error($msg);
Idno::site()->session()->addErrorMessage($msg);
}
} else {
$msg = "Could not get account details for syndication account {$syndacct}";
Idno::site()->logging()->error($msg);
Idno::site()->session()->addErrorMessage($msg);
}
}
示例14: getVendorMessages
/**
* Retrieve notices (eg notifications that a new version has been released) from Known HQ
* @return mixed
*/
function getVendorMessages()
{
if (!empty(site()->config()->noping)) {
return '';
}
$results = Webservice::post('https://withknown.com/vendor-services/messages/', array('url' => site()->config()->getURL(), 'title' => site()->config()->getTitle(), 'version' => site()->getVersion(), 'public' => site()->config()->isPublicSite(), 'phpversion' => phpversion(), 'dbengine' => get_class(site()->db()), 'hub' => site()->config()->known_hub));
if ($results['response'] == 200) {
return $results['content'];
}
}
示例15: warmFacebookCache
/**
* Facebook is silly and needs to have its cache warmed up before you post.
* @param $url
*/
function warmFacebookCache($url)
{
$client = new Webservice();
$result = $client->post('https://graph.facebook.com/', ['id' => $url, 'scrape' => 'true']);
error_log('Facebook cache result: ' . json_encode($result));
}