コード例 #1
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", _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>()
                    {
                        { "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 = _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_ = await TeaCore.DoActionAsync(request_, runtime_);

                    Dictionary <string, object> respMap = _readAsJson(response_, "alipay.pass.instance.update");
                    if (_isCertMode())
                    {
                        if (_verify(respMap, _extractAlipayPublicKey(_getAlipayCertSN(respMap))))
                        {
                            return(TeaModel.ToObject <AlipayPassInstanceUpdateResponse>(_toRespModel(respMap)));
                        }
                    }
                    else
                    {
                        if (_verify(respMap, _getConfig("alipayPublicKey")))
                        {
                            return(TeaModel.ToObject <AlipayPassInstanceUpdateResponse>(_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);
        }
コード例 #2
0
        public async Task <AlipaySystemOauthTokenResponse> GetTokenAsync(string code)
        {
            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.system.oauth.token" },
                        { "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>()
                    {
                    };
                    Dictionary <string, string> textParams = new Dictionary <string, string>
                    {
                        { "grant_type", "authorization_code" },
                        { "code", code },
                    };
                    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.system.oauth.token");

                    if (this._kernel.IsCertMode())
                    {
                        if (this._kernel.Verify(respMap, this._kernel.ExtractAlipayPublicKey(this._kernel.GetAlipayCertSN(respMap))))
                        {
                            return(TeaModel.ToObject <AlipaySystemOauthTokenResponse>(this._kernel.ToRespModel(respMap)));
                        }
                    }
                    else
                    {
                        if (this._kernel.Verify(respMap, this._kernel.GetConfig("alipayPublicKey")))
                        {
                            return(TeaModel.ToObject <AlipaySystemOauthTokenResponse>(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);
        }
コード例 #3
0
        /**
         * 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 version, string action, string protocol, string method, string pathname, Dictionary <string, object> request, Dictionary <string, string> headers, 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) },
                { "maxIdleTimeMillis", _maxIdleTimeMillis },
                { "keepAliveDurationMillis", _keepAliveDurationMillis },
                { "maxRequests", _maxRequests },
                { "maxRequestsPerHost", _maxRequestsPerHost },
                { "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", version },
                        { "sign_type", "HmacSHA1" },
                        { "req_time", AntChain.AlipayUtil.AntchainUtils.GetTimestamp() },
                        { "req_msg_id", AntChain.AlipayUtil.AntchainUtils.GetNonce() },
                        { "access_key", _accessKeyId },
                        { "base_sdk_version", "TeaSDK-2.0" },
                        { "sdk_version", "1.1.6" },
                    };
                    if (!AlibabaCloud.TeaUtil.Common.Empty(_securityToken))
                    {
                        request_.Query["security_token"] = _securityToken;
                    }
                    request_.Headers = TeaConverter.merge <string>
                                       (
                        new Dictionary <string, string>()
                    {
                        { "host", AlibabaCloud.TeaUtil.Common.DefaultString(_endpoint, "openapi.antchain.antgroup.com") },
                        { "user-agent", AlibabaCloud.TeaUtil.Common.GetUserAgent(_userAgent) },
                    },
                        headers
                                       );
                    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.AntchainUtils.GetSignature(signedParam, _accessKeySecret);
                    _lastRequest           = request_;
                    TeaResponse response_ = TeaCore.DoAction(request_, runtime_);

                    string raw = AlibabaCloud.TeaUtil.Common.ReadAsString(response_.Body);
                    object obj = AlibabaCloud.TeaUtil.Common.ParseJSON(raw);
                    Dictionary <string, object> res  = AlibabaCloud.TeaUtil.Common.AssertAsMap(obj);
                    Dictionary <string, object> resp = AlibabaCloud.TeaUtil.Common.AssertAsMap(res.Get("response"));
                    if (AntChain.AlipayUtil.AntchainUtils.HasError(raw, _accessKeySecret))
                    {
                        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);
        }
コード例 #4
0
        public AlipayTradePayResponse Pay(string subject, string outTradeNo, string totalAmount, string authCode)
        {
            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.trade.pay" },
                        { "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>()
                    {
                        { "subject", subject },
                        { "out_trade_no", outTradeNo },
                        { "total_amount", totalAmount },
                        { "auth_code", authCode },
                        { "scene", "bar_code" },
                    };
                    Dictionary <string, string> textParams = new Dictionary <string, string>()
                    {
                    };
                    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) },
                    },
                        systemParams,
                        textParams
                        );
                    request_.Body = TeaCore.BytesReadable(_toUrlEncodedRequestBody(bizParams));
                    _lastRequest  = request_;
                    TeaResponse response_ = TeaCore.DoAction(request_, runtime_);

                    Dictionary <string, object> respMap = _readAsJson(response_, "alipay.trade.pay");
                    if (_isCertMode())
                    {
                        if (_verify(respMap, _extractAlipayPublicKey(_getAlipayCertSN(respMap))))
                        {
                            return(TeaModel.ToObject <AlipayTradePayResponse>(_toRespModel(respMap)));
                        }
                    }
                    else
                    {
                        if (_verify(respMap, _getConfig("alipayPublicKey")))
                        {
                            return(TeaModel.ToObject <AlipayTradePayResponse>(_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);
        }
コード例 #5
0
        public void Test_PercentEncode()
        {
            Assert.Null(TeaCore.PercentEncode(null));

            Assert.Equal("test%3D", TeaCore.PercentEncode("test="));
        }
コード例 #6
0
        public void TestDoAction()
        {
            TeaRequest teaRequest = new TeaRequest();

            teaRequest.Protocol        = "http";
            teaRequest.Method          = "GET";
            teaRequest.Headers         = new Dictionary <string, string>();
            teaRequest.Headers["host"] = "www.alibabacloud.com";
            teaRequest.Pathname        = "/s/zh";
            teaRequest.Query           = new Dictionary <string, string>();
            teaRequest.Query.Add("k", "ecs");
            Dictionary <string, object> runtime = new Dictionary <string, object>();

            runtime.Add("readTimeout", 7000);
            runtime.Add("connectTimeout", 7000);
            runtime.Add("httpsProxy", "http://www.alibabacloud.com/s/zh?k=ecs");
            runtime.Add("ignoreSSL", true);

            TeaResponse teaResponse = TeaCore.DoAction(teaRequest, runtime);

            Assert.NotNull(teaResponse);

            teaRequest.Protocol = "https";
            teaResponse         = TeaCore.DoAction(teaRequest);
            Assert.NotNull(teaResponse);


            string bodyStr = TeaCore.GetResponseBody(teaResponse);

            Assert.NotNull(bodyStr);

            teaRequest.Method = "POST";
            teaRequest.Body   = new MemoryStream(Encoding.UTF8.GetBytes("test"));
            teaRequest.Headers["content-test"] = "test";
            teaResponse = TeaCore.DoAction(teaRequest, runtime);
            Assert.NotNull(teaResponse);

            TeaRequest teaRequest404 = new TeaRequest();

            teaRequest404.Protocol        = "https";
            teaRequest404.Method          = "GET";
            teaRequest404.Headers         = new Dictionary <string, string>();
            teaRequest404.Headers["host"] = "www.alibabacloud404.com";
            teaRequest404.Pathname        = "/s/zh";
            teaRequest404.Query           = new Dictionary <string, string>();
            teaRequest404.Query.Add("k", "ecs");
            Dictionary <string, object> runtime404 = new Dictionary <string, object>();

            runtime404.Add("readTimeout", 7000);
            runtime404.Add("connectTimeout", 7000);
            Assert.Throws <AggregateException>(() => { TeaCore.DoAction(teaRequest404, runtime404); });

            TeaRequest teaRequestProxy = new TeaRequest();


            TeaRequest requestException = new TeaRequest
            {
                Protocol = "http",
                Method   = "GET",
                Pathname = "/test"
            };
            Dictionary <string, object> runtimeException = new Dictionary <string, object>();

            requestException.Headers["host"] = "www.aliyun.com";
            TeaResponse responseException = TeaCore.DoAction(requestException, runtimeException);

            Assert.NotNull(responseException);
        }
コード例 #7
0
        public async Task TestDoActionAsync()
        {
            TeaRequest teaRequest = new TeaRequest();

            teaRequest.Protocol        = "https";
            teaRequest.Method          = "GET";
            teaRequest.Headers         = new Dictionary <string, string>();
            teaRequest.Headers["host"] = "www.alibabacloud.com";
            teaRequest.Pathname        = "/s/zh";
            teaRequest.Query           = new Dictionary <string, string>();
            teaRequest.Query.Add("k", "ecs");

            TeaResponse teaResponse = await TeaCore.DoActionAsync(teaRequest);

            Assert.NotNull(teaResponse);

            Dictionary <string, object> runtime = new Dictionary <string, object>();

            runtime.Add("readTimeout", 4000);
            runtime.Add("connectTimeout", 0);

            teaResponse = await TeaCore.DoActionAsync(teaRequest, runtime);

            Assert.NotNull(teaResponse);

            string bodyStr = TeaCore.GetResponseBody(teaResponse);

            Assert.NotNull(bodyStr);

            teaRequest.Method = "POST";
            teaRequest.Body   = new MemoryStream(Encoding.UTF8.GetBytes("test"));
            teaResponse       = await TeaCore.DoActionAsync(teaRequest, runtime);

            Assert.NotNull(teaResponse);

            TeaRequest teaRequest404 = new TeaRequest();

            teaRequest404.Protocol        = "https";
            teaRequest404.Method          = "GET";
            teaRequest404.Headers         = new Dictionary <string, string>();
            teaRequest404.Headers["host"] = "www.alibabacloud404.com";
            teaRequest404.Pathname        = "/s/zh";
            teaRequest404.Query           = new Dictionary <string, string>();
            teaRequest404.Query.Add("k", "ecs");
            Dictionary <string, object> runtime404 = new Dictionary <string, object>();

            runtime404.Add("readTimeout", 7000);
            runtime404.Add("connectTimeout", 7000);
            await Assert.ThrowsAsync <HttpRequestException>(async() => { await TeaCore.DoActionAsync(teaRequest404, runtime); });

            TeaRequest requestException = new TeaRequest
            {
                Protocol = "http",
                Method   = "GET",
                Pathname = "/test"
            };
            Dictionary <string, object> runtimeException = new Dictionary <string, object>();

            requestException.Headers["host"] = "www.aliyun.com";
            TeaResponse responseException = await TeaCore.DoActionAsync(requestException, runtimeException);
        }
コード例 #8
0
ファイル: Client.cs プロジェクト: fjch1997/alipay-easysdk
        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) },
                    },
                        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);
        }
コード例 #9
0
ファイル: Client.cs プロジェクト: aliyun/tea-roa
        /**
         * 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);
        }
コード例 #10
0
        protected string _readAsString(TeaResponse teaResponse)
        {
            string bodyStr = TeaCore.GetResponseBody(teaResponse);

            return(bodyStr);
        }
コード例 #11
0
 /// <summary>
 /// Create a new tea key
 /// </summary>
 /// <returns></returns>
 public static string GenerateTeaKey() => TeaCore.GenerateTeaKey();