Esempio n. 1
0
        public void TestMerge()
        {
            Assert.Empty(TeaConverter.merge <object>(null));

            Dictionary <string, string> dic      = new Dictionary <string, string>();
            Dictionary <string, object> dicNull  = null;
            Dictionary <string, object> dicMerge = new Dictionary <string, object>();
            TestRegModel model = new TestRegModel();

            dic.Add("testNull", null);
            dic.Add("testExist", "testExist");
            dic.Add("test", "test");
            dicMerge.Add("testMerge", "testMerge");
            dicMerge.Add("testExist", "IsExist");
            Dictionary <string, string> dicResult = TeaConverter.merge <string>(dic, dicNull, dicMerge, null);

            Assert.NotNull(dicResult);
            Assert.Equal(4, dicResult.Count);

            Dictionary <string, object> dicModelMerge = TeaConverter.merge <object>(dic, dicNull, dicMerge, model);

            Assert.NotNull(dicResult);

            Assert.Throws <ArgumentException>(() => { TeaConverter.merge <object>(dic, 1); });
        }
Esempio n. 2
0
        public ComplexRequest Complex3(ComplexRequest request)
        {
            request.Validate();
            TeaRequest request_ = new TeaRequest();
            string     name     = "complex";

            request_.Protocol = TemplateString();
            request_.Port     = 80;
            request_.Method   = "GET";
            request_.Pathname = "/";
            request_.Body     = TeaCore.BytesReadable("body");
            request_.Query    = new Dictionary <string, string>
            {
                { "date", "2019" },
            };
            TeaResponse response_ = TeaCore.DoAction(request_);

            TeaResponse resp = response_;

            Darabonba.import.Models.Request req = new Darabonba.import.Models.Request
            {
                Accesskey = request.AccessKey,
                Region    = resp.StatusMessage,
            };
            Client.Array0(request.ToMap());
            req.Accesskey = "accesskey";
            req.Accesskey = request.AccessKey;
            Client.PrintNull();
            Darabonba.import.Common.Array(request.ToMap(), "1");
            return(TeaModel.ToObject <ComplexRequest>(TeaConverter.merge <string>
                                                      (
                                                          request_.Query
                                                      )));
        }
        public static Dictionary <string, string> HelloMap()
        {
            Dictionary <string, string> m = new Dictionary <string, string>()
            {
            };

            return(TeaConverter.merge <string>
                   (
                       new Dictionary <string, string>()
            {
                { "key", "value" },
                { "key-1", "value-1" },
            },
                       m
                   ));
        }
Esempio n. 4
0
        public async Task <ComplexRequest> Complex3Async(ComplexRequest request)
        {
            request.Validate();
            TeaRequest request_ = new TeaRequest();
            string     name     = "complex";

            request_.Protocol = await TemplateStringAsync();

            request_.Port     = 80;
            request_.Method   = "GET";
            request_.Pathname = "/";
            request_.Body     = TeaCore.BytesReadable("body");
            request_.Query    = new Dictionary <string, string>
            {
                { "date", "2019" },
            };
            TeaResponse response_ = await TeaCore.DoActionAsync(request_);

            if (true)
            {
                throw new TeaRetryableException(request_, response_);
            }
            TeaResponse resp = response_;

            Darabonba.import.Models.Request req = new Darabonba.import.Models.Request
            {
                Accesskey = request.AccessKey,
                Region    = resp.StatusMessage,
            };
            Array0(request.ToMap());
            req.Accesskey = "accesskey";
            req.Accesskey = request.AccessKey;
            await PrintNullAsync(typeof(Config));

            Darabonba.import.Common.Array(request.ToMap(), "1");
            return(TeaModel.ToObject <ComplexRequest>(TeaConverter.merge <string>
                                                      (
                                                          request_.Query
                                                      )));
        }
Esempio n. 5
0
        public async Task <AlipayPassInstanceUpdateResponse> UpdateInstanceAsync(string serialNumber, string channelId, string tplParams, string status, string verifyCode, string verifyType)
        {
            Dictionary <string, object> runtime_ = new Dictionary <string, object>
            {
                { "connectTimeout", 15000 },
                { "readTimeout", 15000 },
                { "retry", new Dictionary <string, int?>
                  {
                      { "maxAttempts", 0 },
                  } },
            };

            TeaRequest _lastRequest   = null;
            Exception  _lastException = null;
            long       _now           = System.DateTime.Now.Millisecond;
            int        _retryTimes    = 0;

            while (TeaCore.AllowRetry((IDictionary)runtime_["retry"], _retryTimes, _now))
            {
                if (_retryTimes > 0)
                {
                    int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes);
                    if (backoffTime > 0)
                    {
                        TeaCore.Sleep(backoffTime);
                    }
                }
                _retryTimes = _retryTimes + 1;
                try
                {
                    TeaRequest request_ = new TeaRequest();
                    Dictionary <string, string> systemParams = new Dictionary <string, string>
                    {
                        { "method", "alipay.pass.instance.update" },
                        { "app_id", this._kernel.GetConfig("appId") },
                        { "timestamp", this._kernel.GetTimestamp() },
                        { "format", "json" },
                        { "version", "1.0" },
                        { "alipay_sdk", this._kernel.GetSdkVersion() },
                        { "charset", "UTF-8" },
                        { "sign_type", this._kernel.GetConfig("signType") },
                        { "app_cert_sn", this._kernel.GetMerchantCertSN() },
                        { "alipay_root_cert_sn", this._kernel.GetAlipayRootCertSN() },
                    };
                    Dictionary <string, object> bizParams = new Dictionary <string, object>
                    {
                        { "serial_number", serialNumber },
                        { "channel_id", channelId },
                        { "tpl_params", tplParams },
                        { "status", status },
                        { "verify_code", verifyCode },
                        { "verify_type", verifyType },
                    };
                    Dictionary <string, string> textParams = new Dictionary <string, string>()
                    {
                    };
                    request_.Protocol = this._kernel.GetConfig("protocol");
                    request_.Method   = "POST";
                    request_.Pathname = "/gateway.do";
                    request_.Headers  = new Dictionary <string, string>
                    {
                        { "host", this._kernel.GetConfig("gatewayHost") },
                        { "content-type", "application/x-www-form-urlencoded;charset=utf-8" },
                    };
                    request_.Query = this._kernel.SortMap(TeaConverter.merge <string>
                                                          (
                                                              new Dictionary <string, string>()
                    {
                        { "sign", this._kernel.Sign(systemParams, bizParams, textParams, this._kernel.GetConfig("merchantPrivateKey")) },
                    },
                                                              systemParams,
                                                              textParams
                                                          ));
                    request_.Body = TeaCore.BytesReadable(this._kernel.ToUrlEncodedRequestBody(bizParams));
                    _lastRequest  = request_;
                    TeaResponse response_ = await TeaCore.DoActionAsync(request_, runtime_);

                    Dictionary <string, object> respMap = await this._kernel.ReadAsJsonAsync(response_, "alipay.pass.instance.update");

                    if (this._kernel.IsCertMode())
                    {
                        if (this._kernel.Verify(respMap, this._kernel.ExtractAlipayPublicKey(this._kernel.GetAlipayCertSN(respMap))))
                        {
                            return(TeaModel.ToObject <AlipayPassInstanceUpdateResponse>(this._kernel.ToRespModel(respMap)));
                        }
                    }
                    else
                    {
                        if (this._kernel.Verify(respMap, this._kernel.GetConfig("alipayPublicKey")))
                        {
                            return(TeaModel.ToObject <AlipayPassInstanceUpdateResponse>(this._kernel.ToRespModel(respMap)));
                        }
                    }
                    throw new TeaException(new Dictionary <string, string>
                    {
                        { "message", "验签失败,请检查支付宝公钥设置是否正确。" },
                    });
                }
                catch (Exception e)
                {
                    if (TeaCore.IsRetryable(e))
                    {
                        _lastException = e;
                        continue;
                    }
                    throw e;
                }
            }

            throw new TeaUnretryableException(_lastRequest, _lastException);
        }
        /**
         * Encapsulate the request and invoke the network
         * @param action api name
         * @param protocol http or https
         * @param method e.g. GET
         * @param pathname pathname of every api
         * @param request which contains request params
         * @param runtime which controls some details of call api, such as retry times
         * @return the response
         */
        public Dictionary <string, object> DoRequest(string action, string protocol, string method, string pathname, Dictionary <string, object> request, AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime)
        {
            Dictionary <string, object> runtime_ = new Dictionary <string, object>
            {
                { "timeouted", "retry" },
                { "readTimeout", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.ReadTimeout, _readTimeout) },
                { "connectTimeout", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.ConnectTimeout, _connectTimeout) },
                { "httpProxy", AlibabaCloud.TeaUtil.Common.DefaultString(runtime.HttpProxy, _httpProxy) },
                { "httpsProxy", AlibabaCloud.TeaUtil.Common.DefaultString(runtime.HttpsProxy, _httpsProxy) },
                { "noProxy", AlibabaCloud.TeaUtil.Common.DefaultString(runtime.NoProxy, _noProxy) },
                { "maxIdleConns", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.MaxIdleConns, _maxIdleConns) },
                { "retry", new Dictionary <string, object>
                  {
                      { "retryable", runtime.Autoretry },
                      { "maxAttempts", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.MaxAttempts, 3) },
                  } },
                { "backoff", new Dictionary <string, object>
                  {
                      { "policy", AlibabaCloud.TeaUtil.Common.DefaultString(runtime.BackoffPolicy, "no") },
                      { "period", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.BackoffPeriod, 1) },
                  } },
                { "ignoreSSL", runtime.IgnoreSSL },
            };

            TeaRequest _lastRequest   = null;
            Exception  _lastException = null;
            long       _now           = System.DateTime.Now.Millisecond;
            int        _retryTimes    = 0;

            while (TeaCore.AllowRetry((IDictionary)runtime_["retry"], _retryTimes, _now))
            {
                if (_retryTimes > 0)
                {
                    int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes);
                    if (backoffTime > 0)
                    {
                        TeaCore.Sleep(backoffTime);
                    }
                }
                _retryTimes = _retryTimes + 1;
                try
                {
                    TeaRequest request_ = new TeaRequest();
                    request_.Protocol = AlibabaCloud.TeaUtil.Common.DefaultString(_protocol, protocol);
                    request_.Method   = method;
                    request_.Pathname = pathname;
                    request_.Query    = new Dictionary <string, string>
                    {
                        { "method", action },
                        { "version", "1.0" },
                        { "sign_type", "HmacSHA1" },
                        { "req_time", AntChain.AlipayUtil.Client.GetTimestamp() },
                        { "req_msg_id", AlibabaCloud.TeaUtil.Common.GetNonce() },
                    };
                    if (!AlibabaCloud.TeaUtil.Common.Empty(_tenant))
                    {
                        request_.Query["tenant"] = _tenant;
                    }
                    if (!AlibabaCloud.TeaUtil.Common.Empty(_workspace))
                    {
                        request_.Query["workspace"] = _workspace;
                    }
                    if (!AlibabaCloud.TeaUtil.Common.Empty(_authToken))
                    {
                        request_.Query["auth_token"] = _authToken;
                    }
                    else
                    {
                        request_.Query["access_key"] = _accessKeyId;
                    }
                    request_.Headers = new Dictionary <string, string>
                    {
                        { "host", _endpoint },
                        { "user-agent", GetUserAgent() },
                    };
                    Dictionary <string, object> tmp = AlibabaCloud.TeaUtil.Common.AnyifyMapValue(AlibabaCloud.Commons.Common.Query(request));
                    request_.Body = TeaCore.BytesReadable(AlibabaCloud.TeaUtil.Common.ToFormString(tmp));
                    request_.Headers["content-type"] = "application/x-www-form-urlencoded";
                    Dictionary <string, string> signedParam = TeaConverter.merge <string>
                                                              (
                        request_.Query,
                        AlibabaCloud.Commons.Common.Query(request)
                                                              );
                    request_.Query["sign"] = AntChain.AlipayUtil.Client.GetSignature(signedParam, _accessKeySecret);
                    _lastRequest           = request_;
                    TeaResponse response_ = TeaCore.DoAction(request_, runtime_);

                    object obj = AlibabaCloud.TeaUtil.Common.ReadAsJSON(response_.Body);
                    Dictionary <string, object> res  = AlibabaCloud.TeaUtil.Common.AssertAsMap(obj);
                    Dictionary <string, object> resp = AlibabaCloud.TeaUtil.Common.AssertAsMap(res.Get("response"));
                    if (AntChain.AlipayUtil.Client.HasError(res))
                    {
                        throw new TeaException(new Dictionary <string, object>
                        {
                            { "message", resp.Get("result_msg") },
                            { "data", resp },
                            { "code", resp.Get("result_code") },
                        });
                    }
                    return(resp);
                }
                catch (Exception e)
                {
                    if (TeaCore.IsRetryable(e))
                    {
                        _lastException = e;
                        continue;
                    }
                    throw e;
                }
            }

            throw new TeaUnretryableException(_lastRequest, _lastException);
        }
        /**
         * Send request
         * @param pathname the url path
         * @param protocol http or https
         * @param method example GET
         * @param header request header
         * @param body the object of IoTApiRequest
         * @param runtime which controls some details of call api, such as retry times
         * @return the response
         */
        public TeaResponse DoRequest(string pathname, string protocol, string method, Dictionary <string, string> header, IoTApiRequest body, AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime)
        {
            body.Validate();
            Dictionary <string, object> runtime_ = new Dictionary <string, object>
            {
                { "timeouted", "retry" },
                { "readTimeout", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.ReadTimeout, _readTimeout) },
                { "connectTimeout", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.ConnectTimeout, _connectTimeout) },
                { "httpProxy", AlibabaCloud.TeaUtil.Common.DefaultString(runtime.HttpProxy, _httpProxy) },
                { "httpsProxy", AlibabaCloud.TeaUtil.Common.DefaultString(runtime.HttpsProxy, _httpsProxy) },
                { "noProxy", AlibabaCloud.TeaUtil.Common.DefaultString(runtime.NoProxy, _noProxy) },
                { "maxIdleConns", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.MaxIdleConns, _maxIdleConns) },
                { "retry", new Dictionary <string, object>
                  {
                      { "retryable", runtime.Autoretry },
                      { "maxAttempts", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.MaxAttempts, 3) },
                  } },
                { "backoff", new Dictionary <string, object>
                  {
                      { "policy", AlibabaCloud.TeaUtil.Common.DefaultString(runtime.BackoffPolicy, "no") },
                      { "period", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.BackoffPeriod, 1) },
                  } },
                { "ignoreSSL", runtime.IgnoreSSL },
            };

            TeaRequest _lastRequest   = null;
            Exception  _lastException = null;
            long       _now           = System.DateTime.Now.Millisecond;
            int        _retryTimes    = 0;

            while (TeaCore.AllowRetry((IDictionary)runtime_["retry"], _retryTimes, _now))
            {
                if (_retryTimes > 0)
                {
                    int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes);
                    if (backoffTime > 0)
                    {
                        TeaCore.Sleep(backoffTime);
                    }
                }
                _retryTimes = _retryTimes + 1;
                try
                {
                    TeaRequest request_ = new TeaRequest();
                    request_.Protocol = AlibabaCloud.TeaUtil.Common.DefaultString(_protocol, protocol);
                    request_.Method   = AlibabaCloud.TeaUtil.Common.DefaultString(method, "POST");
                    request_.Pathname = pathname;
                    request_.Headers  = TeaConverter.merge <string>
                                        (
                        new Dictionary <string, string>()
                    {
                        { "host", _domain },
                        { "date", AlibabaCloud.TeaUtil.Common.GetDateUTCString() },
                        { "x-ca-nonce", AlibabaCloud.TeaUtil.Common.GetNonce() },
                        { "x-ca-key", _appKey },
                        { "x-ca-signaturemethod", "HmacSHA256" },
                        { "accept", "application/json" },
                        { "user-agent", GetUserAgent() },
                    },
                        header
                                        );
                    if (AlibabaCloud.TeaUtil.Common.Empty(body.Id))
                    {
                        body.Id = AlibabaCloud.TeaUtil.Common.GetNonce();
                    }
                    if (!AlibabaCloud.TeaUtil.Common.IsUnset(body.ToMap()))
                    {
                        request_.Headers["content-type"] = "application/octet-stream";
                        request_.Headers["content-md5"]  = AlibabaCloud.APIGatewayUtil.Common.GetContentMD5(AlibabaCloud.TeaUtil.Common.ToJSONString(body.ToMap()));
                        request_.Body = TeaCore.BytesReadable(AlibabaCloud.TeaUtil.Common.ToJSONString(body.ToMap()));
                    }
                    request_.Headers["x-ca-signature"] = AlibabaCloud.APIGatewayUtil.Common.GetSignature(request_, _appSecret);
                    _lastRequest = request_;
                    TeaResponse response_ = TeaCore.DoAction(request_, runtime_);

                    return(response_);
                }
                catch (Exception e)
                {
                    if (TeaCore.IsRetryable(e))
                    {
                        _lastException = e;
                        continue;
                    }
                    throw e;
                }
            }

            throw new TeaUnretryableException(_lastRequest, _lastException);
        }
Esempio n. 8
0
        public AlipayOpenApiGenericResponse Execute(string method, Dictionary <string, string> textParams, Dictionary <string, object> bizParams)
        {
            Dictionary <string, object> runtime_ = new Dictionary <string, object>()
            {
                { "connectTimeout", 15000 },
                { "readTimeout", 15000 },
                { "retry", new Dictionary <string, int?>()
                  {
                      { "maxAttempts", 0 },
                  } },
            };

            TeaRequest _lastRequest   = null;
            Exception  _lastException = null;
            long       _now           = System.DateTime.Now.Millisecond;
            int        _retryTimes    = 0;

            while (TeaCore.AllowRetry((IDictionary)runtime_["retry"], _retryTimes, _now))
            {
                if (_retryTimes > 0)
                {
                    int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes);
                    if (backoffTime > 0)
                    {
                        TeaCore.Sleep(backoffTime);
                    }
                }
                _retryTimes = _retryTimes + 1;
                try
                {
                    TeaRequest request_ = new TeaRequest();
                    Dictionary <string, string> systemParams = new Dictionary <string, string>()
                    {
                        { "method", method },
                        { "app_id", _getConfig("appId") },
                        { "timestamp", _getTimestamp() },
                        { "format", "json" },
                        { "version", "1.0" },
                        { "alipay_sdk", _getSdkVersion() },
                        { "charset", "UTF-8" },
                        { "sign_type", _getConfig("signType") },
                        { "app_cert_sn", _getMerchantCertSN() },
                        { "alipay_root_cert_sn", _getAlipayRootCertSN() },
                    };
                    request_.Protocol = _getConfig("protocol");
                    request_.Method   = "POST";
                    request_.Pathname = "/gateway.do";
                    request_.Headers  = new Dictionary <string, string>()
                    {
                        { "host", _getConfig("gatewayHost") },
                        { "content-type", "application/x-www-form-urlencoded;charset=utf-8" },
                    };
                    request_.Query = TeaConverter.merge <string>(
                        new Dictionary <string, string>()
                    {
                        { "sign", _sign(systemParams, bizParams, textParams, _getConfig("merchantPrivateKey")) },
                    },
                        systemParams
                        );
                    request_.Body = TeaCore.BytesReadable(_toUrlEncodedRequestBody(bizParams, textParams));
                    _lastRequest  = request_;
                    TeaResponse response_ = TeaCore.DoAction(request_, runtime_);

                    Dictionary <string, object> respMap = _readAsJson(response_, method);
                    if (_isCertMode())
                    {
                        if (_verify(respMap, _extractAlipayPublicKey(_getAlipayCertSN(respMap))))
                        {
                            return(TeaModel.ToObject <AlipayOpenApiGenericResponse>(_toRespModel(respMap)));
                        }
                    }
                    else
                    {
                        if (_verify(respMap, _getConfig("alipayPublicKey")))
                        {
                            return(TeaModel.ToObject <AlipayOpenApiGenericResponse>(_toRespModel(respMap)));
                        }
                    }
                    throw new TeaException(new Dictionary <string, string>()
                    {
                        { "message", "验签失败,请检查支付宝公钥设置是否正确。" },
                    });
                }
                catch (Exception e)
                {
                    if (TeaCore.IsRetryable(e))
                    {
                        _lastException = e;
                        continue;
                    }
                    throw e;
                }
            }

            throw new TeaUnretryableException(_lastRequest, _lastException);
        }
Esempio n. 9
0
        /**
         * Encapsulate the request and invoke the network
         * @param action api name
         * @param protocol http or https
         * @param method e.g. GET
         * @param version product version
         * @param authType when authType is Anonymous, the signature will not be calculate
         * @param pathname pathname of every api
         * @param query which contains request params
         * @param body content of request
         * @param runtime which controls some details of call api, such as retry times
         * @return the response
         */
        public async Task <Dictionary <string, object> > DoRequestAsync(string action, string protocol, string method, string version, string authType, Dictionary <string, object> query, Dictionary <string, object> body, AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime)
        {
            Dictionary <string, object> runtime_ = new Dictionary <string, object>
            {
                { "timeouted", "retry" },
                { "readTimeout", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.ReadTimeout, _readTimeout) },
                { "connectTimeout", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.ConnectTimeout, _connectTimeout) },
                { "httpProxy", AlibabaCloud.TeaUtil.Common.DefaultString(runtime.HttpProxy, _httpProxy) },
                { "httpsProxy", AlibabaCloud.TeaUtil.Common.DefaultString(runtime.HttpsProxy, _httpsProxy) },
                { "noProxy", AlibabaCloud.TeaUtil.Common.DefaultString(runtime.NoProxy, _noProxy) },
                { "maxIdleConns", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.MaxIdleConns, _maxIdleConns) },
                { "retry", new Dictionary <string, object>
                  {
                      { "retryable", runtime.Autoretry },
                      { "maxAttempts", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.MaxAttempts, 3) },
                  } },
                { "backoff", new Dictionary <string, object>
                  {
                      { "policy", AlibabaCloud.TeaUtil.Common.DefaultString(runtime.BackoffPolicy, "no") },
                      { "period", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.BackoffPeriod, 1) },
                  } },
                { "ignoreSSL", runtime.IgnoreSSL },
            };

            TeaRequest _lastRequest   = null;
            Exception  _lastException = null;
            long       _now           = System.DateTime.Now.Millisecond;
            int        _retryTimes    = 0;

            while (TeaCore.AllowRetry((IDictionary)runtime_["retry"], _retryTimes, _now))
            {
                if (_retryTimes > 0)
                {
                    int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes);
                    if (backoffTime > 0)
                    {
                        TeaCore.Sleep(backoffTime);
                    }
                }
                _retryTimes = _retryTimes + 1;
                try
                {
                    TeaRequest request_ = new TeaRequest();
                    request_.Protocol = AlibabaCloud.TeaUtil.Common.DefaultString(_protocol, protocol);
                    request_.Method   = method;
                    request_.Pathname = "/";
                    request_.Query    = AlibabaCloud.Commons.Common.Query(TeaConverter.merge <object>
                                                                          (
                                                                              new Dictionary <string, object>()
                    {
                        { "Action", action },
                        { "Format", "json" },
                        { "Timestamp", AlibabaCloud.Commons.Common.GetTimestamp() },
                        { "Version", version },
                        { "SignatureNonce", AlibabaCloud.TeaUtil.Common.GetNonce() },
                    },
                                                                              query
                                                                          ));
                    // endpoint is setted in product client
                    request_.Headers = new Dictionary <string, string>
                    {
                        { "x-acs-version", version },
                        { "x-acs-action", action },
                        { "host", _endpoint },
                        { "user-agent", GetUserAgent() },
                    };
                    if (!AlibabaCloud.TeaUtil.Common.IsUnset(body))
                    {
                        Dictionary <string, object> tmp = AlibabaCloud.TeaUtil.Common.AnyifyMapValue(AlibabaCloud.Commons.Common.Query(body));
                        request_.Body = TeaCore.BytesReadable(AlibabaCloud.TeaUtil.Common.ToFormString(tmp));
                        request_.Headers["content-type"] = "application/x-www-form-urlencoded";
                    }
                    if (!AlibabaCloud.TeaUtil.Common.EqualString(authType, "Anonymous"))
                    {
                        string accessKeyId = await GetAccessKeyIdAsync();

                        string accessKeySecret = await GetAccessKeySecretAsync();

                        string securityToken = await GetSecurityTokenAsync();

                        if (!AlibabaCloud.TeaUtil.Common.Empty(securityToken))
                        {
                            request_.Query["SecurityToken"] = securityToken;
                        }
                        request_.Query["SignatureMethod"]  = "HMAC-SHA1";
                        request_.Query["SignatureVersion"] = "1.0";
                        request_.Query["AccessKeyId"]      = accessKeyId;
                        Dictionary <string, string> signedParam = TeaConverter.merge <string>
                                                                  (
                            request_.Query,
                            AlibabaCloud.Commons.Common.Query(body)
                                                                  );
                        request_.Query["Signature"] = AlibabaCloud.Commons.Common.GetSignatureV1(signedParam, request_.Method, accessKeySecret);
                    }
                    _lastRequest = request_;
                    TeaResponse response_ = await TeaCore.DoActionAsync(request_, runtime_);

                    object obj = AlibabaCloud.TeaUtil.Common.ReadAsJSON(response_.Body);
                    Dictionary <string, object> res = AlibabaCloud.TeaUtil.Common.AssertAsMap(obj);
                    if (AlibabaCloud.TeaUtil.Common.Is4xx(response_.StatusCode) || AlibabaCloud.TeaUtil.Common.Is5xx(response_.StatusCode))
                    {
                        throw new TeaException(new Dictionary <string, object>
                        {
                            { "code", Client.DefaultAny(res.Get("Code"), res.Get("code")) + "Error" },
                            { "message", "code: " + response_.StatusCode + ", " + Client.DefaultAny(res.Get("Message"), res.Get("message")) + " requestid: " + Client.DefaultAny(res.Get("RequestId"), res.Get("requestId")) },
                            { "data", res },
                        });
                    }
                    return(res);
                }
                catch (Exception e)
                {
                    if (TeaCore.IsRetryable(e))
                    {
                        _lastException = e;
                        continue;
                    }
                    throw e;
                }
            }

            throw new TeaUnretryableException(_lastRequest, _lastException);
        }
Esempio n. 10
0
        public AlipayUserCertifyOpenInitializeResponse Init(string outerOrderNo, string bizCode, IdentityParam identityParam, MerchantConfig merchantConfig)
        {
            identityParam.Validate();
            merchantConfig.Validate();
            Dictionary <string, object> runtime_ = new Dictionary <string, object>
            {
                { "ignoreSSL", this._kernel.GetConfig("ignoreSSL") },
                { "httpProxy", this._kernel.GetConfig("httpProxy") },
                { "connectTimeout", 15000 },
                { "readTimeout", 15000 },
                { "retry", new Dictionary <string, int?>
                  {
                      { "maxAttempts", 0 },
                  } },
            };

            TeaRequest _lastRequest   = null;
            Exception  _lastException = null;
            long       _now           = System.DateTime.Now.Millisecond;
            int        _retryTimes    = 0;

            while (TeaCore.AllowRetry((IDictionary)runtime_["retry"], _retryTimes, _now))
            {
                if (_retryTimes > 0)
                {
                    int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes);
                    if (backoffTime > 0)
                    {
                        TeaCore.Sleep(backoffTime);
                    }
                }
                _retryTimes = _retryTimes + 1;
                try
                {
                    TeaRequest request_ = new TeaRequest();
                    Dictionary <string, string> systemParams = new Dictionary <string, string>
                    {
                        { "method", "alipay.user.certify.open.initialize" },
                        { "app_id", this._kernel.GetConfig("appId") },
                        { "timestamp", this._kernel.GetTimestamp() },
                        { "format", "json" },
                        { "version", "1.0" },
                        { "alipay_sdk", this._kernel.GetSdkVersion() },
                        { "charset", "UTF-8" },
                        { "sign_type", this._kernel.GetConfig("signType") },
                        { "app_cert_sn", this._kernel.GetMerchantCertSN() },
                        { "alipay_root_cert_sn", this._kernel.GetAlipayRootCertSN() },
                    };
                    Dictionary <string, object> bizParams = new Dictionary <string, object>
                    {
                        { "outer_order_no", outerOrderNo },
                        { "biz_code", bizCode },
                        { "identity_param", identityParam },
                        { "merchant_config", merchantConfig },
                    };
                    Dictionary <string, string> textParams = new Dictionary <string, string>()
                    {
                    };
                    request_.Protocol = this._kernel.GetConfig("protocol");
                    request_.Method   = "POST";
                    request_.Pathname = "/gateway.do";
                    request_.Headers  = new Dictionary <string, string>
                    {
                        { "host", this._kernel.GetConfig("gatewayHost") },
                        { "content-type", "application/x-www-form-urlencoded;charset=utf-8" },
                    };
                    request_.Query = this._kernel.SortMap(TeaConverter.merge <string>
                                                          (
                                                              new Dictionary <string, string>()
                    {
                        { "sign", this._kernel.Sign(systemParams, bizParams, textParams, this._kernel.GetConfig("merchantPrivateKey")) },
                    },
                                                              systemParams,
                                                              textParams
                                                          ));
                    request_.Body = TeaCore.BytesReadable(this._kernel.ToUrlEncodedRequestBody(bizParams));
                    _lastRequest  = request_;
                    TeaResponse response_ = TeaCore.DoAction(request_, runtime_);

                    Dictionary <string, object> respMap = this._kernel.ReadAsJson(response_, "alipay.user.certify.open.initialize");
                    if (this._kernel.IsCertMode())
                    {
                        if (this._kernel.Verify(respMap, this._kernel.ExtractAlipayPublicKey(this._kernel.GetAlipayCertSN(respMap))))
                        {
                            return(TeaModel.ToObject <AlipayUserCertifyOpenInitializeResponse>(this._kernel.ToRespModel(respMap)));
                        }
                    }
                    else
                    {
                        if (this._kernel.Verify(respMap, this._kernel.GetConfig("alipayPublicKey")))
                        {
                            return(TeaModel.ToObject <AlipayUserCertifyOpenInitializeResponse>(this._kernel.ToRespModel(respMap)));
                        }
                    }
                    throw new TeaException(new Dictionary <string, string>
                    {
                        { "message", "验签失败,请检查支付宝公钥设置是否正确。" },
                    });
                }
                catch (Exception e)
                {
                    if (TeaCore.IsRetryable(e))
                    {
                        _lastException = e;
                        continue;
                    }
                    throw e;
                }
            }

            throw new TeaUnretryableException(_lastRequest, _lastException);
        }
Esempio n. 11
0
        public AlipayOfflineMaterialImageUploadResponse Upload(string imageName, string imageFilePath)
        {
            Dictionary <string, object> runtime_ = new Dictionary <string, object>()
            {
                { "connectTimeout", 100000 },
                { "readTimeout", 100000 },
                { "retry", new Dictionary <string, int?>()
                  {
                      { "maxAttempts", 0 },
                  } },
            };

            TeaRequest _lastRequest   = null;
            Exception  _lastException = null;
            long       _now           = System.DateTime.Now.Millisecond;
            int        _retryTimes    = 0;

            while (TeaCore.AllowRetry((IDictionary)runtime_["retry"], _retryTimes, _now))
            {
                if (_retryTimes > 0)
                {
                    int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes);
                    if (backoffTime > 0)
                    {
                        TeaCore.Sleep(backoffTime);
                    }
                }
                _retryTimes = _retryTimes + 1;
                try
                {
                    TeaRequest request_ = new TeaRequest();
                    Dictionary <string, string> systemParams = new Dictionary <string, string>()
                    {
                        { "method", "alipay.offline.material.image.upload" },
                        { "app_id", _getConfig("appId") },
                        { "timestamp", _getTimestamp() },
                        { "format", "json" },
                        { "version", "1.0" },
                        { "alipay_sdk", _getSdkVersion() },
                        { "charset", "UTF-8" },
                        { "sign_type", _getConfig("signType") },
                        { "app_cert_sn", _getMerchantCertSN() },
                        { "alipay_root_cert_sn", _getAlipayRootCertSN() },
                    };
                    Dictionary <string, object> bizParams = new Dictionary <string, object>()
                    {
                    };
                    Dictionary <string, string> textParams = new Dictionary <string, string>()
                    {
                        { "image_type", "jpg" },
                        { "image_name", imageName },
                    };
                    Dictionary <string, string> fileParams = new Dictionary <string, string>()
                    {
                        { "image_content", imageFilePath },
                    };
                    string boundary = _getRandomBoundary();
                    request_.Protocol = _getConfig("protocol");
                    request_.Method   = "POST";
                    request_.Pathname = "/gateway.do";
                    request_.Headers  = new Dictionary <string, string>()
                    {
                        { "host", _getConfig("gatewayHost") },
                        { "content-type", _concatStr("multipart/form-data;charset=utf-8;boundary=", boundary) },
                    };
                    request_.Query = TeaConverter.merge <string>(
                        new Dictionary <string, string>()
                    {
                        { "sign", _sign(systemParams, bizParams, textParams, _getConfig("merchantPrivateKey")) },
                    },
                        systemParams
                        );
                    request_.Body = _toMultipartRequestBody(textParams, fileParams, boundary);
                    _lastRequest  = request_;
                    TeaResponse response_ = TeaCore.DoAction(request_, runtime_);

                    Dictionary <string, object> respMap = _readAsJson(response_, "alipay.offline.material.image.upload");
                    if (_isCertMode())
                    {
                        if (_verify(respMap, _extractAlipayPublicKey(_getAlipayCertSN(respMap))))
                        {
                            return(TeaModel.ToObject <AlipayOfflineMaterialImageUploadResponse>(_toRespModel(respMap)));
                        }
                    }
                    else
                    {
                        if (_verify(respMap, _getConfig("alipayPublicKey")))
                        {
                            return(TeaModel.ToObject <AlipayOfflineMaterialImageUploadResponse>(_toRespModel(respMap)));
                        }
                    }
                    throw new TeaException(new Dictionary <string, string>()
                    {
                        { "message", "验签失败,请检查支付宝公钥设置是否正确。" },
                    });
                }
                catch (Exception e)
                {
                    if (TeaCore.IsRetryable(e))
                    {
                        _lastException = e;
                        continue;
                    }
                    throw e;
                }
            }

            throw new TeaUnretryableException(_lastRequest, _lastException);
        }
        public Dictionary <string, object> _request(string method, string pathname, Dictionary <string, object> query, Dictionary <string, string> headers, object body, AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime)
        {
            Dictionary <string, object> runtime_ = new Dictionary <string, object>
            {
                { "timeouted", "retry" },
                { "readTimeout", runtime.ReadTimeout },
                { "connectTimeout", runtime.ConnectTimeout },
                { "httpProxy", runtime.HttpProxy },
                { "httpsProxy", runtime.HttpsProxy },
                { "noProxy", runtime.NoProxy },
                { "maxIdleConns", runtime.MaxIdleConns },
                { "retry", new Dictionary <string, object>
                  {
                      { "retryable", runtime.Autoretry },
                      { "maxAttempts", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.MaxAttempts, 3) },
                  } },
                { "backoff", new Dictionary <string, object>
                  {
                      { "policy", AlibabaCloud.TeaUtil.Common.DefaultString(runtime.BackoffPolicy, "no") },
                      { "period", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.BackoffPeriod, 1) },
                  } },
                { "ignoreSSL", runtime.IgnoreSSL },
            };

            TeaRequest _lastRequest   = null;
            Exception  _lastException = null;
            long       _now           = System.DateTime.Now.Millisecond;
            int        _retryTimes    = 0;

            while (TeaCore.AllowRetry((IDictionary)runtime_["retry"], _retryTimes, _now))
            {
                if (_retryTimes > 0)
                {
                    int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes);
                    if (backoffTime > 0)
                    {
                        TeaCore.Sleep(backoffTime);
                    }
                }
                _retryTimes = _retryTimes + 1;
                try
                {
                    TeaRequest request_        = new TeaRequest();
                    string     accesskeyId     = GetAccessKeyId();
                    string     accessKeySecret = GetAccessKeySecret();
                    request_.Protocol = AlibabaCloud.TeaUtil.Common.DefaultString(_protocol, "HTTP");
                    request_.Method   = method;
                    request_.Pathname = pathname;
                    request_.Headers  = TeaConverter.merge <string>
                                        (
                        new Dictionary <string, string>()
                    {
                        { "user-agent", GetUserAgent() },
                        { "Date", AlibabaCloud.OpenSearchUtil.Common.GetDate() },
                        { "host", AlibabaCloud.TeaUtil.Common.DefaultString(_endpoint, "opensearch-cn-hangzhou.aliyuncs.com") },
                        { "X-Opensearch-Nonce", AlibabaCloud.TeaUtil.Common.GetNonce() },
                    },
                        headers
                                        );
                    if (!AlibabaCloud.TeaUtil.Common.IsUnset(query))
                    {
                        request_.Query = AlibabaCloud.TeaUtil.Common.StringifyMapValue(query);
                    }
                    if (!AlibabaCloud.TeaUtil.Common.IsUnset(body))
                    {
                        string reqBody = AlibabaCloud.TeaUtil.Common.ToJSONString(body);
                        request_.Headers["Content-MD5"]  = AlibabaCloud.OpenSearchUtil.Common.GetContentMD5(reqBody);
                        request_.Headers["Content-Type"] = "application/json";
                        request_.Body = TeaCore.BytesReadable(reqBody);
                    }
                    request_.Headers["Authorization"] = AlibabaCloud.OpenSearchUtil.Common.GetSignature(request_, accesskeyId, accessKeySecret);
                    _lastRequest = request_;
                    TeaResponse response_ = TeaCore.DoAction(request_, runtime_);

                    string objStr = AlibabaCloud.TeaUtil.Common.ReadAsString(response_.Body);
                    if (AlibabaCloud.TeaUtil.Common.Is4xx(response_.StatusCode) || AlibabaCloud.TeaUtil.Common.Is5xx(response_.StatusCode))
                    {
                        throw new TeaException(new Dictionary <string, object>
                        {
                            { "message", response_.StatusMessage },
                            { "data", objStr },
                            { "code", response_.StatusCode },
                        });
                    }
                    object obj = AlibabaCloud.TeaUtil.Common.ParseJSON(objStr);
                    Dictionary <string, object> res = AlibabaCloud.TeaUtil.Common.AssertAsMap(obj);
                    return(new Dictionary <string, object>
                    {
                        { "body", res },
                        { "headers", response_.Headers },
                    });
                }
                catch (Exception e)
                {
                    if (TeaCore.IsRetryable(e))
                    {
                        _lastException = e;
                        continue;
                    }
                    throw e;
                }
            }

            throw new TeaUnretryableException(_lastRequest, _lastException);
        }
Esempio n. 13
0
        /**
         * Encapsulate the request and invoke the network
         * @param version product version
         * @param protocol http or https
         * @param method e.g. GET
         * @param authType when authType is Anonymous, the signature will not be calculate
         * @param pathname pathname of every api
         * @param query which contains request params
         * @param headers request headers
         * @param body content of request
         * @param runtime which controls some details of call api, such as retry times
         * @return the response
         */
        public async Task <Dictionary <string, object> > DoRequestWithFormAsync(string version, string protocol, string method, string authType, string pathname, Dictionary <string, string> query, Dictionary <string, string> headers, Dictionary <string, object> body, AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime)
        {
            Dictionary <string, object> runtime_ = new Dictionary <string, object>
            {
                { "timeouted", "retry" },
                { "readTimeout", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.ReadTimeout, _readTimeout) },
                { "connectTimeout", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.ConnectTimeout, _connectTimeout) },
                { "httpProxy", AlibabaCloud.TeaUtil.Common.DefaultString(runtime.HttpProxy, _httpProxy) },
                { "httpsProxy", AlibabaCloud.TeaUtil.Common.DefaultString(runtime.HttpsProxy, _httpsProxy) },
                { "noProxy", AlibabaCloud.TeaUtil.Common.DefaultString(runtime.NoProxy, _noProxy) },
                { "maxIdleConns", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.MaxIdleConns, _maxIdleConns) },
                { "retry", new Dictionary <string, object>
                  {
                      { "retryable", runtime.Autoretry },
                      { "maxAttempts", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.MaxAttempts, 3) },
                  } },
                { "backoff", new Dictionary <string, object>
                  {
                      { "policy", AlibabaCloud.TeaUtil.Common.DefaultString(runtime.BackoffPolicy, "no") },
                      { "period", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.BackoffPeriod, 1) },
                  } },
                { "ignoreSSL", runtime.IgnoreSSL },
            };

            TeaRequest _lastRequest   = null;
            Exception  _lastException = null;
            long       _now           = System.DateTime.Now.Millisecond;
            int        _retryTimes    = 0;

            while (TeaCore.AllowRetry((IDictionary)runtime_["retry"], _retryTimes, _now))
            {
                if (_retryTimes > 0)
                {
                    int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes);
                    if (backoffTime > 0)
                    {
                        TeaCore.Sleep(backoffTime);
                    }
                }
                _retryTimes = _retryTimes + 1;
                try
                {
                    TeaRequest request_ = new TeaRequest();
                    request_.Protocol = AlibabaCloud.TeaUtil.Common.DefaultString(_protocol, protocol);
                    request_.Method   = method;
                    request_.Pathname = pathname;
                    request_.Headers  = TeaConverter.merge <string>
                                        (
                        new Dictionary <string, string>()
                    {
                        { "date", AlibabaCloud.TeaUtil.Common.GetDateUTCString() },
                        { "host", _endpointHost },
                        { "accept", "application/json" },
                        { "x-acs-signature-nonce", AlibabaCloud.TeaUtil.Common.GetNonce() },
                        { "x-acs-signature-method", "HMAC-SHA1" },
                        { "x-acs-signature-version", "1.0" },
                        { "x-acs-version", version },
                        { "user-agent", AlibabaCloud.TeaUtil.Common.GetUserAgent(_userAgent) },
                    },
                        headers
                                        );
                    if (!AlibabaCloud.TeaUtil.Common.IsUnset(body))
                    {
                        request_.Body = TeaCore.BytesReadable(AlibabaCloud.ROAUtil.Common.ToForm(body));
                        request_.Headers["content-type"] = "application/x-www-form-urlencoded";
                    }
                    if (!AlibabaCloud.TeaUtil.Common.IsUnset(query))
                    {
                        request_.Query = query;
                    }
                    if (!AlibabaCloud.TeaUtil.Common.EqualString(authType, "Anonymous"))
                    {
                        string accessKeyId = await this._credential.GetAccessKeyIdAsync();

                        string accessKeySecret = await this._credential.GetAccessKeySecretAsync();

                        string securityToken = await this._credential.GetSecurityTokenAsync();

                        if (!AlibabaCloud.TeaUtil.Common.Empty(securityToken))
                        {
                            request_.Headers["x-acs-accesskey-id"]   = accessKeyId;
                            request_.Headers["x-acs-security-token"] = securityToken;
                        }
                        string stringToSign = AlibabaCloud.ROAUtil.Common.GetStringToSign(request_);
                        request_.Headers["authorization"] = "acs " + accessKeyId + ":" + AlibabaCloud.ROAUtil.Common.GetSignature(stringToSign, accessKeySecret);
                    }
                    _lastRequest = request_;
                    TeaResponse response_ = await TeaCore.DoActionAsync(request_, runtime_);

                    if (AlibabaCloud.TeaUtil.Common.EqualNumber(response_.StatusCode, 204))
                    {
                        return(new Dictionary <string, object>
                        {
                            { "headers", response_.Headers },
                        });
                    }
                    object result = AlibabaCloud.TeaUtil.Common.ReadAsJSON(response_.Body);
                    if (AlibabaCloud.TeaUtil.Common.Is4xx(response_.StatusCode) || AlibabaCloud.TeaUtil.Common.Is5xx(response_.StatusCode))
                    {
                        Dictionary <string, object> err = AlibabaCloud.TeaUtil.Common.AssertAsMap(result);
                        throw new TeaException(new Dictionary <string, object>
                        {
                            { "code", Client.DefaultAny(err.Get("Code"), err.Get("code")) + "Error" },
                            { "message", "code: " + response_.StatusCode + ", " + Client.DefaultAny(err.Get("Message"), err.Get("message")) + " requestid: " + Client.DefaultAny(err.Get("RequestId"), err.Get("requestId")) },
                            { "data", err },
                        });
                    }
                    return(new Dictionary <string, object>
                    {
                        { "headers", response_.Headers },
                        { "body", result },
                    });
                }
                catch (Exception e)
                {
                    if (TeaCore.IsRetryable(e))
                    {
                        _lastException = e;
                        continue;
                    }
                    throw e;
                }
            }

            throw new TeaUnretryableException(_lastRequest, _lastException);
        }
Esempio n. 14
0
        public void TestStrToLower()
        {
            Assert.Empty(TeaConverter.StrToLower(null));

            Assert.Equal("test", TeaConverter.StrToLower("TEST"));
        }