private string appsecret = BP.Sys.SystemConfig.WX_AppSecret; // "KfFkE9AZ3Zp09zTuKvmqWLgtLj-_cHMPTvV992apOWgSKJHcbjpbu1jYVXh7gI7K"; public string getAccessToken() { string accessToken = string.Empty; string url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=" + appid + "&corpsecret=" + appsecret + ""; try { AccessToken AT = new AccessToken(); HttpWebResponse response = new HttpWebResponseUtility().CreateGetHttpResponse(url, 10000, null, null); StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8); string str = reader.ReadToEnd(); AT = FormatToJson.ParseFromJson <AccessToken>(str); reader.Dispose(); reader.Close(); if (response != null) { response.Close(); } if (AT != null) { accessToken = AT.access_token; } } catch { } return(accessToken); }
/// <summary> /// POST方式请求 微信返回信息 /// </summary> /// <param name="parameters">参数</param> /// <param name="URL">请求地址</param> /// <returns>返回字符</returns> public string PostForWeiXin(StringBuilder parameters, string URL) { string access_token = getAccessToken(); string url = URL + "access_token=" + access_token; HttpWebResponse response = new HttpWebResponseUtility().WXCreateGetHttpResponse(url, parameters, 10000, null, Encoding.UTF8, null); StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8); string str = reader.ReadToEnd(); WriteLog(url + "----------------" + parameters + "---------------" + str); return(str); }