[C#] 纯文本查看 复制代码
// 用suite_ticket 获取suite_access_token
var url = "https://qyapi.weixin.qq.com/cgi-bin/service/get_suite_token";
var body = "{\"suite_id\":\"" + WXConfig.SuiteID + "\",\"suite_secret\":\"" + WXConfig.Secret + "\",\"suite_ticket\":\"" + objcache.suite_ticket + "\"}";
//LogHelper.WriteLog(body);
var html = ShouQuan.InfoPost(url, body);
//LogHelper.WriteLog(html);
var info = JsonConvert.DeserializeObject<suite_access_token_info>(html);
if (!string.IsNullOrEmpty(info.suite_access_token))
{
// 存储suite_ticket
int result = cachebll.Update(DictBuilder.Assign("suite_access_token", info.suite_access_token).Assign("suite_access_token_update", DateTime.Now), $" suite_id='{WXConfig.SuiteID}'", null);
if (result > 0)
{
//LogHelper.WriteLog($"suite_access_token:{info.suite_access_token} 写入数据库成功");
}
else
{
//LogHelper.WriteLog($"suite_access_token:{info.suite_access_token} 写入数据库失败");
}
// 保存suite_access_token
return info.suite_access_token;
}
[C#] 纯文本查看 复制代码
/// <summary>
/// post请求代码
/// </summary>
/// <param name="url"></param>
/// <param name="body"></param>
/// <returns></returns>
public static string InfoPost(string url, string body)
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(url));
request.Timeout = 30000;//30秒
request.Method = "POST";
byte[] payload = System.Text.Encoding.UTF8.GetBytes(body);
Stream writer = request.GetRequestStream();
writer.Write(payload, 0, payload.Length);
writer.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8"));
var result = reader.ReadToEnd();
return result;
}