protected static void BettingYiXing(ref BettingSolutinModel bettingData, GloableConstants.AccountBelongs wherefrom, string userToken) { string url = ""; if (wherefrom == GloableConstants.AccountBelongs.Jiang) { url = GloableConstants.Jiang.Phone_CqsscBetServiceUrl; } else if (wherefrom == GloableConstants.AccountBelongs.Qcw) { url = GloableConstants.Qcw.Phone_CqsscBetServiceUrl; } try { CqsscBettingContent bet = new CqsscBettingContent(); bet.UserToken = userToken; //bet.CodeList = GetCodeListNew("-,-,-,-,234", bet.GameType); //bet.GameType = GloableConstants.CqsscGameType.DXDS; //bet.CodeList = GetCodeListNew("4,4;5,4", bet.GameType); bet.GameType = GloableConstants.CqsscGameType.YiXingDX.ToString(); bet.CodeList = GetCodeListNew(bettingData.BettingNumStr, bet.GameType); bet.TotalMatchCount = bettingData.Zhushu; bet.IssuseList = GetIssuseListNew(bettingData.Beishu, bet.TotalMatchCount, bettingData.CurrentIssueStr); bet.RedBagMoney = bettingData.MaxRedUse; bet.TotalMoney = bettingData.TotalMoney; string content = JsonHelper.ObjectToJson(bet); Dictionary <string, string> map = new Dictionary <string, string>(); map.Add("Action", "104"); map.Add("SourceCode", "102"); map.Add("MsgId", "123456"); map.Add("Param", HtmlUtil.UrlEncode(content)); map.Add("Sign", HtmlUtil.UrlEncode(GetMd5HashStr("caibb123456102104" + content))); var objUri = new Uri(url); HttpWebRequest httpRequest = HttpWebRequest.Create(objUri) as HttpWebRequest; httpRequest.Method = "POST"; httpRequest.Accept = "*/*"; httpRequest.KeepAlive = true; httpRequest.ContentType = "application/x-www-form-urlencoded"; httpRequest.UserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.3 (KHTML, like Gecko) Version/8.0 Mobile/12A4345d Safari/600.1.4"; httpRequest.Headers.Add("Cache-Control", "no-cache"); httpRequest.Timeout = 10000; #region 添加Post 参数 StringBuilder builder = new StringBuilder(); var dic = map; int i = 0; foreach (var item in dic) { if (i > 0) { builder.Append("&"); } builder.AppendFormat("{0}={1}", item.Key, item.Value); i++; } byte[] data = Encoding.UTF8.GetBytes(builder.ToString()); httpRequest.ContentLength = data.Length; using (Stream reqStream = httpRequest.GetRequestStream()) { reqStream.Write(data, 0, data.Length); reqStream.Close(); } #endregion var httpResponse = httpRequest.GetResponse(); var responseStream = new StreamReader(httpResponse.GetResponseStream(), Encoding.UTF8); var responseJson = responseStream.ReadToEnd(); responseStream.Close(); BettingResponse response = JsonHelper.JsonToObject <BettingResponse>(responseJson); if (response.Code == 101) { bettingData.IsBettingSucc = true; } bettingData.ResponseCode = response.Code; bettingData.MyMessage = response.Message; } catch (Exception ex) { bettingData.IsBettingSucc = false; bettingData.MyMessage = "投注异常:" + ex.Message; } }
private void button2_Click(object sender, EventArgs e) { //string a="12345678910"; //this.richTextBox1.Text = this.getMd5HashStr(a); //return; CqsscBettingContent bet = new CqsscBettingContent(); //bet.GameType = GloableConstants.CqsscGameType.YiXingDX.ToString(); //bet.CodeList = this.getCodeListNew("-,-,-,-,234", bet.GameType); bet.GameType = GloableConstants.CqsscGameType.DXDS; bet.CodeList = this.getCodeListNew("4,4;5,4", bet.GameType); bet.TotalMatchCount = 2; bet.IssuseList = this.getIssuseListNew(1, bet.TotalMatchCount, this.textBox1.Text.Trim()); bet.RedBagMoney = 0.12f; bet.TotalMoney = 4; string content = JsonHelper.ObjectToJson(bet); //this.richTextBox1.Text = content; //return; Dictionary <string, string> map = new Dictionary <string, string>(); map.Add("Action", "104"); map.Add("SourceCode", "102"); map.Add("MsgId", "123456"); map.Add("Param", HtmlUtil.UrlEncode(content)); map.Add("Sign", HtmlUtil.UrlEncode(this.getMd5HashStr2("caibb123456102104" + content))); this.richTextBox1.Text += JsonHelper.ObjectToJson(map) + "\r\n"; string url = "http://app.jiangapps.com/LotteryService/Service"; try { var objUri = new Uri(url); WebRequest httpRequest = HttpWebRequest.Create(objUri); httpRequest.Method = "POST"; httpRequest.ContentType = "application/x-www-form-urlencoded"; #region 添加Post 参数 StringBuilder builder = new StringBuilder(); var dic = map; int i = 0; foreach (var item in dic) { if (i > 0) { builder.Append("&"); } builder.AppendFormat("{0}={1}", item.Key, item.Value); i++; } byte[] data = Encoding.UTF8.GetBytes(builder.ToString()); httpRequest.ContentLength = data.Length; using (Stream reqStream = httpRequest.GetRequestStream()) { reqStream.Write(data, 0, data.Length); reqStream.Close(); } #endregion var httpResponse = httpRequest.GetResponse(); var responseStream = new StreamReader(httpResponse.GetResponseStream(), Encoding.UTF8); var responseJson = responseStream.ReadToEnd(); responseStream.Close(); //GlobalParams.TimeOutTimes = 0; this.richTextBox1.Text += responseJson + "\r\n"; //AccountResponse account = JsonHelper.JsonToObject<AccountResponse>(responseJson); //GloableParams.CurrentAccount = account; } catch (Exception ex) { //GlobalParams.TimeOutTimes++; this.richTextBox1.Text += ex.Message + "\r\n"; } }