如何认证成为开发者?请点击第一篇文章进行查看,成为了开发者之后微信平台会给您appid和secret,在订阅号中是没有的,所以因该申请一下服务号,有了ACCESSTOKEN才能做添加菜单,上传/下载图片等功能。

private string GetToken()
   {

     // 也可以这样写:
     //return GetPage("https://api.weixin.qq.com/cgi-bin/token", "");
    
     string res = "";
     HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("https://api.weixin.qq.com/cgi-bin/token");
 req.Method = "GET";
     using (WebResponse wr = req.GetResponse())
     {
       HttpWebResponse myResponse = (HttpWebResponse)req.GetResponse();


       StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);


       string content = reader.ReadToEnd();
  
       List<ACCESSTOKEN> myACCESSTOKEN = Json.JSONStringToList<ACCESSTOKEN>(content);
       res = myACCESSTOKEN[0].access_token;
 
     }


     return res;
   }
   public string GetPage(string posturl, string postData)
   {
     Stream outstream = null;
     Stream instream = null;
     StreamReader sr = null;
     HttpWebResponse response = null;
     HttpWebRequest request = null;
     Encoding encoding = Encoding.UTF8;
     byte[] data = encoding.GetBytes(postData);
     // 准备请求...
     try
     {
       // 设置参数
       request = WebRequest.Create(posturl) as HttpWebRequest;
       CookieContainer cookieContainer = new CookieContainer();
       request.CookieContainer = cookieContainer;
       request.AllowAutoRedirect = true;
       request.Method = "POST";
       request.ContentType = "application/x-www-form-urlencoded";
       request.ContentLength = data.Length;
       outstream = request.GetRequestStream();
       outstream.Write(data, 0, data.Length);
       outstream.Close();
       //发送请求并获取相应回应数据
       response = request.GetResponse() as HttpWebResponse;
       //直到request.GetResponse()程序才开始向目标网页发送Post请求
       instream = response.GetResponseStream();
       sr = new StreamReader(instream, encoding);
       //返回结果网页(html)代码
       string content = sr.ReadToEnd();
       string err = string.Empty;
       return content;
     }
     catch (Exception ex)
     {
       string err = ex.Message;
       Response.Write(err);
       return string.Empty;
     }
   }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。