承接 hejunjie/ip138 相关项目开发

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

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

hejunjie/ip138

Composer 安装命令:

composer require hejunjie/ip138

包简介

PHP 封装的 IP138 API SDK, 简化 IP、手机号归属地、天气查询信息接口以及二维码生成接口调用 | PHP SDK for IP138 API integration: IP lookup, mobile attribution, weather, QR code and more.

README 文档

README

PHP SDK for IP138 — IP lookup, mobile attribution, weather queries, and QR code generation

English简体中文

While working on multiple projects, I frequently needed to call IP138 APIs. Since there was no official SDK, I had to write HTTP requests, assemble parameters, and handle responses from scratch every time — a lot of repetitive work.

So I wrapped all of IP138's currently available APIs into this PHP SDK. It makes integration much simpler in my own projects, and hopefully helps others with similar needs.

This project has been parsed by Zread — click to view a quick structural overview.

Features

  • Covers all IP138 open APIs: IP lookup, mobile attribution, weather queries, and QR code generation
  • Supports both global token configuration and per-call token passing — convenient yet flexible
  • Four API endpoints available: domestic/global, HTTP/HTTPS
  • Response data matches the official IP138 API documentation exactly — no extra learning curve
  • Requires PHP >= 8.1

Installation

composer require hejunjie/ip138

Quick Start

Each IP138 API uses a separate token. Two configuration approaches are available:

Option 1: Global Configuration (recommended for calling multiple APIs)

<?php

use Hejunjie\Ip138\IP138;

// Four API endpoints available:
//   IP138::URL_DOMESTIC_HTTP    — Domestic HTTP
//   IP138::URL_DOMESTIC_HTTPS   — Domestic HTTPS
//   IP138::URL_FOREIGN_HTTP     — Global HTTP
//   IP138::URL_FOREIGN_HTTPS    — Global HTTPS

$ip138 = new IP138(IP138::URL_DOMESTIC_HTTPS, [
    'ipdata'  => 'your IP lookup token',
    'mobile'  => 'your mobile attribution token',
    'qrcode'  => 'your QR code token',
    'weather' => 'your weather query token',
]);

// IP lookup
$result = $ip138->ipLookup('47.239.212.111');
print_r($result);

// Mobile attribution
$result = $ip138->mobileLookup('13800138000');

// Weather query
$result = $ip138->weatherLookup(code: '110000', type: 7);

// QR code generation
$path = $ip138->qrcodeLookup('https://example.com', '/save/path');

Option 2: Per-call Token (for simple use cases)

<?php

use Hejunjie\Ip138\IP138;

$result = (new IP138(IP138::URL_DOMESTIC_HTTPS))
    ->ipLookup('47.239.212.111', token: 'your IP lookup token');

print_r($result);

Sample Response

Array
(
    [ret] => ok
    [ip] => 47.239.212.111
    [data] => Array
        (
            [0] => 中国
            [1] => 香港
            [2] => 香港
            [3] =>
            [4] => 阿里云
            [5] => 999077
            [6] => 00852
            [7] => 数据中心
        )
)

API Reference

Method Description Returns Docs
ipLookup(ip, datatype, callback, token) IP address lookup array API docs
mobileLookup(mobile, datatype, callback, token) Mobile number attribution array API docs
weatherLookup(code, ip, callback, type, style, token) Weather query array API docs
qrcodeLookup(text, path, name, config, token) QR code generation string (absolute local path) API docs

The token parameter is optional for all methods — if a token was provided in the constructor, it will be used automatically.

Error Handling

All API methods throw Hejunjie\Ip138\Exceptions\IP138Exception when a request fails. It's recommended to catch it in production:

use Hejunjie\Ip138\Exceptions\IP138Exception;

try {
    $result = $ip138->ipLookup('47.239.212.111');
} catch (IP138Exception $e) {
    echo 'Request failed: ' . $e->getMessage();
}

Directory Structure

src/
├── IP138.php                  # Entry point — wraps all four API methods
├── Exceptions/
│   └── IP138Exception.php     # Exception class
└── Services/
    ├── BaseService.php        # Base service (HTTP requests, shared logic)
    ├── IpService.php          # IP lookup service
    ├── MobileService.php      # Mobile attribution service
    ├── QrcodeService.php      # QR code generation service
    └── WeatherService.php     # Weather query service

Motivation

The motivation is simple: eliminate repetitive work. IP138's APIs are not complicated on their own, but writing the same request logic across multiple projects is inefficient and hard to maintain. By wrapping them into an SDK, a single update propagates to every project that depends on it.

Contact

Questions or suggestions? Feel free to open an issue on GitHub Issues.

hejunjie/ip138 适用场景与选型建议

hejunjie/ip138 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 06 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-16