10 KiB
10 KiB
External Integrations
Analysis Date: 2026-03-27
APIs & External Services
Database / Cache Infrastructure:
- PostgreSQL - 主业务数据库,GORM 通过 DSN 建连并配置连接池,见
pkg/database/postgres.go- Client:
gorm.io/gorm+gorm.io/driver/postgres - Config:
pkg/config/config.go的database.*
- Client:
- Redis - Token、缓存、Asynq 后端、限流存储、微信配置缓存,见
pkg/database/redis.go、pkg/queue/client.go、cmd/api/main.go、internal/service/wechat_config/service.go- Client:
github.com/redis/go-redis/v9 - Config:
pkg/config/config.go的redis.*
- Client:
Object Storage:
- S3-compatible object storage - 文件直传、下载、导入任务临时落盘,见
pkg/storage/s3.go、pkg/storage/service.go- SDK/Client:
github.com/aws/aws-sdk-go - Config:
storage.provider、storage.s3.*、storage.presign.*inpkg/config/config.go - Used by:
internal/handler/admin/storage.go、internal/routes/storage.go、internal/task/iot_card_import.go、internal/task/device_import.go
- SDK/Client:
WeChat ecosystem:
- WeChat Official Account OAuth - 公众号登录与用户信息拉取,见
pkg/wechat/official_account.go、internal/service/client_auth/service.go- SDK/Client:
github.com/ArtisanCloud/PowerWeChat/v3 - Config source:
tb_wechat_configviainternal/model/wechat_config.go
- SDK/Client:
- WeChat Mini Program login -
code2session换取 openid/session_key,见pkg/wechat/miniapp.go、internal/service/client_auth/service.go- Transport: 标准
net/http - Config source:
tb_wechat_config
- Transport: 标准
- WeChat Pay - JSAPI/H5 下单、查单、关单、支付回调验签,见
pkg/wechat/payment.go、pkg/wechat/config.go、internal/handler/callback/payment.go- SDK/Client:
github.com/ArtisanCloud/PowerWeChat/v3 - Config source:
tb_wechat_config
- SDK/Client:
Payment gateway:
- Fuiou - 预下单、回调解析、签名与验签 SDK 已存在,见
pkg/fuiou/client.go、pkg/fuiou/wxprecreate.go、pkg/fuiou/notify.go- SDK/Client: repo-local
pkg/fuiou - Config source:
tb_wechat_configprovider=fuiou,字段位于internal/model/wechat_config.go - Callback endpoint:
internal/handler/callback/payment.go - Current state: 回调处理存在
TODO,当前路径解析 XML 但未按配置创建客户端做验签,见internal/handler/callback/payment.go
- SDK/Client: repo-local
SMS gateway:
- SMS HTTP gateway - 验证码/消息发送,见
pkg/sms/client.go、cmd/api/main.go- Client: repo-local
pkg/sms - Config:
sms.gateway_url、sms.username、sms.password、sms.signatureinpkg/config/config.go
- Client: repo-local
Business Gateway / IoT upstream:
- Gateway API - 设备信息、卡状态、流量、实名链接、设备限速/切卡等外部接口,见
internal/gateway/client.go、internal/gateway/device.go、internal/gateway/flow_card.go- Auth: appId + appSecret,自定义 AES-128-ECB 加密 + MD5 签名,见
internal/gateway/client.go - Config:
gateway.base_url、gateway.app_id、gateway.app_secret、gateway.timeoutinpkg/config/config.go - Used by:
internal/service/iot_card/gateway_service.go、internal/service/device/gateway_service.go、internal/task/polling_handler.go
- Auth: appId + appSecret,自定义 AES-128-ECB 加密 + MD5 签名,见
Data Storage
Databases:
- PostgreSQL
- Connection keys:
JUNHONG_DATABASE_HOST,JUNHONG_DATABASE_PORT,JUNHONG_DATABASE_USER,JUNHONG_DATABASE_PASSWORD,JUNHONG_DATABASE_DBNAME,JUNHONG_DATABASE_SSLMODE - Connection code:
pkg/database/postgres.go - Runtime wiring:
cmd/api/main.go,cmd/worker/main.go,docker-compose.prod.yml
- Connection keys:
Redis:
- Redis is shared across auth, cache, rate limiting, WeChat config cache, and Asynq
- Connection keys:
JUNHONG_REDIS_ADDRESS,JUNHONG_REDIS_PORT,JUNHONG_REDIS_PASSWORD,JUNHONG_REDIS_DB - Connection code:
pkg/database/redis.go - Asynq reuse:
pkg/queue/client.go,pkg/queue/server.go - Config cache key example:
wechat:config:activeininternal/service/wechat_config/service.go
- Connection keys:
File Storage:
- S3-compatible bucket storage
- Provider implementation:
pkg/storage/s3.go - Upload URL API:
internal/routes/storage.go - Import consumers download to temp files before parsing:
internal/task/iot_card_import.go,internal/task/device_import.go
- Provider implementation:
Local filesystem:
- Logs are persisted to
/app/logsinside containers and mounted by Compose, seepkg/config/defaults/config.yaml,Dockerfile.api,Dockerfile.worker,docker-compose.prod.yml - OpenAPI runtime export writes to
logs/openapi.yaml, seecmd/api/main.go,cmd/api/docs.go
Authentication & Identity
B-side auth:
- Redis-backed token management and JWT manager initialization occur in
cmd/api/main.go- Components:
pkg/auth, Redis token manager, JWT manager
- Components:
C-side identity via WeChat:
- 公众号 OAuth login path uses active config from
tb_wechat_config, seeinternal/service/client_auth/service.go - 小程序 login path uses WeChat
code2session, seeinternal/service/client_auth/service.go,pkg/wechat/miniapp.go
Monitoring & Observability
Application logs:
- Zap + Lumberjack app/access loggers, see
pkg/logger/logger.go
Request tracing:
- Access logger captures request metadata and request/response bodies, see
pkg/logger/middleware.go
SQL observability:
- GORM logger sends query errors and slow queries to Zap, see
pkg/database/postgres.go
Container health:
- API health endpoint is used by Docker health checks and Compose dependency ordering, see
Dockerfile.api,docker-compose.prod.yml
Queue, Scheduling, and Runtime Integrations
Asynq runtime:
- Worker server consumes Redis-backed queues configured in
queue.*, seepkg/queue/server.go,cmd/worker/main.go - Task submission is wrapped in
pkg/queue/client.go
Registered task domains:
- Email, data sync, SIM status sync, IoT card import, device import, commission stats, commission calculation, polling, package activation, order expiration, alert check, data cleanup, see
pkg/queue/handler.go
Schedulers:
- Worker process starts an internal polling scheduler plus an Asynq Scheduler for recurring jobs, see
cmd/worker/main.go - Recurring jobs include order expiration, alert checks, and nightly cleanup, see
cmd/worker/main.go
Docs Generation Integrations
OpenAPI generation:
- Repo-local generator wraps
swaggest/openapi-goand exports YAML, seepkg/openapi/generator.go - Runtime generation during API boot writes
logs/openapi.yaml, seecmd/api/main.go,cmd/api/docs.go - Manual generation command writes
docs/admin-openapi.yaml, seeMakefile,cmd/gendocs/main.go - Route registration for docs reuses production route registration, see
internal/routes/routes.go,pkg/openapi/handlers.go
CI/CD & Deployment
Hosting / Runtime:
- Dockerized API and Worker services are the deployment target, see
Dockerfile.api,Dockerfile.worker,docker-compose.prod.yml
Registry:
- Images are pushed to a private registry declared in
.gitea/workflows/deploy.yaml
CI Pipeline:
- Gitea workflow builds both images, pushes tag + SHA tags, copies
docker-compose.prod.yml, and executesdocker compose pull/up -d, see.gitea/workflows/deploy.yaml
Migration tooling:
- API image bundles
golang-migrateand migration files, seeDockerfile.api - Local migration shortcuts are defined in
Makefile
Environment Configuration
Required env vars:
- Database:
JUNHONG_DATABASE_HOST,JUNHONG_DATABASE_PORT,JUNHONG_DATABASE_USER,JUNHONG_DATABASE_PASSWORD,JUNHONG_DATABASE_DBNAME - Redis:
JUNHONG_REDIS_ADDRESSplus optional Redis port/password/db tuning vars - JWT:
JUNHONG_JWT_SECRET_KEY
Optional env vars by integration:
- Storage:
JUNHONG_STORAGE_PROVIDER,JUNHONG_STORAGE_S3_* - SMS:
JUNHONG_SMS_* - Gateway:
JUNHONG_GATEWAY_* - Logging:
JUNHONG_LOGGING_*
Secrets location:
- Default app config is embedded from
pkg/config/defaults/config.yaml - Most runtime secrets are expected through environment variables bound in
pkg/config/loader.go - WeChat / payment provider secrets are stored in database table
tb_wechat_config, seeinternal/model/wechat_config.go - Deployment wiring exists in
docker-compose.prod.ymland.gitea/workflows/deploy.yaml; these files should be treated as sensitive and are not reproduced here
Webhooks & Callbacks
Incoming:
- WeChat Pay callback:
POST /api/callback/wechat-pay, handler ininternal/handler/callback/payment.go - Fuiou Pay callback:
POST /api/callback/fuiou-pay, handler ininternal/handler/callback/payment.go - Alipay callback stub:
POST /api/callback/alipay, handler ininternal/handler/callback/payment.go
Outgoing:
- WeChat OAuth and payment API calls from
pkg/wechat/*.go - Gateway API calls from
internal/gateway/*.go - SMS API calls from
pkg/sms/client.go - S3 object storage calls from
pkg/storage/s3.go
Evidence
go.modREADME.mdcmd/api/main.gocmd/api/docs.gocmd/worker/main.gocmd/gendocs/main.gopkg/config/config.gopkg/config/loader.gopkg/config/defaults/config.yamlpkg/database/postgres.gopkg/database/redis.gopkg/queue/client.gopkg/queue/server.gopkg/queue/handler.gopkg/logger/logger.gopkg/openapi/generator.gopkg/openapi/handlers.gopkg/storage/s3.gopkg/storage/service.gopkg/wechat/config.gopkg/wechat/official_account.gopkg/wechat/miniapp.gopkg/wechat/payment.gopkg/fuiou/client.gopkg/fuiou/wxprecreate.gopkg/fuiou/notify.gopkg/sms/client.gointernal/gateway/client.gointernal/gateway/device.gointernal/gateway/flow_card.gointernal/model/wechat_config.gointernal/service/wechat_config/service.gointernal/service/client_auth/service.gointernal/service/client_order/service.gointernal/routes/storage.gointernal/handler/callback/payment.gointernal/task/iot_card_import.gointernal/task/device_import.goMakefileDockerfile.apiDockerfile.workerdocker-compose.prod.yml.gitea/workflows/deploy.yaml
Integration audit: 2026-03-27