Example #1
0
        public async Task <AlipaySystemOauthTokenResponse> RefreshTokenAsync(string refreshToken)
        {
            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.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", "refresh_token" },
                        { "refresh_token", refreshToken },
                    };
                    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);
        }
Example #2
0
        public AlipayPassInstanceAddResponse AddInstance(string tplId, string tplParams, string recognitionType, string recognitionInfo)
        {
            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.add" },
                        { "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>()
                    {
                        { "tpl_id", tplId },
                        { "tpl_params", tplParams },
                        { "recognition_type", recognitionType },
                        { "recognition_info", recognitionInfo },
                    };
                    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,
                        textParams
                        );
                    request_.Body = TeaCore.BytesReadable(_toUrlEncodedRequestBody(bizParams));
                    _lastRequest  = request_;
                    TeaResponse response_ = TeaCore.DoAction(request_, runtime_);

                    Dictionary <string, object> respMap = _readAsJson(response_, "alipay.pass.instance.add");
                    if (_isCertMode())
                    {
                        if (_verify(respMap, _extractAlipayPublicKey(_getAlipayCertSN(respMap))))
                        {
                            return(TeaModel.ToObject <AlipayPassInstanceAddResponse>(_toRespModel(respMap)));
                        }
                    }
                    else
                    {
                        if (_verify(respMap, _getConfig("alipayPublicKey")))
                        {
                            return(TeaModel.ToObject <AlipayPassInstanceAddResponse>(_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);
        }
Example #3
0
        public AlipayOfflineMaterialImageUploadResponse Upload(string videoName, string videoFilePath)
        {
            Dictionary <string, object> runtime_ = new Dictionary <string, object>
            {
                { "httpProxy", this._kernel.GetConfig("httpProxy") },
                { "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", 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>
                    {
                        { "image_type", "mp4" },
                        { "image_name", videoName },
                    };
                    Dictionary <string, string> fileParams = new Dictionary <string, string>
                    {
                        { "image_content", videoFilePath },
                    };
                    string boundary = this._kernel.GetRandomBoundary();
                    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", this._kernel.ConcatStr("multipart/form-data;charset=utf-8;boundary=", boundary) },
                    };
                    request_.Query = this._kernel.SortMap(TeaConverter.merge <string>
                                                          (
                                                              new Dictionary <string, string>()
                    {
                        { "sign", this._kernel.Sign(systemParams, bizParams, textParams, this._kernel.GetConfig("merchantPrivateKey")) },
                    },
                                                              systemParams
                                                          ));
                    request_.Body = this._kernel.ToMultipartRequestBody(textParams, fileParams, boundary);
                    _lastRequest  = request_;
                    TeaResponse response_ = TeaCore.DoAction(request_, runtime_);

                    Dictionary <string, object> respMap = this._kernel.ReadAsJson(response_, "alipay.offline.material.image.upload");
                    if (this._kernel.IsCertMode())
                    {
                        if (this._kernel.Verify(respMap, this._kernel.ExtractAlipayPublicKey(this._kernel.GetAlipayCertSN(respMap))))
                        {
                            return(TeaModel.ToObject <AlipayOfflineMaterialImageUploadResponse>(this._kernel.ToRespModel(respMap)));
                        }
                    }
                    else
                    {
                        if (this._kernel.Verify(respMap, this._kernel.GetConfig("alipayPublicKey")))
                        {
                            return(TeaModel.ToObject <AlipayOfflineMaterialImageUploadResponse>(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);
        }