コード例 #1
0
ファイル: ProxyAcquisition.cs プロジェクト: chenjunsheep/Sxh
        public async Task <SxhResult> SubmitAsync(VmAcquire para)
        {
            if (para != null && para.IsAvailable)
            {
                var cookieJar = new CookieContainer();
                using (var handler = new HttpClientHandler
                {
                    CookieContainer = cookieJar,
                    UseCookies = true,
                })
                {
                    using (var client = CreateHttpClient(handler))
                    {
                        client.DefaultRequestHeaders.Add("X-Requested-With", "XMLHttpRequest");
                        client.DefaultRequestHeaders.Add("Accept", "*/*");
                        client.DefaultRequestHeaders.Add("Connection", "keep-alive");
                        client.DefaultRequestHeaders.Referrer = CreateUri($"CommissionedAcquisition?projectId={para.ProjectId}&currentPrice={para.ShowPrice}");

                        var formData = new FormUrlEncodedContent(new[] {
                            new KeyValuePair <string, string>("acquisitionPrice", $"{para.AcquisitionPrice}"),
                            new KeyValuePair <string, string>("copies", $"{ para.Copies}"),
                            new KeyValuePair <string, string>("checkbox1", "on"),
                            new KeyValuePair <string, string>("projectId", $"{para.ProjectId}"),
                            new KeyValuePair <string, string>("TOKEN_ACQUIRE", para.TokenAcquire),
                            new KeyValuePair <string, string>("showPrice", $"{para.ShowPrice}"),
                            new KeyValuePair <string, string>("transactionPassword", para.TransactionPassword.Md5Encrypt()),
                            new KeyValuePair <string, string>("verificationCode", para.VerificationCode),
                            new KeyValuePair <string, string>("tockenKey", para.TockenKey),
                        });

                        var uri = CreateUri("/project/acquisitionSubmit");

                        foreach (Cookie token in para.TokenOffical)
                        {
                            cookieJar.Add(uri, new Cookie(token.Name, token.Value));
                        }

                        var response = await client.PostAsync(uri, formData);

                        if (response.IsSuccessStatusCode)
                        {
                            await response.Content.ReadAsStringAsync();

                            return(new SxhResult(true, $"{para.Copies}份 {para.ProjectName}已成功提交"));
                        }
                        else
                        {
                            return(new SxhResult(false, response.StatusCode));
                        }
                    }
                }
            }

            return(new SxhResult(false, $"invalid acquire parameter"));
        }
コード例 #2
0
ファイル: Acquisition.cs プロジェクト: chenjunsheep/Sxh
        private async Task <SxhResult> SubmitAsync()
        {
            if (Project != null && Account != null)
            {
                var para = new VmAcquire()
                {
                    AcquisitionPrice    = TypeParser.GetDoubleValue(Project.minTransferingPrice, 0),
                    Copies              = TypeParser.GetInt32Value(txtCopy.Text),
                    ProjectId           = Project.projectId,
                    ProjectName         = Project.projectTitle,
                    ShowPrice           = TypeParser.GetDoubleValue(Project.advicePrice),
                    TockenKey           = txtToken.Text,
                    TokenAcquire        = txtTokenAcquire.Text,
                    TransactionPassword = Account.PasswordTran,
                    VerificationCode    = txtVerifyCode.Text,
                    TokenOffical        = Account.TokenOffical,
                };

                var proxy = new ProxyAcquisition();
                return(await proxy.SubmitAsync(para));
            }

            return(new SxhResult(false, $"invalid project or account"));
        }