麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

C# Winfrom小黃雞功能調用

2019-11-17 01:46:23
字體:
來源:轉載
供稿:網友

C# Winfrom小黃雞功能調用

最近研究微信公眾平臺,搭建了一個微信聊天機器人,調用小黃雞的公眾接口,實現在線和小黃雞聊天的功能。

接口調用不是很麻煩,不過是php版本,所以研究了一下C#的功能模塊,

Winfrom版

后臺界面代碼為

  1 using System;  2 using System.Collections.Generic;  3 using System.ComponentModel;  4 using System.Data;  5 using System.Drawing;  6 using System.Linq;  7 using System.Text;  8 using System.Windows.Forms;  9 using System.Threading; 10  11 namespace 小賤雞 12 { 13     public partial class Form1 : Form 14     { 15         PRivate static string cookie = null; 16         private string msg = ""; 17         private Thread th2 = null; 18         private Thread th3 = null; 19         private bool changed = false; 20  21         public Form1() 22         { 23             InitializeComponent(); 24             simsimi.SetAllowUnsafeHeaderParsing20(); 25             Thread th = new Thread(new ThreadStart(Cookie_Thread)); 26             th2 = new Thread(new ThreadStart(Hi_Thread)); 27             th3 = new Thread(new ThreadStart(PowerOn_Thread)); 28             th.Start(); 29             th2.Start(); 30             th3.Start(); 31          } 32  33         private void button1_Click(object sender, EventArgs e) 34         { 35             if (textBox1.Text != "") 36             { 37                 changed = true; 38                 msg = textBox1.Text; 39                 textBox1.Text = ""; 40                 richTextBox1.Text += String.Format("Me:{0}/n", msg); 41                 changed = false; 42             } 43         }  44  45         private static void Cookie_Thread() 46         { 47             cookie = simsimi.GetCookie(); 48         } 49         private void PowerOn_Thread() 50         { 51             while (cookie == null) 52             { 53                 this.Invoke(new Action(Update_PowerText), null); 54                 Thread.Sleep(1500); 55             } 56              this.Invoke(new Action(Update_PowerFinalText), null); 57         } 58         private void Update_PowerText() 59         { 60             richTextBox1.Text += "正在開雞中。。。/n"; 61         } 62         private void Update_PowerFinalText() 63         { 64             richTextBox1.Text += "唔,終于開雞了。/n小賤雞:你好,我是小賤雞。o(∩_∩)o/n"; 65         } 66         private void Hi_Thread() 67         { 68             while (true) 69             { 70                 while (changed) 71                 { 72                     this.Invoke(new Action(Update_Text), null); 73                     break; 74                 } 75             } 76         } 77         private void Update_Text() 78         { 79             richTextBox1.Text += String.Format("小賤雞:{0}/n", simsimi.Hi_Simsimi(msg,cookie)); 80         } 81  82         private void textBox1_KeyUp(object sender, KeyEventArgs e) 83        { 84             if (e.KeyValue == 13) 85             { 86                 if (textBox1.Text != "") 87                 { 88                     changed = true; 89                     msg = textBox1.Text; 90                     textBox1.Text = ""; 91                     richTextBox1.Text += String.Format("Me:{0}/n", msg); 92                     changed = false; 93                 }           94             } 95         } 96  97         private void richTextBox1_TextChanged(object sender, EventArgs e) 98         { 99             //設定光標所在位置 100             this.richTextBox1.SelectionStart = richTextBox1.TextLength-1;101             //滾動到當前光標處 102             this.richTextBox1.ScrollToCaret();103         } 104 105     }106 }
View Code

應用的類代碼:應用接口用小黃雞那邊傳回來的是一個json形式的內容,所以應用到json的解析問題,我應用的是網上通用的方法Newtonsoft.Json,可以從網上下載對應的DLL

  1 using System;  2 using System.Collections.Generic;  3 using System.Linq;  4 using System.Text;  5 using System.Net;  6 using System.IO;  7 using System.IO.Compression;  8 using System.Reflection;  9 using Newtonsoft.Json; 10 using Newtonsoft.Json.Linq; 11   12  13 namespace 小賤雞 14 { 15     class simsimi 16     { 17         /// <summary> 18         /// Cookie 19         /// </summary> 20         /// <returns></returns> 21         public static string GetCookie() 22         { 23             string Cookiesstr = null; 24             CookieCollection cookies = new CookieCollection(); 25             HttpWebRequest request = null; 26             request = (HttpWebRequest)WebRequest.Create("http://www.simsimi.com/talk.htm"); 27             request.CookieContainer = new CookieContainer(); 28             request.CookieContainer.Add(cookies); 29             //Get the response from the server and save the cookies from the request.. 30             HttpWebResponse response = (HttpWebResponse)request.GetResponse(); 31             Cookiesstr = request.CookieContainer.GetCookieHeader(request.RequestUri); 32  33             return Cookiesstr; 34         } 35   36  37         public static string Hi_Simsimi(string que, string cookies) 38         { 39             string ans = "我們換個話題吧"; 40             string url = String.Format("http://www.simsimi.com/func/reqN?lc=ch&ft=0.0&req={0}&fl=http%3A%2F%2Fwww.simsimi.com%2Ftalk.htm", que); 41             HttpWebRequest hi_request = null; 42             try 43             { 44                 hi_request = (HttpWebRequest)WebRequest.Create(url); 45                 hi_request.Method = "GET"; 46                 hi_request.KeepAlive = true; 47                 hi_request.ServicePoint.Expect100Continue = false; 48  49                 hi_request.AllowWriteStreamBuffering = false; 50                 //終端信息 51                 hi_request.Accept = "application/json,text/javascr
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 亚洲午夜久久久精品一区二区三区 | 久久免费看毛片 | 视频在线中文字幕 | 久久久中文 | 欧美一区二区精品夜夜嗨 | 午夜精品成人 | 精品国产九九九 | 性片网站 | 成人午夜网址 | 777zyz色资源站在线观看 | 欧美精品一区二区三区在线 | 成人免费一区二区三区在线观看 | 亚洲欧美日韩一区二区三区在线观看 | 欧美一级免费看 | 色视频在线观看 | 欧美一级免费视频 | 羞羞电影在线观看www | 欧美1区2区在线观看 | 国产91九色 | 国产精品成人亚洲一区二区 | 久久午夜免费视频 | 日韩欧美综合在线 | 亚洲第一色婷婷 | 久久看免费视频 | www.国产一区.com | 婷婷久久青草热一区二区 | 全免费午夜一级毛片真人 | 天天舔夜夜操 | 黑人日比视频 | 欧洲色阁中文字幕 | 国产91在线播放九色 | 高清中文字幕在线 | 黄色免费播放网站 | 黄色一级毛片免费看 | 丁香天堂网 | 国产无限资源在线观看 | 国产88久久久国产精品免费二区 | 亚洲草逼视频 | 中文字幕在线观看免费 | 日韩午夜片 | 在线播放污|