• .net 后台以post方式调用微信公众平台接口


    1 public class Fresult
    2 {
    3         public int errcode { get; set; }
    4         public string errmsg { get; set; }
    5         public string msgid { get; set; }
    6 }
     1  public static Fresult SendTemplateMessage(string accessToken, string body)
     2 {
     3             Fresult fresult = new Fresult();
     4             string uriStr = $"https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={accessToken}";
     5             var uri = new Uri(uriStr);
     6             HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
     7             request.Method = "POST";
     8             request.ContentType = "application/json";
     9             request.Accept = "application/json";
    10             Encoding encoding = Encoding.UTF8;
    11             byte[] data = encoding.GetBytes(body);
    12             Stream sm = request.GetRequestStream();
    13             sm.Write(data, 0, data.Length);
    14             sm.Close();
    15             HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    16             using (Stream streamResponse = response.GetResponseStream())
    17             {
    18                 using (StreamReader streamRead = new StreamReader(streamResponse, Encoding.UTF8))
    19                 {
    20                     char[] readBuff = new char[256];
    21                     int count = streamRead.Read(readBuff, 0, 256);
    22                     string content = "";
    23                     while (count > 0)
    24                     {
    25                         string outputData = new string(readBuff, 0, count);
    26                         content += outputData;                                             
    27                         count = streamRead.Read(readBuff, 0, 256);
    28                     }
    29                     fresult = JsonConvert.DeserializeObject<Fresult>(content);
    30                 }
    31             }
    32             response.Close();
    33             response.Dispose();
    34             return fresult;
    35 }
  • 相关阅读:
    Caffe--solver.prototxt配置文件 参数设置及含义
    关于KMP算法理解(快速字符串匹配)
    Lintcode--004(最小子串覆盖)
    Lintcode--003(乱序字符串)
    Lintcode--002(两个字符串是变位词)
    Lintcode--001(比较字符串)
    闭包的应用实例
    JavaScript完整性检查
    null和undefined相等比较
    JavaScript逻辑运算符(操作数运算符)
  • 原文地址:https://www.cnblogs.com/jasonbourne3/p/11098209.html
Copyright © 2020-2023  润新知