# oauth手册

⽂档版本 内容修订 修订⼈ 修订⽇期
V1.0 初稿 郭程豪 2023-09-01

# 目录

# 服务发现接入规范

# 基础信息

  • clientId:可以使用用户认证平台已存在发clientID, 也可以自己生成

  • clientType:自定义 clientType 需要先在用户认证平台中注册

服务名 clientType
通用中控 ccs-pro
通用运维管理平台 ccs-pro-ops
HULK hulk
配置平台大客户 cloud
StarRiver starRiver
V3Pro v3pro_server
用户认证平台 sansi-account

# 上报服务信息

# nodejs

import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
import { Server } from 'node-ssdp';
import { ConfigService } from '@nestjs/config';
import * as log4js from 'log4js';
import * as dayjs from 'dayjs';

@Injectable()
export class SsdpService implements OnModuleInit, OnModuleDestroy {
  private ssdpServer: Server;
  private logger = log4js.getLogger();

  constructor(private configService: ConfigService) {
    this.ssdpServer = new Server({
      location: {
        protocol: 'http://', // 协议
        port: this.configService.get<number>('port'), // 端口
        path: '', // url 前缀,不需要填写
      },
      headers: {
        NAME: this.configService.get<string>('clientType'),
      },
      // udn: 'uuid:deviceId, // Unique Device Name,自动生成,设备的唯一标识符,它通常采用 uuid:YOUR_UUID_HERE 的形式。
    });
    this.ssdpServer.addUSN(this.configService.get<string>('clientType') + ':' + this.configService.get<string>('clientId')); // 网络唯一标识
    this.logger.log(this.ssdpServer._extraHeaders);
    this.logger.log(this.ssdpServer._usns);
  }

  // 启动时上报服务
  onModuleInit() {
    this.ssdpServer.start();
  }

  // 关闭时销毁服务
  onModuleDestroy() {
    this.ssdpServer.stop();
  }
}

# go

import "github.com/koron/go-ssdp"

func InitSSDP() error {
	common.Logger.Infoln("--- InitSSDP --- ")
	protocol := "http"
	port := viper.GetString("httpPort")
	if viper.GetBool("https") {
		protocol = "https"
		port = viper.GetString("httpsPort")
	}
	deviceId := viper.GetString("clientDeviceId")
	clientId := viper.GetString("clientId")
	if clientId == "" {
		clientId = deviceId
	}
	clientType := viper.GetString("clientType")

	ips, err := ToolGetIp()
	common.Logger.Infoln(ips)
	if err == nil {
		for _, ip := range ips {
			ad, err := ssdp.Advertise(
				clientType, // 使用你的 ST
				"uuid:"+ip+"::"+clientType+":"+clientId,     // 使用你的 USN
				protocol+"://"+ip+":"+port,                  // 设备描述的位置
				runtime.Version()+" UPnP/1.1 go-ssdp/0.0.4", // 服务器字符串
				1800)
			err = ad.Alive()
			if err != nil {
				common.Logger.Fatal(err)
			}
		}
	}
	return err
}