private void Workwxnotic(String message) { String[] workwxidarr = idorkeyt.Text.Split(new char[1] { '.' }); String corpid = workwxidarr[0]; String corpsecret = workwxidarr[1]; String agentid = workwxidarr[2]; String tokenpath = noticpatht.Text + "\\workwx.token"; String access_token; if (File.Exists(tokenpath)) { DateTime tokencretime = new FileInfo(tokenpath).LastWriteTime; DateTime tokenexptime = tokencretime.AddHours(2); if (DateTime.Now < tokenexptime) { returnmsgt.AppendText("\r\n企业微信的本地token还在有效期内,继续使用"); access_token = File.ReadAllText(tokenpath); } else { returnmsgt.AppendText("\r\n企业微信的本地token可能已过期,正在自动重新获取"); access_token = GetWorkwxtoken(corpid, corpsecret); if (access_token == "") { return; } } } else { access_token = GetWorkwxtoken(corpid, corpsecret); if (access_token == "") { return; } } SendWorkwxmsg(agentid, access_token, message); }