承接 geovanefss/laravel-api-moloni 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

geovanefss/laravel-api-moloni

Composer 安装命令:

composer require geovanefss/laravel-api-moloni

包简介

A PHP package for interacting with Moloni APIs

README 文档

README

https://packagist.org/packages/geovanefss/laravel-api-moloni

Supported PHP Versions GitHub Releases Maintained - Yes

Installation

To install this package, ensure you have Composer installed on your system. Then, run the following command in your project directory:

composer require geovanefss/laravel-api-moloni

Environment Configuration

In your .env file, define the necessary environment variables to configure the Moloni API. This will keep your credentials secure and allow for easy configuration changes.

MOLONI_GRANT_TYPE=password
MOLONI_CLIENT_ID=your_client_id
MOLONI_CLIENT_SECRET=your_client_secret
MOLONI_USERNAME=your_username
MOLONI_PASSWORD=your_password

You can adjust these values based on your Moloni API credentials and usage requirements.

Usage Example

Below is an example demonstrating how to use this package in your Laravel project:

<?php

require_once('vendor/autoload.php');

use Dotenv\Dotenv;
use Geovanefss\LaravelApiMoloni\Exceptions\ApiException;
use Geovanefss\LaravelApiMoloni\Exceptions\TokenException;
use Geovanefss\LaravelApiMoloni\Exceptions\ValidationException;
use Geovanefss\LaravelApiMoloni\Moloni;

try {
    // Load environment variables
    $dotenv = Dotenv::createUnsafeImmutable(__DIR__);
    $dotenv->safeLoad();

    // Set Moloni API configuration using environment variables
    $configs = [
        // Required (see: https://www.moloni.pt/dev/autenticacao/)
        'grant_type' => getenv('MOLONI_GRANT_TYPE'),

        // Required
        'client_id' => getenv('MOLONI_CLIENT_ID'),

        // Required
        'client_secret' => getenv('MOLONI_CLIENT_SECRET'),

        // Required (for authorize)
        'response_type' => getenv('MOLONI_RESPONSE_TYPE'),
        
        // Required (for authorize and grant_type: authorization_code)
        'redirect_uri' => getenv('MOLONI_REDIRECT_URI'),

        // Required (for grant_type: authorization_code)
        'authorization_code' => getenv('MOLONI_AUTHORIZATION_CODE'),

        // Required (for grant_type: password)
        'username' => getenv('MOLONI_USERNAME'),

        // Required (for grant_type: password)
        'password' => getenv('MOLONI_PASSWORD'),

        // Required (for grant_type: refresh_token)
        'refresh_token' => getenv('MOLONI_REFRESH_TOKEN'),
    ];
    
    // Initialize Moloni instance
    $moloni = new Moloni($configs);

    // Start Debug API
    $moloni->startDebug(); // default is to not Debug

    // Stop Debug API
    $moloni->stopDebug(); // default is to not Debug

    // Stop Validate API
    $moloni->stopValidate(); // default is to Validate

    // Start Validate API
    $moloni->startValidate(); // default is to Validate

    // Example: Fetch user profile from Moloni API
    $resp = $moloni->myProfile()->getMe();

    // Output the response in a readable format
    var_dump(json_encode($resp, JSON_PRETTY_PRINT));

} catch (ApiException | ValidationException | TokenException $e) {
    // Handle Moloni API-specific exceptions
    var_dump(get_class($e) . ': ' . $e->toString());
} catch (Exception $e) {
    // Handle general exceptions
    var_dump(get_class($e) . ': ' . $e->getMessage());
}

Explanation

Using Environment Variables

By placing the configuration values in the .env file, you avoid hard-coding sensitive data like client credentials and user passwords. This makes the application:

  • Easier to configure: Modify .env for different environments (e.g., production, staging, development).
  • More secure: Credentials are not exposed in source code.

Steps Breakdown:

  1. Environment Setup: Define all the necessary environment variables for the Moloni API configuration in the .env file.
  2. Load Environment Variables: The Dotenv library is used to load these variables dynamically.
  3. Configure the API: Pass the loaded environment variables to the Moloni API configuration array.

Moloni's API Documentation

For more details, please refer to the official Moloni API documentation:

geovanefss/laravel-api-moloni 适用场景与选型建议

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

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

围绕 geovanefss/laravel-api-moloni 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-23