package model import ( "cu-helper/cus-eng-con-sys/cryptokit" "reflect" ) /* /zjgd/frm/commonController/getToken */ /* 用途 1、/zjgd/frm/acceptanceController/udpateAccInfo.action时入参使用 */ // GetTokenReq 获取Token type GetTokenReq struct { Ranstr string `map:"ranstr"` Timestamp string `map:"timestamp"` } func NewGetToken() *GetTokenReq { getToken := new(GetTokenReq) getToken.Ranstr = cryptokit.RandomStr(true, 10, 32) getToken.Timestamp = cryptokit.GetTimeStamp() return getToken } // GenReqParam 返回加密后的请求参数 func (th *GetTokenReq) GenReqParam() map[string]string { th.encrypt() return th.structToMap() } func (th *GetTokenReq) structToMap() map[string]string { result := make(map[string]string) t := reflect.TypeOf(*th) v := reflect.ValueOf(*th) for i := 0; i < t.NumField(); i++ { field := t.Field(i) value := v.Field(i) // Use the tag value as the key in the map, if it exists; otherwise, use the field name. tag := field.Tag.Get("map") if tag == "" { tag = field.Name } result[tag] = value.String() } return result } func (th *GetTokenReq) encrypt() { v := reflect.ValueOf(th).Elem() for i := 0; i < v.NumField(); i++ { field := v.Field(i) if field.CanSet() { field.SetString(cryptokit.Encrypt(field.String())) } } }