diff --git a/README.md b/README.md new file mode 100644 index 00000000..05db3ed3 --- /dev/null +++ b/README.md @@ -0,0 +1,57 @@ +![](https://aliyunsdk-pages.alicdn.com/icons/AlibabaCloud.svg) + +# YuanJing OpenAPI SDK for Go + +## Requirements +- It's necessary for you to make sure your system have installed Go environment which version greater than 1.12.0. + +## Installation +If you use `go mod` to manage your dependence, you can use the following command: +``` +go get github.com/aliyun/alibabacloud-yjopenapi-go-client 1.0.20221015-beta +``` + +## Usage +``` +import ( + "github.com/aliyun/alibabacloud-yjopenapi-go-client/client/api" + "github.com/aliyun/alibabacloud-yjopenapi-go-client/client/model" +) + +configuration := api.DefaultConfiguration +configuration.Host = "host" +configuration.AccessKey = "Your Access Key" +configuration.SecretKey = "Your Secret Key" + +client := api.NewAPIClient(configuration) + +// {{Api}},{{Method}},{{Param}} is placeholder, take a look at Explain Of Usage Placeholder +result, response, error := client.{{Api}}.{{Method}}(&model.{{Params}}{}) + +// OpenAPI TraceId +traceId := response.Header.Get(client.Trace_Id) +// OpenAPI Status Code +statusCode := response.Header.Get(client.Result_Status) + +// OpenAPI result +_ := result +``` + +## Explain Of Usage Placeholder + +| Api | Method | Params | Result | Description | +| ------------ | ------------- | ------------- | ------------- | ------------- | + | *InteractiveApi* | **GetParty** | *GetPartyForms* | *InteractiveGetPartyResult* | 获取派对 | + | *InteractiveApi* | **GetPartyStatus** | *GetPartyStatusForms* | *InteractiveGetPartyStatusResult* | 查询派对游戏状态 | + | *InteractiveApi* | **JoinParty** | *JoinPartyForms* | *InteractiveJoinPartyResult* | 加入分配席位 | + | *InteractiveApi* | **KickOutUser** | *KickOutUserForms* | *InteractiveKickOutUserResult* | 踢出派对 | + | *InteractiveApi* | **ModifySeats** | *ModifySeatsForms* | *InteractiveModifySeatsResult* | 修改席位 | + | *InteractiveApi* | **ShutDownParty** | *ShutDownPartyForms* | *InteractiveShutDownPartyResult* | 关闭派对 | + | *TokenApi* | **GetTriple** | | *GetTripleResult* | 获取临时安全令牌 | + +## License +[Apache-2.0](http://www.apache.org/licenses/LICENSE-2.0) + +Copyright (c) 2009-present, Alibaba Cloud All rights reserved. + + diff --git a/client/api/client.go b/client/api/client.go new file mode 100644 index 00000000..203bd935 --- /dev/null +++ b/client/api/client.go @@ -0,0 +1,422 @@ +// Package client +/* + * YuanJing OpenAPI SDK for Go + * + * + */ +package api + +import ( + "bytes" + "crypto/md5" + "crypto/rand" + "encoding/hex" + "encoding/json" + "errors" + "fmt" + "net/http" + "net/url" + "reflect" + "regexp" + "sort" + "strconv" + "strings" + "time" + "unicode/utf8" +) + +const ( + Trace_Id string = "Traceid" + Result_Status string = "Result-Status" +) + +var ( + jsonCheck = regexp.MustCompile("(?i:[application|text]/json)") + xmlCheck = regexp.MustCompile("(?i:[application|text]/xml)") + + DefaultConfiguration = NewConfiguration() +) + +// APIClient manages communication with the API v1.0.20221015-beta +// In most cases there should be only one, shared, APIClient. +type APIClient struct { + cfg *Configuration + common service // Reuse a single struct instead of allocating one for each service on the heap. + + // API Services + + InteractiveApi *InteractiveApiService + + TokenApi *TokenApiService +} + +type service struct { + client *APIClient +} + +// NewAPIClient creates a new API client. Requires a userAgent string describing your application. +// optionally a custom http.Client to allow for advanced features such as caching. +func NewAPIClient(cfg *Configuration) *APIClient { + if cfg.HTTPClient == nil { + cfg.HTTPClient = http.DefaultClient + } + + c := &APIClient{} + c.cfg = cfg + c.common.client = c + + // API Services + c.InteractiveApi = (*InteractiveApiService)(&c.common) + c.TokenApi = (*TokenApiService)(&c.common) + + return c +} + +func atoi(in string) (int, error) { + return strconv.Atoi(in) +} + +// selectHeaderContentType select a content type from the available list. +func selectHeaderContentType(contentTypes []string) string { + if len(contentTypes) == 0 { + return "" + } + if contains(contentTypes, "application/json") { + return "application/json" + } + return contentTypes[0] // use the first content type specified in 'consumes' +} + +// selectHeaderAccept join all accept types and return +func selectHeaderAccept(accepts []string) string { + if len(accepts) == 0 { + return "" + } + + if contains(accepts, "application/json") { + return "application/json" + } + + return strings.Join(accepts, ",") +} + +// contains is a case insenstive match, finding needle in a haystack +func contains(haystack []string, needle string) bool { + for _, a := range haystack { + if strings.ToLower(a) == strings.ToLower(needle) { + return true + } + } + return false +} + +// Verify optional parameters are of the correct type. +func typeCheckParameter(obj interface{}, expected string, name string) error { + // Make sure there is an object. + if obj == nil { + return nil + } + + // Check the type is as expected. + if reflect.TypeOf(obj).String() != expected { + return fmt.Errorf("Expected %s to be of type %s but received %s.", name, expected, reflect.TypeOf(obj).String()) + } + return nil +} + +// parameterToString convert interface{} parameters to string, using a delimiter if format is provided. +func parameterToString(obj interface{}, collectionFormat string) string { + // var delimiter string + + // switch collectionFormat { + // case "pipes": + // delimiter = "|" + // case "ssv": + // delimiter = " " + // case "tsv": + // delimiter = "\t" + // case "csv": + // delimiter = "," + // } + + if reflect.TypeOf(obj).Kind() == reflect.Slice { + // return strings.Trim(strings.Replace(fmt.Sprint(obj), " ", delimiter, -1), "[]") + if marshal, err := json.Marshal(obj); err != nil { + return "" + } else { + return string(marshal) + } + } + if reflect.TypeOf(obj).Kind() == reflect.Struct { + if marshal, err := json.Marshal(obj); err != nil { + return "" + } else { + return string(marshal) + } + } + return fmt.Sprintf("%v", obj) +} + +// callAPI do the request. +func (c *APIClient) callAPI(request *http.Request) (*http.Response, error) { + return c.cfg.HTTPClient.Do(request) +} + +// prepareRequest build the request +func (c *APIClient) prepareRequest( + path string, + method string, + headerParams map[string]string, + queryParams url.Values, + formParams url.Values, +) (localVarRequest *http.Request, err error) { + + var body *bytes.Buffer + + // add form parameters + if strings.HasPrefix(headerParams["Content-Type"], "application/x-www-form-urlencoded") && len(formParams) > 0 { + body = &bytes.Buffer{} + body.WriteString(formParams.Encode()) + // Set Content-Length + headerParams["Content-Length"] = fmt.Sprintf("%d", body.Len()) + } + + // Setup path and query parameters + url, err := url.Parse(path) + if err != nil { + return nil, err + } + + // Adding Query Param + query := url.Query() + for k, v := range queryParams { + for _, iv := range v { + query.Add(k, iv) + } + } + + // Encode the parameters. + url.RawQuery = query.Encode() + + // Generate a new request + if body != nil { + localVarRequest, err = http.NewRequest(method, url.String(), body) + } else { + localVarRequest, err = http.NewRequest(method, url.String(), nil) + } + if err != nil { + return nil, err + } + + // add header parameters, if any + if len(headerParams) > 0 { + headers := http.Header{} + for h, v := range headerParams { + headers.Set(h, v) + } + localVarRequest.Header = headers + } + + // Override request host, if applicable + if c.cfg.Host != "" { + localVarRequest.Host = c.cfg.Host + } + + // Add the user agent to the request. + localVarRequest.Header.Add("User-Agent", "cgw-client/1.0.0/go") + + // prepare sign headers + prepareSignHeader(queryParams, formParams, localVarRequest, c.cfg) + + for header, value := range c.cfg.DefaultHeader { + localVarRequest.Header.Add(header, value) + } + + return localVarRequest, nil +} + +func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err error) { + if strings.Contains(contentType, "application/json") { + if err = json.Unmarshal(b, v); err != nil { + return err + } + return nil + } + return errors.New("undefined response type") +} + +// Prevent trying to import "fmt" +func reportError(format string, a ...interface{}) error { + return fmt.Errorf(format, a...) +} + +// Ripped from https://github.com/gregjones/httpcache/blob/master/httpcache.go +type cacheControl map[string]string + +func parseCacheControl(headers http.Header) cacheControl { + cc := cacheControl{} + ccHeader := headers.Get("Cache-Control") + for _, part := range strings.Split(ccHeader, ",") { + part = strings.Trim(part, " ") + if part == "" { + continue + } + if strings.ContainsRune(part, '=') { + keyval := strings.Split(part, "=") + cc[strings.Trim(keyval[0], " ")] = strings.Trim(keyval[1], ",") + } else { + cc[part] = "" + } + } + return cc +} + +// CacheExpires helper function to determine remaining time before repeating a request. +func CacheExpires(r *http.Response) time.Time { + // Figure out when the cache expires. + var expires time.Time + now, err := time.Parse(time.RFC1123, r.Header.Get("date")) + if err != nil { + return time.Now() + } + respCacheControl := parseCacheControl(r.Header) + + if maxAge, ok := respCacheControl["max-age"]; ok { + lifetime, err := time.ParseDuration(maxAge + "s") + if err != nil { + expires = now + } + expires = now.Add(lifetime) + } else { + expiresHeader := r.Header.Get("Expires") + if expiresHeader != "" { + expires, err = time.Parse(time.RFC1123, expiresHeader) + if err != nil { + expires = now + } + } + } + return expires +} + +func strlen(s string) int { + return utf8.RuneCountInString(s) +} + +func prepareSignHeader(queryParams url.Values, formParams url.Values, localVarRequest *http.Request, cfg *Configuration) { + accessKey := cfg.AccessKey + nonce := randNonce(16) + version := cfg.SignatureVersion + timestamp := time.Now().UTC().Format(time.RFC3339) + method := cfg.SignatureMethod + + values := url.Values{} + values.Add("AccessKey", accessKey) + values.Add("SignatureNonce", nonce) + values.Add("SignatureVersion", version) + values.Add("SignatureMethod", method) + values.Add("Timestamp", timestamp) + if len(queryParams) > 0 { + for s, i := range queryParams { + for _, s2 := range i { + values.Add(s, s2) + } + } + } + if len(formParams) > 0 { + for s, i := range formParams { + for _, s2 := range i { + values.Add(s, s2) + } + } + } + + sign := md5Hex([]byte(getSignRaw(values, localVarRequest.Method, cfg.SecretKey))) + localVarRequest.Header.Add("Signature", sign) + localVarRequest.Header.Add("Accesskey", accessKey) + localVarRequest.Header.Add("Signaturenonce", nonce) + localVarRequest.Header.Add("Signatureversion", version) + localVarRequest.Header.Add("Timestamp", timestamp) + localVarRequest.Header.Add("Signaturemethod", method) +} + +func md5Hex(data []byte) string { + md5Sum := md5.Sum(data) + return hex.EncodeToString(md5Sum[:]) +} + +func getSignRaw(values url.Values, method string, secret string) string { + return secret + "&" + keySignInput(values, method) +} + +func keySignInput(values url.Values, method string) string { + keys := make([]string, 0) + for s, _ := range values { + keys = append(keys, s) + } + sort.Strings(keys) + + stringToSign := method + "&" + encodeURLComponent("/") + + strs := make([]string, 0) + for _, k := range keys { + strs = append(strs, k+"="+encodeURLComponent(values.Get(k))) + } + return stringToSign + "&" + encodeURLComponent(strings.Join(strs, "&")) +} + +func encodeURLComponent(str string) string { + escape := url.QueryEscape(str) + escape = strings.ReplaceAll(escape, "+", "%20") + escape = strings.ReplaceAll(escape, "*", "%2A") + escape = strings.ReplaceAll(escape, "%7E", "~") + return escape +} + +func randNonce(n int) string { + b := make([]byte, n) + rand.Read(b) + return hex.EncodeToString(b) +} + +// GenericError Provides access to the body, error and model on returned errors. +type GenericError struct { + body []byte + error string + model interface{} +} + +// Error returns non-empty string if there was an error. +func (e GenericError) Error() string { + return e.error +} + +// Body returns the raw bytes of the response +func (e GenericError) Body() []byte { + return e.body +} + +// Model returns the unpacked model of the error +func (e GenericError) Model() interface{} { + return e.model +} + +type Configuration struct { + Host string `json:"host"` + Scheme string `json:"scheme"` + DefaultHeader map[string]string `json:"defaultHeader,omitempty"` + AccessKey string `json:"accessKey"` + SecretKey string `json:"secretKey"` + SignatureVersion string `json:"signatureVersion"` + SignatureMethod string `json:"signatureMethod"` + HTTPClient *http.Client +} + +func NewConfiguration() *Configuration { + return &Configuration{ + Scheme: "https", + SignatureVersion: "1.0", + SignatureMethod: "MD5", + HTTPClient: http.DefaultClient, + } +} diff --git a/client/api/interactive_api.go b/client/api/interactive_api.go new file mode 100644 index 00000000..a42ffce5 --- /dev/null +++ b/client/api/interactive_api.go @@ -0,0 +1,481 @@ +// Package client +/* + * YuanJing OpenAPI SDK for Go + * + * + */ +package api + +import ( + "github.com/aliyun/alibabacloud-yjopenapi-go-client/client/model" + "io/ioutil" + "net/http" + "net/url" + "strings" +) + +type InteractiveApiService service + + +// GetParty +/* + * 获取派对 + * @param varForms model.GetPartyForms + */ +func (s *InteractiveApiService) GetParty( + varForms *model.GetPartyForms, +) (model.InteractiveGetPartyResult, *http.Response, error) { + var ( + varHttpMethod = strings.ToUpper("Post") + varReturnValue model.InteractiveGetPartyResult + ) + + // create path and map variables + varPath := s.client.cfg.Scheme + "://" + s.client.cfg.Host + "/interactive/getParty" + + varHeaderParams := make(map[string]string) + varQueryParams := url.Values{} + varFormParams := url.Values{} + + // to determine the Content-Type header + varHttpContentTypes := []string{"application/x-www-form-urlencoded"} + + // set Content-Type header + varHttpContentType := selectHeaderContentType(varHttpContentTypes) + if varHttpContentType != "" { + varHeaderParams["Content-Type"] = varHttpContentType + } + + // to determine the Accept header + varHttpHeaderAccepts := []string{"application/json"} + + // set Accept header + varHttpHeaderAccept := selectHeaderAccept(varHttpHeaderAccepts) + if varHttpHeaderAccept != "" { + varHeaderParams["Accept"] = varHttpHeaderAccept + } + varFormParams.Add("mixGameId", parameterToString(varForms.MixGameId, "")) + varFormParams.Add("userId", parameterToString(varForms.UserId, "")) + varFormParams.Add("reConnect", parameterToString(varForms.ReConnect, "")) + varFormParams.Add("projectId", parameterToString(varForms.ProjectId, "")) + if varForms != nil && varForms.Config != nil { + varFormParams.Add("config", parameterToString(*varForms.Config, "")) + } + + r, err := s.client.prepareRequest(varPath, varHttpMethod, varHeaderParams, varQueryParams, varFormParams) + if err != nil { + return varReturnValue, nil, err + } + + varHttpResponse, err := s.client.callAPI(r) + if err != nil || varHttpResponse == nil { + return varReturnValue, varHttpResponse, err + } + + defer varHttpResponse.Body.Close() + varBody, err := ioutil.ReadAll(varHttpResponse.Body) + if err != nil { + return varReturnValue, varHttpResponse, err + } + + if varHttpResponse.StatusCode < 300 { + // If we succeed, return the data, otherwise pass on to decode error. + err = s.client.decode(&varReturnValue, varBody, varHttpResponse.Header.Get("Content-Type")) + if err == nil { + return varReturnValue, varHttpResponse, err + } + } + + if varHttpResponse.StatusCode >= 300 { + newErr := GenericError{ + body: varBody, + error: varHttpResponse.Status, + } + return varReturnValue, varHttpResponse, newErr + } + + return varReturnValue, varHttpResponse, nil +} + +// GetPartyStatus +/* + * 查询派对游戏状态 + * @param varForms model.GetPartyStatusForms + */ +func (s *InteractiveApiService) GetPartyStatus( + varForms *model.GetPartyStatusForms, +) (model.InteractiveGetPartyStatusResult, *http.Response, error) { + var ( + varHttpMethod = strings.ToUpper("Post") + varReturnValue model.InteractiveGetPartyStatusResult + ) + + // create path and map variables + varPath := s.client.cfg.Scheme + "://" + s.client.cfg.Host + "/interactive/getPartyStatus" + + varHeaderParams := make(map[string]string) + varQueryParams := url.Values{} + varFormParams := url.Values{} + + // to determine the Content-Type header + varHttpContentTypes := []string{"application/x-www-form-urlencoded"} + + // set Content-Type header + varHttpContentType := selectHeaderContentType(varHttpContentTypes) + if varHttpContentType != "" { + varHeaderParams["Content-Type"] = varHttpContentType + } + + // to determine the Accept header + varHttpHeaderAccepts := []string{"application/json"} + + // set Accept header + varHttpHeaderAccept := selectHeaderAccept(varHttpHeaderAccepts) + if varHttpHeaderAccept != "" { + varHeaderParams["Accept"] = varHttpHeaderAccept + } + varFormParams.Add("partyId", parameterToString(varForms.PartyId, "")) + + r, err := s.client.prepareRequest(varPath, varHttpMethod, varHeaderParams, varQueryParams, varFormParams) + if err != nil { + return varReturnValue, nil, err + } + + varHttpResponse, err := s.client.callAPI(r) + if err != nil || varHttpResponse == nil { + return varReturnValue, varHttpResponse, err + } + + defer varHttpResponse.Body.Close() + varBody, err := ioutil.ReadAll(varHttpResponse.Body) + if err != nil { + return varReturnValue, varHttpResponse, err + } + + if varHttpResponse.StatusCode < 300 { + // If we succeed, return the data, otherwise pass on to decode error. + err = s.client.decode(&varReturnValue, varBody, varHttpResponse.Header.Get("Content-Type")) + if err == nil { + return varReturnValue, varHttpResponse, err + } + } + + if varHttpResponse.StatusCode >= 300 { + newErr := GenericError{ + body: varBody, + error: varHttpResponse.Status, + } + return varReturnValue, varHttpResponse, newErr + } + + return varReturnValue, varHttpResponse, nil +} + +// JoinParty +/* + * 加入分配席位 + * @param varForms model.JoinPartyForms + */ +func (s *InteractiveApiService) JoinParty( + varForms *model.JoinPartyForms, +) (model.InteractiveJoinPartyResult, *http.Response, error) { + var ( + varHttpMethod = strings.ToUpper("Post") + varReturnValue model.InteractiveJoinPartyResult + ) + + // create path and map variables + varPath := s.client.cfg.Scheme + "://" + s.client.cfg.Host + "/interactive/joinParty" + + varHeaderParams := make(map[string]string) + varQueryParams := url.Values{} + varFormParams := url.Values{} + + // to determine the Content-Type header + varHttpContentTypes := []string{"application/x-www-form-urlencoded"} + + // set Content-Type header + varHttpContentType := selectHeaderContentType(varHttpContentTypes) + if varHttpContentType != "" { + varHeaderParams["Content-Type"] = varHttpContentType + } + + // to determine the Accept header + varHttpHeaderAccepts := []string{"application/json"} + + // set Accept header + varHttpHeaderAccept := selectHeaderAccept(varHttpHeaderAccepts) + if varHttpHeaderAccept != "" { + varHeaderParams["Accept"] = varHttpHeaderAccept + } + varFormParams.Add("partyId", parameterToString(varForms.PartyId, "")) + varFormParams.Add("userId", parameterToString(varForms.UserId, "")) + varFormParams.Add("seatId", parameterToString(varForms.SeatId, "")) + varFormParams.Add("controlId", parameterToString(varForms.ControlId, "")) + varFormParams.Add("reConnect", parameterToString(varForms.ReConnect, "")) + + r, err := s.client.prepareRequest(varPath, varHttpMethod, varHeaderParams, varQueryParams, varFormParams) + if err != nil { + return varReturnValue, nil, err + } + + varHttpResponse, err := s.client.callAPI(r) + if err != nil || varHttpResponse == nil { + return varReturnValue, varHttpResponse, err + } + + defer varHttpResponse.Body.Close() + varBody, err := ioutil.ReadAll(varHttpResponse.Body) + if err != nil { + return varReturnValue, varHttpResponse, err + } + + if varHttpResponse.StatusCode < 300 { + // If we succeed, return the data, otherwise pass on to decode error. + err = s.client.decode(&varReturnValue, varBody, varHttpResponse.Header.Get("Content-Type")) + if err == nil { + return varReturnValue, varHttpResponse, err + } + } + + if varHttpResponse.StatusCode >= 300 { + newErr := GenericError{ + body: varBody, + error: varHttpResponse.Status, + } + return varReturnValue, varHttpResponse, newErr + } + + return varReturnValue, varHttpResponse, nil +} + +// KickOutUser +/* + * 踢出派对 + * @param varForms model.KickOutUserForms + */ +func (s *InteractiveApiService) KickOutUser( + varForms *model.KickOutUserForms, +) (model.InteractiveKickOutUserResult, *http.Response, error) { + var ( + varHttpMethod = strings.ToUpper("Post") + varReturnValue model.InteractiveKickOutUserResult + ) + + // create path and map variables + varPath := s.client.cfg.Scheme + "://" + s.client.cfg.Host + "/interactive/kickOutUser" + + varHeaderParams := make(map[string]string) + varQueryParams := url.Values{} + varFormParams := url.Values{} + + // to determine the Content-Type header + varHttpContentTypes := []string{"application/x-www-form-urlencoded"} + + // set Content-Type header + varHttpContentType := selectHeaderContentType(varHttpContentTypes) + if varHttpContentType != "" { + varHeaderParams["Content-Type"] = varHttpContentType + } + + // to determine the Accept header + varHttpHeaderAccepts := []string{"application/json"} + + // set Accept header + varHttpHeaderAccept := selectHeaderAccept(varHttpHeaderAccepts) + if varHttpHeaderAccept != "" { + varHeaderParams["Accept"] = varHttpHeaderAccept + } + varFormParams.Add("partyId", parameterToString(varForms.PartyId, "")) + varFormParams.Add("userId", parameterToString(varForms.UserId, "")) + if varForms != nil && varForms.KickOutReason != nil { + varFormParams.Add("kickOutReason", parameterToString(*varForms.KickOutReason, "")) + } + + r, err := s.client.prepareRequest(varPath, varHttpMethod, varHeaderParams, varQueryParams, varFormParams) + if err != nil { + return varReturnValue, nil, err + } + + varHttpResponse, err := s.client.callAPI(r) + if err != nil || varHttpResponse == nil { + return varReturnValue, varHttpResponse, err + } + + defer varHttpResponse.Body.Close() + varBody, err := ioutil.ReadAll(varHttpResponse.Body) + if err != nil { + return varReturnValue, varHttpResponse, err + } + + if varHttpResponse.StatusCode < 300 { + // If we succeed, return the data, otherwise pass on to decode error. + err = s.client.decode(&varReturnValue, varBody, varHttpResponse.Header.Get("Content-Type")) + if err == nil { + return varReturnValue, varHttpResponse, err + } + } + + if varHttpResponse.StatusCode >= 300 { + newErr := GenericError{ + body: varBody, + error: varHttpResponse.Status, + } + return varReturnValue, varHttpResponse, newErr + } + + return varReturnValue, varHttpResponse, nil +} + +// ModifySeats +/* + * 修改席位 + * @param varForms model.ModifySeatsForms + */ +func (s *InteractiveApiService) ModifySeats( + varForms *model.ModifySeatsForms, +) (model.InteractiveModifySeatsResult, *http.Response, error) { + var ( + varHttpMethod = strings.ToUpper("Post") + varReturnValue model.InteractiveModifySeatsResult + ) + + // create path and map variables + varPath := s.client.cfg.Scheme + "://" + s.client.cfg.Host + "/interactive/modifySeats" + + varHeaderParams := make(map[string]string) + varQueryParams := url.Values{} + varFormParams := url.Values{} + + // to determine the Content-Type header + varHttpContentTypes := []string{"application/x-www-form-urlencoded"} + + // set Content-Type header + varHttpContentType := selectHeaderContentType(varHttpContentTypes) + if varHttpContentType != "" { + varHeaderParams["Content-Type"] = varHttpContentType + } + + // to determine the Accept header + varHttpHeaderAccepts := []string{"application/json"} + + // set Accept header + varHttpHeaderAccept := selectHeaderAccept(varHttpHeaderAccepts) + if varHttpHeaderAccept != "" { + varHeaderParams["Accept"] = varHttpHeaderAccept + } + varFormParams.Add("partyId", parameterToString(varForms.PartyId, "")) + varFormParams.Add("operator", parameterToString(varForms.Operator, "")) + varFormParams.Add("modifySeats", parameterToString(varForms.ModifySeats, "multi")) + + r, err := s.client.prepareRequest(varPath, varHttpMethod, varHeaderParams, varQueryParams, varFormParams) + if err != nil { + return varReturnValue, nil, err + } + + varHttpResponse, err := s.client.callAPI(r) + if err != nil || varHttpResponse == nil { + return varReturnValue, varHttpResponse, err + } + + defer varHttpResponse.Body.Close() + varBody, err := ioutil.ReadAll(varHttpResponse.Body) + if err != nil { + return varReturnValue, varHttpResponse, err + } + + if varHttpResponse.StatusCode < 300 { + // If we succeed, return the data, otherwise pass on to decode error. + err = s.client.decode(&varReturnValue, varBody, varHttpResponse.Header.Get("Content-Type")) + if err == nil { + return varReturnValue, varHttpResponse, err + } + } + + if varHttpResponse.StatusCode >= 300 { + newErr := GenericError{ + body: varBody, + error: varHttpResponse.Status, + } + return varReturnValue, varHttpResponse, newErr + } + + return varReturnValue, varHttpResponse, nil +} + +// ShutDownParty +/* + * 关闭派对 + * @param varForms model.ShutDownPartyForms + */ +func (s *InteractiveApiService) ShutDownParty( + varForms *model.ShutDownPartyForms, +) (model.InteractiveShutDownPartyResult, *http.Response, error) { + var ( + varHttpMethod = strings.ToUpper("Post") + varReturnValue model.InteractiveShutDownPartyResult + ) + + // create path and map variables + varPath := s.client.cfg.Scheme + "://" + s.client.cfg.Host + "/interactive/shutDownParty" + + varHeaderParams := make(map[string]string) + varQueryParams := url.Values{} + varFormParams := url.Values{} + + // to determine the Content-Type header + varHttpContentTypes := []string{"application/x-www-form-urlencoded"} + + // set Content-Type header + varHttpContentType := selectHeaderContentType(varHttpContentTypes) + if varHttpContentType != "" { + varHeaderParams["Content-Type"] = varHttpContentType + } + + // to determine the Accept header + varHttpHeaderAccepts := []string{"application/json"} + + // set Accept header + varHttpHeaderAccept := selectHeaderAccept(varHttpHeaderAccepts) + if varHttpHeaderAccept != "" { + varHeaderParams["Accept"] = varHttpHeaderAccept + } + varFormParams.Add("partyId", parameterToString(varForms.PartyId, "")) + if varForms != nil && varForms.ShutDownReason != nil { + varFormParams.Add("shutDownReason", parameterToString(*varForms.ShutDownReason, "")) + } + + r, err := s.client.prepareRequest(varPath, varHttpMethod, varHeaderParams, varQueryParams, varFormParams) + if err != nil { + return varReturnValue, nil, err + } + + varHttpResponse, err := s.client.callAPI(r) + if err != nil || varHttpResponse == nil { + return varReturnValue, varHttpResponse, err + } + + defer varHttpResponse.Body.Close() + varBody, err := ioutil.ReadAll(varHttpResponse.Body) + if err != nil { + return varReturnValue, varHttpResponse, err + } + + if varHttpResponse.StatusCode < 300 { + // If we succeed, return the data, otherwise pass on to decode error. + err = s.client.decode(&varReturnValue, varBody, varHttpResponse.Header.Get("Content-Type")) + if err == nil { + return varReturnValue, varHttpResponse, err + } + } + + if varHttpResponse.StatusCode >= 300 { + newErr := GenericError{ + body: varBody, + error: varHttpResponse.Status, + } + return varReturnValue, varHttpResponse, newErr + } + + return varReturnValue, varHttpResponse, nil +} diff --git a/client/api/token_api.go b/client/api/token_api.go new file mode 100644 index 00000000..a37c8d44 --- /dev/null +++ b/client/api/token_api.go @@ -0,0 +1,90 @@ +// Package client +/* + * YuanJing OpenAPI SDK for Go + * + * + */ +package api + +import ( + "github.com/aliyun/alibabacloud-yjopenapi-go-client/client/model" + "io/ioutil" + "net/http" + "net/url" + "strings" +) + +type TokenApiService service + + +// GetTriple +/* + * 获取临时安全令牌 + */ +func (s *TokenApiService) GetTriple( + +) (model.GetTripleResult, *http.Response, error) { + var ( + varHttpMethod = strings.ToUpper("Post") + varReturnValue model.GetTripleResult + ) + + // create path and map variables + varPath := s.client.cfg.Scheme + "://" + s.client.cfg.Host + "/sts" + + varHeaderParams := make(map[string]string) + varQueryParams := url.Values{} + varFormParams := url.Values{} + + // to determine the Content-Type header + varHttpContentTypes := []string{} + + // set Content-Type header + varHttpContentType := selectHeaderContentType(varHttpContentTypes) + if varHttpContentType != "" { + varHeaderParams["Content-Type"] = varHttpContentType + } + + // to determine the Accept header + varHttpHeaderAccepts := []string{"application/json"} + + // set Accept header + varHttpHeaderAccept := selectHeaderAccept(varHttpHeaderAccepts) + if varHttpHeaderAccept != "" { + varHeaderParams["Accept"] = varHttpHeaderAccept + } + + r, err := s.client.prepareRequest(varPath, varHttpMethod, varHeaderParams, varQueryParams, varFormParams) + if err != nil { + return varReturnValue, nil, err + } + + varHttpResponse, err := s.client.callAPI(r) + if err != nil || varHttpResponse == nil { + return varReturnValue, varHttpResponse, err + } + + defer varHttpResponse.Body.Close() + varBody, err := ioutil.ReadAll(varHttpResponse.Body) + if err != nil { + return varReturnValue, varHttpResponse, err + } + + if varHttpResponse.StatusCode < 300 { + // If we succeed, return the data, otherwise pass on to decode error. + err = s.client.decode(&varReturnValue, varBody, varHttpResponse.Header.Get("Content-Type")) + if err == nil { + return varReturnValue, varHttpResponse, err + } + } + + if varHttpResponse.StatusCode >= 300 { + newErr := GenericError{ + body: varBody, + error: varHttpResponse.Status, + } + return varReturnValue, varHttpResponse, newErr + } + + return varReturnValue, varHttpResponse, nil +} diff --git a/client/model/getpartyforms.go b/client/model/getpartyforms.go new file mode 100644 index 00000000..7bd25196 --- /dev/null +++ b/client/model/getpartyforms.go @@ -0,0 +1,19 @@ +// Package client +/* + * YuanJing OpenAPI SDK for Go + * + * + */ +package model + +type GetPartyForms struct { + // 游戏ID + MixGameId string `json:"mixGameId"` + // 用户ID + UserId string `json:"userId"` + ReConnect int32 `json:"reConnect"` + // 项目 + ProjectId string `json:"projectId"` + // 派对配置 + Config *InteractiveGetPartyFormsConfig `json:"config,omitempty"` +} diff --git a/client/model/getpartystatusforms.go b/client/model/getpartystatusforms.go new file mode 100644 index 00000000..b0289286 --- /dev/null +++ b/client/model/getpartystatusforms.go @@ -0,0 +1,12 @@ +// Package client +/* + * YuanJing OpenAPI SDK for Go + * + * + */ +package model + +type GetPartyStatusForms struct { + // 派对id + PartyId string `json:"partyId"` +} diff --git a/client/model/gettripleresult.go b/client/model/gettripleresult.go new file mode 100644 index 00000000..f306e19f --- /dev/null +++ b/client/model/gettripleresult.go @@ -0,0 +1,22 @@ +// Package client +/* + * YuanJing OpenAPI SDK for Go + * + * + */ +package model + +type GetTripleResult struct { + // 临时token + Token string `json:"token,omitempty"` + // 临时accessKey + AccessKey string `json:"accessKey,omitempty"` + // 临时secretKey + AccessSecret string `json:"accessSecret,omitempty"` + // token失效时间戳,单位:秒 + Expired string `json:"expired,omitempty"` + // 返回码 + Code string `json:"code,omitempty"` + // 返回信息 + Message string `json:"message,omitempty"` +} diff --git a/client/model/interactivegetpartyformsconfig.go b/client/model/interactivegetpartyformsconfig.go new file mode 100644 index 00000000..c17e56f6 --- /dev/null +++ b/client/model/interactivegetpartyformsconfig.go @@ -0,0 +1,16 @@ +// Package client +/* + * YuanJing OpenAPI SDK for Go + * + * + */ +package model + +type InteractiveGetPartyFormsConfig struct { + // 派对创建者断线保活时间 + OwnerDisconnectKeepAliveTime *int32 `json:"ownerDisconnectKeepAliveTime,omitempty"` + // 加入派对玩家断线保活时间 + JoinerDisconnectKeepAliveTime *int32 `json:"joinerDisconnectKeepAliveTime,omitempty"` + // 无操作保活时间 + NoActionKeepAliveTime *int32 `json:"noActionKeepAliveTime,omitempty"` +} diff --git a/client/model/interactivegetpartyresult.go b/client/model/interactivegetpartyresult.go new file mode 100644 index 00000000..f4b45414 --- /dev/null +++ b/client/model/interactivegetpartyresult.go @@ -0,0 +1,15 @@ +// Package client +/* + * YuanJing OpenAPI SDK for Go + * + * + */ +package model + +type InteractiveGetPartyResult struct { + // 服务端状态码 + MsgCode string `json:"msgCode,omitempty"` + // 服务端描述信息 + MsgInfo string `json:"msgInfo,omitempty"` + Model InteractiveGetPartyResultModel `json:"model,omitempty"` +} diff --git a/client/model/interactivegetpartyresultmodel.go b/client/model/interactivegetpartyresultmodel.go new file mode 100644 index 00000000..f9d9e60f --- /dev/null +++ b/client/model/interactivegetpartyresultmodel.go @@ -0,0 +1,15 @@ +// Package client +/* + * YuanJing OpenAPI SDK for Go + * + * + */ +package model + + // 获取结果 +type InteractiveGetPartyResultModel struct { + // 派对Id + PartyId string `json:"partyId,omitempty"` + // 扩展信息 + ExtInfo string `json:"extInfo,omitempty"` +} diff --git a/client/model/interactivegetpartystatusresult.go b/client/model/interactivegetpartystatusresult.go new file mode 100644 index 00000000..8abd7e24 --- /dev/null +++ b/client/model/interactivegetpartystatusresult.go @@ -0,0 +1,15 @@ +// Package client +/* + * YuanJing OpenAPI SDK for Go + * + * + */ +package model + +type InteractiveGetPartyStatusResult struct { + // 服务端状态码 + MsgCode string `json:"msgCode,omitempty"` + // 服务端描述信息 + MsgInfo string `json:"msgInfo,omitempty"` + Model InteractiveGetPartyStatusResultModel `json:"model,omitempty"` +} diff --git a/client/model/interactivegetpartystatusresultmodel.go b/client/model/interactivegetpartystatusresultmodel.go new file mode 100644 index 00000000..d40f1880 --- /dev/null +++ b/client/model/interactivegetpartystatusresultmodel.go @@ -0,0 +1,26 @@ +// Package client +/* + * YuanJing OpenAPI SDK for Go + * + * + */ +package model + + // 获取结果 +type InteractiveGetPartyStatusResultModel struct { + // 派对Id + PartyId string `json:"partyId,omitempty"` + // 游戏Id + MixGameId string `json:"mixGameId,omitempty"` + // 派对创建者 + Creator string `json:"creator,omitempty"` + // 最大游戏人数 + MaxPlayerNum int32 `json:"maxPlayerNum,omitempty"` + // 当前派对人数 + CurrentPlayerNum int32 `json:"currentPlayerNum,omitempty"` + // 派对状态 + Status int32 `json:"status,omitempty"` + // 派对绑定项目ID + ProjectId string `json:"projectId,omitempty"` + PlayerList []InteractiveGetPartyStatusResultModelPlayList `json:"playerList,omitempty"` +} diff --git a/client/model/interactivegetpartystatusresultmodelplaylist.go b/client/model/interactivegetpartystatusresultmodelplaylist.go new file mode 100644 index 00000000..5e40ca17 --- /dev/null +++ b/client/model/interactivegetpartystatusresultmodelplaylist.go @@ -0,0 +1,16 @@ +// Package client +/* + * YuanJing OpenAPI SDK for Go + * + * + */ +package model + +type InteractiveGetPartyStatusResultModelPlayList struct { + // 用户ID + UserId int32 `json:"userId,omitempty"` + // 位次ID + SeatId int32 `json:"seatId,omitempty"` + // 控制位ID + ControlId int32 `json:"controlId,omitempty"` +} diff --git a/client/model/interactivejoinpartyresult.go b/client/model/interactivejoinpartyresult.go new file mode 100644 index 00000000..70c797ca --- /dev/null +++ b/client/model/interactivejoinpartyresult.go @@ -0,0 +1,15 @@ +// Package client +/* + * YuanJing OpenAPI SDK for Go + * + * + */ +package model + +type InteractiveJoinPartyResult struct { + // 服务端状态码 + MsgCode string `json:"msgCode,omitempty"` + // 服务端描述信息 + MsgInfo string `json:"msgInfo,omitempty"` + Model InteractiveJoinPartyResultModel `json:"model,omitempty"` +} diff --git a/client/model/interactivejoinpartyresultextinfo.go b/client/model/interactivejoinpartyresultextinfo.go new file mode 100644 index 00000000..39ead593 --- /dev/null +++ b/client/model/interactivejoinpartyresultextinfo.go @@ -0,0 +1,12 @@ +// Package client +/* + * YuanJing OpenAPI SDK for Go + * + * + */ +package model + + // 扩展信息 +type InteractiveJoinPartyResultExtInfo struct { + ReturnDataType int32 `json:"returnDataType,omitempty"` +} diff --git a/client/model/interactivejoinpartyresultmodel.go b/client/model/interactivejoinpartyresultmodel.go new file mode 100644 index 00000000..70af2892 --- /dev/null +++ b/client/model/interactivejoinpartyresultmodel.go @@ -0,0 +1,13 @@ +// Package client +/* + * YuanJing OpenAPI SDK for Go + * + * + */ +package model + + // 获取结果 +type InteractiveJoinPartyResultModel struct { + PlayerList []InteractiveJoinPartyResultModelPlayerList `json:"playerList,omitempty"` + ExtInfo InteractiveJoinPartyResultExtInfo `json:"extInfo,omitempty"` +} diff --git a/client/model/interactivejoinpartyresultmodelplayerlist.go b/client/model/interactivejoinpartyresultmodelplayerlist.go new file mode 100644 index 00000000..ed671917 --- /dev/null +++ b/client/model/interactivejoinpartyresultmodelplayerlist.go @@ -0,0 +1,17 @@ +// Package client +/* + * YuanJing OpenAPI SDK for Go + * + * + */ +package model + + // 派对Id +type InteractiveJoinPartyResultModelPlayerList struct { + // 用户ID + UserId string `json:"userId,omitempty"` + // 派对坐次 + SeatId int32 `json:"seatId,omitempty"` + // 控制位ID + ControlId int32 `json:"controlId,omitempty"` +} diff --git a/client/model/interactivekickoutuserresult.go b/client/model/interactivekickoutuserresult.go new file mode 100644 index 00000000..676d6c3a --- /dev/null +++ b/client/model/interactivekickoutuserresult.go @@ -0,0 +1,15 @@ +// Package client +/* + * YuanJing OpenAPI SDK for Go + * + * + */ +package model + +type InteractiveKickOutUserResult struct { + // 服务端状态码 + MsgCode string `json:"msgCode,omitempty"` + // 服务端描述信息 + MsgInfo string `json:"msgInfo,omitempty"` + Model InteractiveKickOutUserResultModel `json:"model,omitempty"` +} diff --git a/client/model/interactivekickoutuserresultmodel.go b/client/model/interactivekickoutuserresultmodel.go new file mode 100644 index 00000000..a52732ae --- /dev/null +++ b/client/model/interactivekickoutuserresultmodel.go @@ -0,0 +1,13 @@ +// Package client +/* + * YuanJing OpenAPI SDK for Go + * + * + */ +package model + + // 获取结果 +type InteractiveKickOutUserResultModel struct { + // 派对Id + PlayerList []InteractiveKickOutUserResultModelPlayerList `json:"playerList,omitempty"` +} diff --git a/client/model/interactivekickoutuserresultmodelplayerlist.go b/client/model/interactivekickoutuserresultmodelplayerlist.go new file mode 100644 index 00000000..87483660 --- /dev/null +++ b/client/model/interactivekickoutuserresultmodelplayerlist.go @@ -0,0 +1,16 @@ +// Package client +/* + * YuanJing OpenAPI SDK for Go + * + * + */ +package model + +type InteractiveKickOutUserResultModelPlayerList struct { + // 用户ID + UserId string `json:"userId,omitempty"` + // 派对坐次 + SeatId int32 `json:"seatId,omitempty"` + // 控制位ID + ControlId int32 `json:"controlId,omitempty"` +} diff --git a/client/model/interactivemodifyseatsformsmodifyseats.go b/client/model/interactivemodifyseatsformsmodifyseats.go new file mode 100644 index 00000000..69fdb3bf --- /dev/null +++ b/client/model/interactivemodifyseatsformsmodifyseats.go @@ -0,0 +1,16 @@ +// Package client +/* + * YuanJing OpenAPI SDK for Go + * + * + */ +package model + +type InteractiveModifySeatsFormsModifySeats struct { + // 被操作用户Id + UserId string `json:"userId"` + // 派对坐次 + SeatId int32 `json:"seatId"` + // 控制位 + ControlId int32 `json:"controlId"` +} diff --git a/client/model/interactivemodifyseatsresult.go b/client/model/interactivemodifyseatsresult.go new file mode 100644 index 00000000..d911bf4e --- /dev/null +++ b/client/model/interactivemodifyseatsresult.go @@ -0,0 +1,15 @@ +// Package client +/* + * YuanJing OpenAPI SDK for Go + * + * + */ +package model + +type InteractiveModifySeatsResult struct { + // 服务端状态码 + MsgCode string `json:"msgCode,omitempty"` + // 服务端描述信息 + MsgInfo string `json:"msgInfo,omitempty"` + Model InteractiveModifySeatsResultModel `json:"model,omitempty"` +} diff --git a/client/model/interactivemodifyseatsresultmodel.go b/client/model/interactivemodifyseatsresultmodel.go new file mode 100644 index 00000000..3d1bef94 --- /dev/null +++ b/client/model/interactivemodifyseatsresultmodel.go @@ -0,0 +1,14 @@ +// Package client +/* + * YuanJing OpenAPI SDK for Go + * + * + */ +package model + + // 获取结果 +type InteractiveModifySeatsResultModel struct { + PlayerList []InteractiveModifySeatsResultModelPlayerList `json:"playerList,omitempty"` + // 扩展信息 + ExtInfo string `json:"extInfo,omitempty"` +} diff --git a/client/model/interactivemodifyseatsresultmodelplayerlist.go b/client/model/interactivemodifyseatsresultmodelplayerlist.go new file mode 100644 index 00000000..39a0ee8d --- /dev/null +++ b/client/model/interactivemodifyseatsresultmodelplayerlist.go @@ -0,0 +1,17 @@ +// Package client +/* + * YuanJing OpenAPI SDK for Go + * + * + */ +package model + + // 派对Id +type InteractiveModifySeatsResultModelPlayerList struct { + // 用户ID + UserId string `json:"userId,omitempty"` + // 派对坐次 + SeatId int32 `json:"seatId,omitempty"` + // 控制位ID + ControlId int32 `json:"controlId,omitempty"` +} diff --git a/client/model/interactiveshutdownpartyresult.go b/client/model/interactiveshutdownpartyresult.go new file mode 100644 index 00000000..a0efb1d1 --- /dev/null +++ b/client/model/interactiveshutdownpartyresult.go @@ -0,0 +1,14 @@ +// Package client +/* + * YuanJing OpenAPI SDK for Go + * + * + */ +package model + +type InteractiveShutDownPartyResult struct { + // 服务端状态码 + MsgCode string `json:"msgCode,omitempty"` + // 服务端描述信息 + MsgInfo string `json:"msgInfo,omitempty"` +} diff --git a/client/model/joinpartyforms.go b/client/model/joinpartyforms.go new file mode 100644 index 00000000..2718c146 --- /dev/null +++ b/client/model/joinpartyforms.go @@ -0,0 +1,19 @@ +// Package client +/* + * YuanJing OpenAPI SDK for Go + * + * + */ +package model + +type JoinPartyForms struct { + // 派对id + PartyId string `json:"partyId"` + // 用户ID + UserId string `json:"userId"` + // 派对坐次 + SeatId int32 `json:"seatId"` + // 项目 + ControlId int32 `json:"controlId"` + ReConnect int32 `json:"reConnect"` +} diff --git a/client/model/kickoutuserforms.go b/client/model/kickoutuserforms.go new file mode 100644 index 00000000..5406bcf8 --- /dev/null +++ b/client/model/kickoutuserforms.go @@ -0,0 +1,16 @@ +// Package client +/* + * YuanJing OpenAPI SDK for Go + * + * + */ +package model + +type KickOutUserForms struct { + // 派对id + PartyId string `json:"partyId"` + // 用户Id + UserId string `json:"userId"` + // 踢出原因 + KickOutReason *string `json:"kickOutReason,omitempty"` +} diff --git a/client/model/modifyseatsforms.go b/client/model/modifyseatsforms.go new file mode 100644 index 00000000..4c887488 --- /dev/null +++ b/client/model/modifyseatsforms.go @@ -0,0 +1,15 @@ +// Package client +/* + * YuanJing OpenAPI SDK for Go + * + * + */ +package model + +type ModifySeatsForms struct { + // 派对id + PartyId string `json:"partyId"` + // 操作者 + Operator string `json:"operator"` + ModifySeats []InteractiveModifySeatsFormsModifySeats `json:"modifySeats"` +} diff --git a/client/model/shutdownpartyforms.go b/client/model/shutdownpartyforms.go new file mode 100644 index 00000000..7a6bc6a5 --- /dev/null +++ b/client/model/shutdownpartyforms.go @@ -0,0 +1,14 @@ +// Package client +/* + * YuanJing OpenAPI SDK for Go + * + * + */ +package model + +type ShutDownPartyForms struct { + // 派对id + PartyId string `json:"partyId"` + // 关闭原因 + ShutDownReason *string `json:"shutDownReason,omitempty"` +} diff --git a/go.mod b/go.mod new file mode 100644 index 00000000..7f281e33 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/aliyun/alibabacloud-yjopenapi-go-client + +go 1.15