123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- /*
- * @Author: wfhou
- * @Date: 2022-05-17 10:07:52
- * @LastEditors: wfhou
- * @LastEditTime: 2022-05-17 14:44:58
- * @FilePath: \SCD\controllers\wsController.go
- * @Description:
- *
- * Copyright (c) 2022 by wfhou/jujutong, All Rights Reserved.
- */
- package controllers
- import (
- "fmt"
- "log"
- "scd_check_tools/conf"
- "scd_check_tools/tools"
- )
- type WsController struct {
- BaseController
- }
- func init() {
- }
- /**
- * @description: 获取ws长连接地址
- * @Author: wfhou
- * @method: get
- * @url: /api/ws/getconnect
- * @content-type: application/json
- * @return json格式的ws连接地址
- */
- // @Summary 获取ws长连接地址
- // @Description 获取ws长连接地址
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param ws_url query string true "WS连接地址获取接口地址"
- // @Param token_url query string true "token获取接口地址"
- // @Success 200 {object} ResultOK 成功
- // @Failure 500 {object} ResultError 失败
- // @router /ws/getconnect [get]
- func (c *WsController) GetWsConnect() {
- //登录的url地址
- token_url := conf.GlobalConfig["token_url"]
- //获取ws的url地址
- get_ws_url := conf.GlobalConfig["ws_url"]
- //获取用户名和密码
- appKey := conf.GlobalConfig["appkey"]
- appSecret := conf.GlobalConfig["appsecret"]
- fss := fmt.Sprintf("{\"appKey\":\"%s\",\"appSecret\":\"%s\"}", appKey, appSecret)
- res, err := tools.PostJson(token_url, fss)
- if err != nil {
- log.Println(err)
- c.Data["json"] = c.ResultError("获取电梯平台的token出错!")
- c.ServeJSON()
- return
- }
- if res == nil {
- c.Data["json"] = c.ResultError("获取ws地址的接口调用失败!")
- c.ServeJSON()
- return
- }
- resTmp := res.(map[string]interface{})
- resTmp2 := resTmp["data"].(map[string]interface{})
- var accessToken interface{}
- if resTmp2["code"] == 0 {
- log.Println(err)
- c.Data["json"] = c.ResultError("返回code错误!")
- c.ServeJSON()
- return
- } else {
- accessToken = resTmp2["accessToken"]
- get_ws_url = get_ws_url + accessToken.(string)
- }
- wsRes, err := tools.PostJson(get_ws_url, "{}")
- if wsRes == nil || err != nil {
- log.Println(err)
- c.Data["json"] = c.ResultError("获取电梯平台的wsurl出错!")
- c.ServeJSON()
- return
- }
- c.Data["json"] = c.ResultOK(wsRes, 0)
- c.ServeJSON()
- }
|