Example #1
0
        public async Task <AlipayTradeCreateResponse> CreateAsync(string subject, string outTradeNo, string totalAmount, string buyerId, HuabeiConfig extendParams)
        {
            extendParams.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.trade.create" },
                        { "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>
                    {
                        { "subject", subject },
                        { "out_trade_no", outTradeNo },
                        { "total_amount", totalAmount },
                        { "buyer_id", buyerId },
                        { "extend_params", extendParams },
                    };
                    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.trade.create");

                    if (this._kernel.IsCertMode())
                    {
                        if (this._kernel.Verify(respMap, this._kernel.ExtractAlipayPublicKey(this._kernel.GetAlipayCertSN(respMap))))
                        {
                            return(TeaModel.ToObject <AlipayTradeCreateResponse>(this._kernel.ToRespModel(respMap)));
                        }
                    }
                    else
                    {
                        if (this._kernel.Verify(respMap, this._kernel.GetConfig("alipayPublicKey")))
                        {
                            return(TeaModel.ToObject <AlipayTradeCreateResponse>(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 AlipayOpenAppQrcodeCreateResponse Create(string urlParam, string queryParam, string describe)
        {
            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.open.app.qrcode.create" },
                        { "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>()
                    {
                        { "url_param", urlParam },
                        { "query_param", queryParam },
                        { "describe", describe },
                    };
                    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.open.app.qrcode.create");
                    if (_isCertMode())
                    {
                        if (_verify(respMap, _extractAlipayPublicKey(_getAlipayCertSN(respMap))))
                        {
                            return(TeaModel.ToObject <AlipayOpenAppQrcodeCreateResponse>(_toRespModel(respMap)));
                        }
                    }
                    else
                    {
                        if (_verify(respMap, _getConfig("alipayPublicKey")))
                        {
                            return(TeaModel.ToObject <AlipayOpenAppQrcodeCreateResponse>(_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 AlipayOpenAppMiniTemplatemessageSendResponse Send(string toUserId, string formId, string userTemplateId, string page, string data)
        {
            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.open.app.mini.templatemessage.send" },
                        { "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>
                    {
                        { "to_user_id", toUserId },
                        { "form_id", formId },
                        { "user_template_id", userTemplateId },
                        { "page", page },
                        { "data", data },
                    };
                    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.open.app.mini.templatemessage.send");
                    if (this._kernel.IsCertMode())
                    {
                        if (this._kernel.Verify(respMap, this._kernel.ExtractAlipayPublicKey(this._kernel.GetAlipayCertSN(respMap))))
                        {
                            return(TeaModel.ToObject <AlipayOpenAppMiniTemplatemessageSendResponse>(this._kernel.ToRespModel(respMap)));
                        }
                    }
                    else
                    {
                        if (this._kernel.Verify(respMap, this._kernel.GetConfig("alipayPublicKey")))
                        {
                            return(TeaModel.ToObject <AlipayOpenAppMiniTemplatemessageSendResponse>(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 #4
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);
        }