作者 tangxuhui

更新

... ... @@ -3,6 +3,7 @@ module gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway
go 1.16
require (
github.com/astaxie/beego v1.12.3
github.com/beego/beego/v2 v2.0.1
github.com/boombuler/barcode v1.0.1
github.com/dgrijalva/jwt-go v3.2.0+incompatible
... ...
package domain
import "time"
const (
loginTokenSecret string = "bbe35ad433dd8e67"
)
type LoginToken struct {
Account string `json:"account"`
CompanyId int64 `json:"companyId"`
DepartmentId int64 `json:"departmentId"`
// 账号
Account string `json:"account"`
// 对应平台
Platform string `json:"platform"`
// 公司id
CompanyId int64 `json:"companyId"`
// 组织id
OrganizationId int64 `json:"organizationId"`
// 登录凭证存储
AccessToken string `json:"accessToken"`
// 刷新登录凭证
RefreshToken string `json:"refreshToken"`
// 登录凭证过期时间,时间戳精度秒
AccessExpired int64 `json:"accessExpired"`
// 刷新登录凭证过期时间,时间戳精度秒
RefreshExpired int64 `json:"refreshExpired"`
// 创建时间
CreatedTime time.Time `json:"createdTime"`
// 更新时间
UpdatedTime time.Time `json:"updatedTime"`
}
func (t *LoginToken) GenerateAccessToken() error {
... ...
package service_gateway
import (
"time"
"github.com/astaxie/beego/httplib"
)
type HttplibAlliedCreationBasic struct {
connectTimeout time.Duration
readWriteTimeout time.Duration
BaseUrL string
}
func (gateway HttplibAlliedCreationBasic) createRequest(url string, method string) *httplib.BeegoHTTPRequest {
var request *httplib.BeegoHTTPRequest
switch method {
case "get":
request = httplib.Get(url)
case "post":
request = httplib.Post(url)
case "put":
request = httplib.Put(url)
case "delete":
request = httplib.Delete(url)
case "head":
request = httplib.Head(url)
default:
request = httplib.Get(url)
}
return request.SetTimeout(gateway.connectTimeout, gateway.readWriteTimeout)
}
func (gateway HttplibAlliedCreationBasic) getResponseData(result GatewayResponse) {
}
//GetDictionarysByCode 根据code获取字典数据
func (gateway HttplibAlliedCreationBasic) GetDictionarysByCode(param map[string]interface{}) error {
url := gateway.BaseUrL + "/dictionarys/dictionary-code"
req := gateway.createRequest(url, "post")
req, err := req.JSONBody(param)
if err != nil {
return err
}
var result GatewayResponse
err = req.ToJSON(&result)
if err != nil {
return err
}
return nil
}
... ...
package service_gateway
import (
"encoding/json"
)
//GatewayResponse 统一消息返回格式
type GatewayResponse struct {
Code int `json:"code"`
Msg string `json:"msg"`
Data json.RawMessage `json:"data"`
}
... ...
package snowflake
import (
"github.com/linmadan/egglib-go/utils/snowflake"
)
// 这里workId进行分组防止数组序列化时报错
func NextIdentify(workId int64) (int64, error) {
IdWorker, err := snowflake.NewIdWorker(workId)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
return id, err
}