phplicengine/bitly 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

phplicengine/bitly

Composer 安装命令:

composer require phplicengine/bitly

包简介

Bitly API v4

README 文档

README

Build Status Scrutinizer Code Quality Latest Stable Version Total Downloads php License

Bitly API v4

Contents

Installation

composer require phplicengine/bitly

Usage

use PHPLicengine\Api\Api;
use PHPLicengine\Service\Bitlink;

$api = new Api("API KEY GOES HERE");
$bitlink = new Bitlink($api);
$result = $bitlink->createBitlink(['long_url' => 'http://www.example.com']);

// if cURL error occurs.
if ($api->isCurlError()) {
    
    print($api->getCurlErrno().': '.$api->getCurlError());
    
} else {

    // if Bitly response contains error message.
    if ($result->isError()) {

        print("Error:<br />");
        print($result->getResponse());
        print($result->getDescription());
    
    } else {
    
        // if Bitly response is 200 or 201
        if ($result->isSuccess()) {
        
            print("SUCCESS:<br />");
            print($result->getResponse());
            print_r($result->getResponseArray());

        } else {

            print("FAIL:<br />");
            print($result->getResponse());
            print_r($result->getResponseArray());

        }
    }
}

// for debug only.
print("INFO:<br />");

// returns response exactly as it is. e.g. json.
$resj = $result->getResponse();
print($resj."<br />");

// returns decoded json.
$reso = $result->getResponseObject();
print_r($reso);

// returns header of server.
$resh = $result->getHeaders();
print_r($resh);

// returns request.
$resr = $api->getRequest();
print_r($resr);

Manual

Service Classes

In Bitly API v4 documentations, resources are classified under serveral categories:

Bitlink, Group, Organization, User, Custom, Campaign, Bsd, OAuth, Auth, Webhook

We made each of them as a separate service class. Method names are the same as the last part of documentation url. For example if you want to use Get Metrics for a Bitlink by Country, this one is classified under Bitlink category in documentation and the last part of its url is getMetricsForBitlinkByCountries, so you can call it this way:

use PHPLicengine\Api\Api;
use PHPLicengine\Service\Bitlink;

$api = new Api("API KEY GOES HERE");
$bitlink = new Bitlink($api);
$result = $bitlink->getMetricsForBitlinkByCountries('bit.ly/34nRNvl', ['unit' => 'day', 'units' => -1]);

All Path parameters, must be passed as string in first argument of methods if necessary and all Query parameters must be passed as array in second argument of methods if necessary. If Path parameter is not needed, Query parameters will be first argument of methods.

Another example:

Retrieve Group Shorten Counts is classified under Group category, and the last part of its link is getGroupShortenCounts, so you can call it this way:

use PHPLicengine\Api\Api;
use PHPLicengine\Service\Group;

$api = new Api("API KEY GOES HERE");
$group = new Group($api);
$result = $group->getGroupShortenCounts($group_guid);

Here is list of available service classes and methods.

Custom cURL Options

By default cURL timeout is 30. You can change it with:

$api->setTimeout(30);

If you need to add some CURLOPT_* constants that are not enabled by default, you can call setCurlCallback() method to add them.

use PHPLicengine\Api\Api;
use PHPLicengine\Service\Bitlink;

$api = new Api("API KEY GOES HERE");
$api->setCurlCallback(function($ch, $params, $headers, $method) { 
      curl_setopt($ch, CURLOPT_*, 'some value'); 
}); 
$bitlink = new Bitlink($api);

This is added for your convenience, but you should not need it.

Contributing and Support

For all issues or feature request or support questions please open a new issue. All pull requests are welcome.

License

PHPLicengine Api is distributed under the Apache License. See License.

phplicengine/bitly 适用场景与选型建议

phplicengine/bitly 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 308.09k 次下载、GitHub Stars 达 21, 最近一次更新时间为 2019 年 10 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「api」 「shortener」 「bitly」 「bit.ly」 「Shorturl」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 phplicengine/bitly 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 phplicengine/bitly 我们能提供哪些服务?
定制开发 / 二次开发

基于 phplicengine/bitly 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 308.09k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 22
  • 点击次数: 28
  • 依赖项目数: 0
  • 推荐数: 1

GitHub 信息

  • Stars: 21
  • Watchers: 2
  • Forks: 82
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2019-10-30