public void TestCrate()
        {
            string       outTradeNo = Guid.NewGuid().ToString();
            HuabeiConfig config     = new HuabeiConfig()
            {
                HbFqNum           = "3",
                HbFqSellerPercent = "0"
            };
            AlipayTradeCreateResponse response = Factory.Payment.Huabei().Create("Iphone6 16G",
                                                                                 outTradeNo, "88.88", "2088002656718920", config);

            Assert.AreEqual(response.Code, "10000");
            Assert.AreEqual(response.Msg, "Success");
            Assert.Null(response.SubCode);
            Assert.Null(response.SubMsg);
            Assert.NotNull(response.HttpBody);
            Assert.AreEqual(response.OutTradeNo, outTradeNo);
            Assert.True(response.TradeNo.StartsWith("202"));
        }
示例#2
0
        public AlipayTradeCreateResponse Create(string subject, string outTradeNo, string totalAmount, string buyerId, HuabeiConfig extendParams)
        {
            extendParams.Validate();
            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.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>()
                    {
                        { "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 = _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.trade.create");
                    if (_isCertMode())
                    {
                        if (_verify(respMap, _extractAlipayPublicKey(_getAlipayCertSN(respMap))))
                        {
                            return(TeaModel.ToObject <AlipayTradeCreateResponse>(_toRespModel(respMap)));
                        }
                    }
                    else
                    {
                        if (_verify(respMap, _getConfig("alipayPublicKey")))
                        {
                            return(TeaModel.ToObject <AlipayTradeCreateResponse>(_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);
        }