moesif/moesifapi-php 问题修复 & 功能扩展

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

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

moesif/moesifapi-php

Composer 安装命令:

composer require moesif/moesifapi-php

包简介

Log HTTP API Requests/Responses to Moesif

README 文档

README

Built For Latest Version Software License Source Code

Source Code on GitHub

Check out Moesif's Developer Documentation and PHP API Reference to learn more

How To Install

Install via Composer

composer require moesif/moesifapi-php

How To Use:

For using this SDK do the following:

  1. Use Composer to install the dependencies. See the section "How To Build".

  2. See that you have configured your SDK correctly. See the section "How To Configure".

  3. Depending on your project setup, you might need to include composer's autoloader in your PHP code to enable autoloading of classes.

    require_once "vendor/autoload.php";
  4. Import the SDK client in your project:

    use Moesif\Sender\MoesifApi;
  5. Instantiate the client. After this, you can now access the Moesif API and call the respective methods:

    $client = MoesifApi::getInstance("Your Moesif Application Id", ['fork'=>true, 'debug'=>false]);

Your Moesif Application Id can be found in the Moesif Portal. After signing up for a Moesif account, your Moesif Application Id will be displayed during the onboarding steps.

You can always find your Moesif Application Id at any time by logging into the Moesif Portal, click on the top right menu, and then clicking Installation.

Create a Single API Event

use Moesif\Sender\MoesifApi;

$reqdate = new DateTime();
$rspdate = new DateTime();

$event= array(
    "request" => array(
        "time" => $reqdate->format(DateTime::ISO8601), 
        "uri" => "https://api.acmeinc.com/items/reviews/", 
        "verb" => "PATCH", 
        "api_version" => "1.1.0", 
        "ip_address" => "61.48.220.123", 
        "headers" => array(
          "Host" => "api.acmeinc.com", 
          "Accept" => "_/_", 
          "Connection" => "Keep-Alive", 
          "User-Agent" => "moesifapi-php/1.1.0",
          "Content-Type" => "application/json", 
          "Content-Length" => "126", 
          "Accept-Encoding" => "gzip"), 
         "body" => array(
          "review_id" => 132232, 
          "item_id" => "ewdcpoijc0", 
          "liked" => false
        )
    ),
    "response" => array(
        "time" => $rspdate->format(DateTime::ISO8601), 
        "status" => 500, 
        "headers" => array(
          "Date" => "Tue, 12 June 2020 23:46:49 GMT", 
          "Vary" => "Accept-Encoding", 
          "Pragma" => "no-cache", 
          "Expires" => "-1", 
          "Content-Type" => "application/json; charset=utf-8", 
          "X-Powered-By" => "ARR/3.0", 
          "Cache-Control" => "no-cache", 
          "Arr-Disable-Session-Affinity" => "true"), 
          "body" => array(
            "item_id" => "13221", 
            "title" => "Red Brown Chair",
            "description" => "Red brown chair for sale",
            "price" => 22.23
        )
    ),
    "metadata" => array(
        "foo" => "bar" 
    ),
    "user_id" => "12345",
    "company_id" => "67890",
    "session_token" => "23jdf0owekfmcn4u3qypxg09w4d8ayrcdx8nu2ngs98y18cx98q3yhwmnhcfx43f"     
);

$apiClient = MoesifApi::getInstance("Your Moesif Application Id", ['fork'=>true, 'debug'=>false]);
$apiClient->createEvent($event);

Update a Single User

Create or update a user profile in Moesif. The metadata field can be any customer demographic or other info you want to store. Only the user_id field is required.

use Moesif\Sender\MoesifApi;

// Only userId is required.
// Campaign object is optional, but useful if you want to track ROI of acquisition channels
// See https://www.moesif.com/docs/api#users for campaign schema
// metadata can be any custom object
$user = array(
    "user_id" => "12345",
    "company_id" => "67890", // If set, associate user with a company object
    "campaign" => array(
        "utm_source" => "google",
        "utm_medium" => "cpc",
        "utm_campaign" => "adwords",
        "utm_term" => "api+tooling",
        "utm_content" => "landing"
    ),
    "metadata" => array(
        "email" => "john@acmeinc.com",
        "first_name" => "John",
        "last_name" => "Doe",
        "title" => "Software Engineer",
        "sales_info" => array(
            "stage" => "Customer",
            "lifetime_value" => 24000,
            "account_owner" => "mary@contoso.com"
        )
    )
);

$apiClient = MoesifApi::getInstance("Your Moesif Application Id", ['fork'=>true, 'debug'=>false]);
$apiClient->updateUser($user);

Update Users in Batch

Similar to update user, but used to update a list of users in one batch. Only the user_id field is required.

use Moesif\Sender\MoesifApi;

$userA = array(
    "user_id" => "12345",
    "company_id" => "67890", // If set, associate user with a company object
    "campaign" => array(
        "utm_source" => "google",
        "utm_medium" => "cpc",
        "utm_campaign" => "adwords",
        "utm_term" => "api+tooling",
        "utm_content" => "landing"
    ),
    "metadata" => array(
        "email" => "john@acmeinc.com",
        "first_name" => "John",
        "last_name" => "Doe",
        "title" => "Software Engineer",
        "sales_info" => array(
            "stage" => "Customer",
            "lifetime_value" => 24000,
            "account_owner" => "mary@contoso.com"
        )
    )
);

$userB = array(
    "user_id" => "1234",
    "company_id" => "6789", // If set, associate user with a company object
    "campaign" => array(
        "utm_source" => "google",
        "utm_medium" => "cpc",
        "utm_campaign" => "adwords",
        "utm_term" => "api+tooling",
        "utm_content" => "landing"
    ),
    "metadata" => array(
        "email" => "john@acmeinc.com",
        "first_name" => "John",
        "last_name" => "Doe",
        "title" => "Software Engineer",
        "sales_info" => array(
            "stage" => "Customer",
            "lifetime_value" => 24000,
            "account_owner" => "mary@contoso.com"
        )
    )
);

$users = array($userA, $userB);

$apiClient = MoesifApi::getInstance("Your Moesif Application Id", ['fork'=>true, 'debug'=>false]);
$apiClient->updateUsersBatch($users);

Update a Single Company

Create or update a company profile in Moesif. The metadata field can be any company demographic or other info you want to store. Only the company_id field is required.

use Moesif\Sender\MoesifApi;

// Only companyId is required.
// Campaign object is optional, but useful if you want to track ROI of acquisition channels
// See https://www.moesif.com/docs/api#update-a-company for campaign schema
// metadata can be any custom object
$company = array(
    "company_id" => "67890",
    "company_domain" => "acmeinc.com", // If domain is set, Moesif will enrich your profiles with publicly available info 
    "campaign" => array(
        "utm_source" => "google",
        "utm_medium" => "cpc",
        "utm_campaign" => "adwords",
        "utm_term" => "api+tooling",
        "utm_content" => "landing"
    ),
    "metadata" => array(
        "org_name" => "Acme, Inc",
        "plan_name" => "Free",
        "deal_stage" => "Lead",
        "mrr" => 24000,
        "demographics" => array(
            "alexa_ranking" => 500000,
            "employee_count" => 47
        )
    )
);

$apiClient = MoesifApi::getInstance("Your Moesif Application Id", ['fork'=>true, 'debug'=>false]);
$apiClient->updateCompany($company);

Update Companies in Batch

Similar to update company, but used to update a list of companies in one batch. Only the company_id field is required.

use Moesif\Sender\MoesifApi;

$companyA = array(
    "company_id" => "67890",
    "company_domain" => "acmeinc.com", // If domain is set, Moesif will enrich your profiles with publicly available info 
    "campaign" => array(
        "utm_source" => "google",
        "utm_medium" => "cpc",
        "utm_campaign" => "adwords",
        "utm_term" => "api+tooling",
        "utm_content" => "landing"
    ),
    "metadata" => array(
        "org_name" => "Acme, Inc",
        "plan_name" => "Free",
        "deal_stage" => "Lead",
        "mrr" => 24000,
        "demographics" => array(
            "alexa_ranking" => 500000,
            "employee_count" => 47
        )
    )
);

$companyB = array(
    "company_id" => "6789",
    "company_domain" => "acmeinc.com", // If domain is set, Moesif will enrich your profiles with publicly available info 
    "campaign" => array(
        "utm_source" => "google",
        "utm_medium" => "cpc",
        "utm_campaign" => "adwords",
        "utm_term" => "api+tooling",
        "utm_content" => "landing"
    ),
    "metadata" => array(
        "org_name" => "Acme, Inc",
        "plan_name" => "Free",
        "deal_stage" => "Lead",
        "mrr" => 24000,
        "demographics" => array(
            "alexa_ranking" => 500000,
            "employee_count" => 47
        )
    )
);

$companies = array($companyA, $companyB);

$apiClient = MoesifApi::getInstance("Your Moesif Application Id", ['fork'=>true, 'debug'=>false]);
$apiClient->updateCompaniesBatch($companies);

moesif/moesifapi-php 适用场景与选型建议

moesif/moesifapi-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 359 次下载、GitHub Stars 达 4, 最近一次更新时间为 2017 年 04 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 moesif/moesifapi-php 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 359
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 16
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 5
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2017-04-09