using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Reflection;
using System.Net;
using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Security.Cryptography;
using System.Text;
namespace user
{
public partial class FormIOT : Form
{
private static log4net.ILog log = log4net.LogManager.GetLogger(typeof(FormIOT));
string strToken = “”;
public static string access_token = “”;
public static DateTime token_last_time;
public FormIOT()
{
InitializeComponent();
}
private void bt_sent_Click(object sender, EventArgs e)
{
if(!string.IsNullOrEmpty(this.tb_content.Text.Trim()))
{
if (string.IsNullOrEmpty(access_token))
{
getToken();
}
if (!string.IsNullOrEmpty(access_token))
{
updateLedContent(this.tb_content.Text.Trim(), access_token);
}
else
{
MessageBox.Show("Token为空");
}
}
else
{
MessageBox.Show("请输入内容!");
this.tb_content.Focus();
}
}
/// <summary>
/// 获得Token
/// </summary>
public static void getToken()
{
string href = "http://www.bekingai.com/login";
LoginInfo user = new LoginInfo();
user.account = "feek";
//MD5加密后的密码
user.password = MD5Encrypt32("13434r");
string json = JsonConvert.SerializeObject(user);
string result = GetResponse(href, null, json);
FirstResult<DataResult> uresult = DeserializeJsonToObject<FirstResult<DataResult>>(result);
//成功
if (uresult.status == 0)
{
access_token = uresult.data.token;
token_last_t