微信公众号开发客服接口实例代码

最近,开发微信公众号,负责开发客服功能,这里简单记录下:

Kf_account.cs代码:

 public partial class Kf_account : Form
  {
    private readonly DataTable adt_user = new DataTable();
    private readonly string as_INIFile = Application.StartupPath + "\\user.ini";

    public Kf_account()
    {
      BindUser();
    }

    private void BindUser()
    {
      if (!File.Exists(as_INIFile))
      {
        var str = new StringBuilder();
        str.Append(";内容由程序自动生成,请不要修改此文件内容\r\n");
        str.Append("[total]\r\n");
        str.Append("total=\r\n");
        str.Append("[count]\r\n");
        str.Append("count=\r\n");
        str.Append("[user]\r\n");
        //StreamWriter sw = default(StreamWriter);
        //sw = File.CreateText(ls_INIFile);
        //sw.WriteLine(str.ToString());
        //sw.Close();
        File.WriteAllText(as_INIFile, str.ToString(), Encoding.Unicode);
        File.SetAttributes(as_INIFile, FileAttributes.Hidden);
      }
      CheckForIllegalCrossThreadCalls = false;
      InitializeComponent();
      Icon = Resource1.ico;
      lkl_num.Text = INIFile.ContentValue("total", "total", as_INIFile);
      lkl_num_c.Text = INIFile.ContentValue("count", "count", as_INIFile);
      pictureBox1.Visible = true;
      var sr = new StreamReader(as_INIFile, Encoding.Unicode);
      String line;
      int li_count = 0;
      adt_user.Columns.Clear();
      adt_user.Columns.Add("username", Type.GetType("System.String"));
      adt_user.Columns.Add("openid", Type.GetType("System.String"));
      while ((line = sr.ReadLine()) != null)
      {
        li_count++;
        if (li_count > 6)
        {
          line = SysVisitor.Current.GetFormatStr(line);
          DataRow newRow;
          newRow = adt_user.NewRow();
          newRow["username"] = line.Substring(0, line.LastIndexOf('='));
          newRow["openid"] = line.Substring(line.LastIndexOf('=') + 1);
          adt_user.Rows.Add(newRow);
        }
      }
      sr.Close();
      dataGridView1.AutoGenerateColumns = false;
      dataGridView1.DataSource = adt_user;
      //dataGridView1.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.DisplayedCells;
      lbl_count.Text = "共" + (li_count - 6) + "行";
      pictureBox1.Visible = false;
    }

    private void btn_GetUser_Click(object sender, EventArgs e)
    {
      if (MessageBox.Show(@"拉取用户信息的速度取决于你的关注数与网络速度,
可能需要几分钟甚至更长时间。
使用此功能将消耗大量用户管理接口配额。
要继续此操作吗?",
        "提示:", MessageBoxButtons.YesNo) == DialogResult.No)
      {
        return;
      }
      var thr = new Thread(Get_user_list);
      thr.Start();
    }

    private void Get_user_list()
    {
      File.Delete(as_INIFile);
      var str = new StringBuilder();
      str.Append(";内容由程序自动生成,请不要修改此文件内容\r\n");
      str.Append("[total]\r\n");
      str.Append("total=\r\n");
      str.Append("[count]\r\n");
      str.Append("count=\r\n");
      str.Append("[user]\r\n");
      File.WriteAllText(as_INIFile, str.ToString(), Encoding.Unicode);
      File.SetAttributes(as_INIFile, FileAttributes.Hidden);

      string ls_appid = INIFile.ContentValue("weixin", "Appid");
      string ls_secret = INIFile.ContentValue("weixin", "AppSecret");
      string access_token = "";
      string menu = "";
      if (ls_appid.Length != 18 || ls_secret.Length != 32)
      {
        MessageBox.Show("你的Appid或AppSecret不对,请检查后再操作");
        return;
      }
      access_token = SysVisitor.Current.Get_Access_token(ls_appid, ls_secret);
      if (access_token == "")
      {
        MessageBox.Show("Appid或AppSecret不对,请检查后再操作");
        return;
      }
      menu = SysVisitor.Current.GetPageInfo("https://api.weixin.qq.com/cgi-bin/user/get?access_token=" + access_token);
      if (menu.Substring(2, 7) == "errcode")
      {
        MessageBox.Show("拉取失败,返回消息:\r\n" + menu);
      }

      JObject json = JObject.Parse(menu);
      lkl_num.Text = json["total"].ToString();
      INIFile.SetINIString("total", "total", lkl_num.Text, as_INIFile);
      lkl_num_c.Text = json["count"].ToString();
      INIFile.SetINIString("count", "count", lkl_num_c.Text, as_INIFile);
      int li_count = int.Parse(json["count"].ToString());
      btn_GetUser.Enabled = false;
      pictureBox1.Visible = true;
      FileStream fs = null;
      Encoding encoder = Encoding.Unicode;
      for (int i = 0; i < li_count; i++)
      {
        string openid, username;
        openid = Get_UserName(json["data"]["openid"][i].ToString());
        username = json["data"]["openid"][i].ToString();
        //INIFile.SetINIString("user", openid, username, as_INIFile);
        byte[] bytes = encoder.GetBytes(openid + "=" + username + " \r\n");
        fs = File.OpenWrite(as_INIFile);
        //设定书写的開始位置为文件的末尾
        fs.Position = fs.Length;
        //将待写入内容追加到文件末尾
        fs.Write(bytes, 0, bytes.Length);
        fs.Close();
        lab_nums.Text = "已拉取" + i + "个,还剩" + (li_count - i) + "个,请耐心等待";
      }
      lab_nums.Text = "";
      //BindUser();
      btn_GetUser.Enabled = true;
      pictureBox1.Visible = false;
      MessageBox.Show("已全部拉取完毕,请重新打开该窗口");
    }

    /// <summary>
    ///   获取用户信息详情,返回json
    /// </summary>
    ///<param name="as_openid">
    private string Get_User(string as_openid)
    {
      string ls_json = "";
      string access_token = "";
      access_token = SysVisitor.Current.Get_Access_token();
      ls_json =
        SysVisitor.Current.GetPageInfo("https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + access_token + "&openid=" + as_openid + "&lang=zh_CN");
      return ls_json;
    }

    /// <summary>
    ///   获取用户用户的昵称
    /// </summary>
    private string Get_UserName(string as_openid)
    {
      string ls_json = "";
      ls_json = Get_User(as_openid);
      string username = "";
      JObject json = JObject.Parse(ls_json);
      username = json["nickname"].ToString();
      username = SysVisitor.Current.GetFormatStr(username);
      return username;
    }

    private void btn_search_Click(object sender, EventArgs e)
    {
      string username = txt_search.Text.Trim();
      if (string.IsNullOrWhiteSpace(username))
      {
        return;
      }
      DataRow[] datarows = adt_user.Select("username like '%" + username + "%'");

      var ldt = new DataTable();
      ldt.Columns.Clear();
      ldt.Columns.Add("username", Type.GetType("System.String"));
      ldt.Columns.Add("openid", Type.GetType("System.String"));
      ldt = ToDataTable(datarows);
      try
      {
        lbl_count.Text = ldt.Rows.Count.ToString();
      }
      catch
      {
      }
      dataGridView1.AutoGenerateColumns = false;
      dataGridView1.DataSource = ldt;
    }

    public DataTable ToDataTable(DataRow[] rows)
    {
      if (rows == null || rows.Length == 0) return null;
      DataTable tmp = rows[0].Table.Clone(); // 复制DataRow的表结构
      foreach (DataRow row in rows)
        tmp.Rows.Add(row.ItemArray); // 将DataRow添加到DataTable中
      return tmp;
    }

    private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
    {
      try
      {
        SysVisitor.Current.Wx_openid =
          dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[1].Value.ToString();
        SysVisitor.Current.Wx_username =
          dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[0].Value.ToString();
        //MessageBox.Show(str);
        grb_chat.Enabled = true;
        grb_chat.Text = SysVisitor.Current.Wx_username;
      }
      catch
      {

      }
      webBrowser_msg.DocumentText = "";
      string url = string.Format("https://api.weixin.qq.com/cgi-bin/customservice/getrecord?access_token={0}",
        SysVisitor.Current.Get_Access_token());
      string ls_text = @"{";
      ls_text += "\"starttime\" : " + DateTime.Now.AddDays(-3).Ticks + ",";
      ls_text += "\"endtime\" : " + DateTime.Now.Ticks + ",";
      ls_text += "\"openid\" : \"" + SysVisitor.Current.Wx_openid + "\",";
      ls_text += "\"pagesize\" : 1000,";
      ls_text += "\"pageindex\" : 1,";
      ls_text += "}";
      string ls_history = SysVisitor.Current.PostPage(url, ls_text);
      webBrowser_msg.DocumentText = ls_history;
    }

    private void btn_send_Click(object sender, EventArgs e)
    {
      string ls_msg = richTextBox_msg.Text;
      string ls_text = @"{";
      ls_text += "\"touser\":\"" + SysVisitor.Current.Wx_openid + "\",";
      ls_text += "\"msgtype\":\"text\",";
      ls_text += "\"text\":";
      ls_text += "{";
      ls_text += "\"content\":\"" + ls_msg + "\"";
      ls_text += "}";
      ls_text += "}";
      string url = string.Format("https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={0}",
        SysVisitor.Current.Get_Access_token());
      string ls_isright = SysVisitor.Current.PostPage(url, ls_text);

      webBrowser_msg.DocumentText += "
" + ls_isright + "

"; } private void btn_addkf_Click(object sender, EventArgs e) { string url = string.Format("https://api.weixin.qq.com/customservice/kfaccount/add?access_token={0}", SysVisitor.Current.Get_Access_token()); //客服账号 设置 xxx@你的公众号 这样的格式才是正确的哟。 string ls_text = "{"; ls_text += "\"kf_account\":test2@gz-sisosoft,"; ls_text += "\"nickname\":\"客服2\","; ls_text += "\"password\":\"12345\","; ls_text += "}"; string ls_kf = @"{ 'kf_account' : 'test1@gz-sisosoft', 'nickname' : '客服1', 'password' : '123456', }"; string ls_isok = SysVisitor.Current.PostPage(url, ls_text); MessageBox.Show(ls_isok); } private void Kf_account_Load(object sender, EventArgs e) { } }

SysVisitor.cs代码:

class SysVisitor
 {
   private static SysVisitor visit = null;
   public static SysVisitor Current
   {
     get
     {
       if (visit == null)
         visit = new SysVisitor();

       return visit;
     }
   }
   /// <summary>
   /// 获取access_token
   /// </summary>
   ///<param name="appid">appid
   ///<param name="secret">appsecret
   /// <returns></returns>
   public string Get_Access_token(string appid, string appsecret)
   {
     string secondappid = INIFile.ContentValue("weixin", "secondappid");
     if (appid.ToLower() == secondappid.ToLower())
     {
       string ls_time = INIFile.ContentValue("weixin", "gettime");
       Decimal ldt;
       try
       {
         ldt = Convert.ToDecimal(ls_time);
         if (Convert.ToDecimal(DateTime.Now.ToString("yyyyMMddHHmmss")) - ldt < 7100)//每两个小时刷新一次
         {
           return INIFile.ContentValue("weixin", "access_token");
         }
       }
       catch
       { }
     }
     string ls_appid = appid.Replace(" ", "");
     string ls_secret = appsecret.Replace(" ", "");
     string access_token = "";
     string url = string.Format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}", ls_appid, ls_secret);
     string json_access_token = GetPageInfo(url);
     //DataTable dt = Json.JsonToDataTable(json_access_token);
     DataTable dt = JsonHelper.JsonToDataTable(json_access_token);
     try
     {
       access_token = dt.Rows[0]["access_token"].ToString();
     }
     catch
     {
       return "";
     }
     INIFile.SetINIString("weixin", "gettime", DateTime.Now.ToString("yyyyMMddHHmmss"));
     INIFile.SetINIString("weixin", "access_token", access_token);
     INIFile.SetINIString("weixin", "secondappid", ls_appid);

     return access_token;
   }

   /// <summary>
   /// 获取access_token
   /// </summary>
   public string Get_Access_token()
   {
     string ls_appid = INIFile.ContentValue("weixin", "Appid");
     string ls_secret = INIFile.ContentValue("weixin", "AppSecret");
     return Get_Access_token(ls_appid, ls_secret);
   }

   /// <summary>
   /// Get方法请求url并接收返回消息
   /// </summary>
   ///<param name="strUrl">Url地址
   /// <returns></returns>
   public string GetPageInfo(string url)
   {
     HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
     HttpWebResponse response = (HttpWebResponse)request.GetResponse();

     string ret = string.Empty;
     Stream s;
     string StrDate = "";
     string strValue = "";

     if (response.StatusCode == HttpStatusCode.OK)
     {
       s = response.GetResponseStream();
       ////在这儿处理返回的文本
       StreamReader Reader = new StreamReader(s, Encoding.UTF8);

       while ((StrDate = Reader.ReadLine()) != null)
       {
         strValue += StrDate + "\r\n";
       }
       //strValue = Reader.ReadToEnd();
     }
     return strValue;
   }

   /// <summary>
   /// Post方法
   /// </summary>
   ///<param name="posturl">URL
   ///<param name="postData">Post数据
   /// <returns></returns>
   public string PostPage(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;
       return string.Empty;
     }
   }

   /// <summary>
   /// 格式化字符串
   /// </summary>
   ///<param name="str">
   /// <returns></returns>
   public string GetFormatStr(string str)
   {
     if ("" == str)
       return "";
     else
     {
       str = str.Trim();
       str = str.Replace("'", "'");
       str = str.Replace("〈", "<");
       str = str.Replace("〉", ">");
       str = str.Replace(",", ",");
       return str;
     }
   }
   string ls_username = "";
   /// <summary>
   /// 用户名
   /// </summary>
   public string Wx_username
   {
     get
     {
       return ls_username;
     }
     set
     {
       ls_username = value;
     }
   }
   string ls_openid = "";
   /// <summary>
   /// Openid
   /// </summary>
   public string Wx_openid
   {
     get
     {
       return ls_openid;
     }
     set
     {
       ls_openid = value;
     }
   }
 }

INIFile.cs代码:

class INIFile
  {
    ///// <summary>
    ///// 设置INI文件参数
    ///// </summary>
    /////<param name="section">INI文件中的段落
    /////<param name="key">INI文件中的关键字
    /////<param name="val">INI文件中关键字的数值
    /////<param name="filePath">INI文件的完整的路径和名称
    ///// <returns></returns>
    //[DllImport("kernel32")]
    //private static extern long WritePrivateProfileString(
    //  string section, string key, string val, string filePath);

    ///// <summary>
    ///// 获取INI文件参数
    ///// </summary>
    /////<param name="section">INI文件中的段落名称
    /////<param name="key">INI文件中的关键字
    /////<param name="def">无法读取时候时候的缺省数值
    /////<param name="retVal">读取数值
    /////<param name="size">数值的大小
    /////<param name="filePath">INI文件的完整路径和名称
    //[DllImport("kernel32")]
    //private static extern int GetPrivateProfileString(
    //  string section, string key, string def, StringBuilder retVal, int size, string filePath);

    //static string gs_FileName = System.AppDomain.CurrentDomain.BaseDirectory + "Config.ini";

    ///// <summary>
    ///// 获取INI文件参数
    ///// </summary>
    /////<param name="as_section">INI文件中的段落名称
    /////<param name="as_key">INI文件中的关键字
    /////<param name="as_FileName">INI文件的完整路径和名称
    //public static string GetINIString(string as_section, string as_key, string as_FileName)
    //{
    //  StringBuilder temp = new StringBuilder(255);
    //  int i = GetPrivateProfileString(as_section, as_key, "", temp, 255, as_FileName);
    //  return temp.ToString();
    //}
    ///// <summary>
    ///// 获取INI文件参数
    ///// </summary>
    /////<param name="as_section">INI文件中的段落名称
    /////<param name="as_key">INI文件中的关键字
    /////<param name="as_FileName">INI文件的完整路径和名称
    //public static string GetINIString(string as_section, string as_key)
    //{
    //  return GetINIString(as_section, as_key, gs_FileName);
    //}

    ///// <summary>
    ///// 设置INI文件参数
    ///// </summary>
    /////<param name="as_section">INI文件中的段落
    /////<param name="as_key">INI文件中的关键字
    /////<param name="as_Value">INI文件中关键字的数值
    /////<param name="as_FileName">INI文件的完整路径和名称
    //public static long SetINIString(string as_section, string as_key, string as_Value, string as_FileName)
    //{
    //  return WritePrivateProfileString(as_section, as_key, as_Value, as_FileName);
    //}
    ///// <summary>
    ///// 设置INI文件参数
    ///// </summary>
    /////<param name="as_section">INI文件中的段落
    /////<param name="as_key">INI文件中的关键字
    /////<param name="as_Value">INI文件中关键字的数值
    //public static long SetINIString(string as_section, string as_key, string as_Value)
    //{
    //  return SetINIString(as_section, as_key, as_Value, gs_FileName);
    //}
    /// <summary>
    /// 写入INI文件
    /// </summary>
    ///<param name="section">节点名称[如[TypeName]]
    ///<param name="key">键
    ///<param name="val">值
    ///<param name="filepath">文件路径
    /// <returns></returns>
    [DllImport("kernel32")]
    public static extern long WritePrivateProfileString(string section, string key, string val, string filepath);
    [DllImport("kernel32.dll")]
    public extern static int GetPrivateProfileSectionNamesA(byte[] buffer, int iLen, string fileName);
    /// <summary>
    /// 写入INI文件(section:节点名称 key:键 val:值)
    /// </summary>
    ///<param name="section">节点名称
    ///<param name="key">键
    ///<param name="val">值
    /// <returns></returns>
    public static long SetINIString(string section, string key, string val, string as_FilePath = "")
    {
      if (as_FilePath == "")
      {
        return (WritePrivateProfileString(section, key, val, strFilePath));
      }
      else
      {
        return (WritePrivateProfileString(section, key, val, as_FilePath));
      }
    }
    /// <summary>
    /// 读取INI文件
    /// </summary>
    ///<param name="section">节点名称
    ///<param name="key">键
    ///<param name="def">值
    ///<param name="retval">stringbulider对象
    ///<param name="size">字节大小
    ///<param name="filePath">文件路径
    /// <returns></returns>
    [DllImport("kernel32")]
    public static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retval, int size, string filePath);
    public static string strFilePath = Application.StartupPath + "\\Config.ini";//获取INI文件默认路径
    public static string strSec = "";

    //INI文件名

    /// <summary>
    /// 读取INI文件中的内容方法 (Section 节点名称;key 键)
    /// </summary>
    ///<param name="Section">节点名称
    ///<param name="key">键
    /// <returns></returns>
    public static string ContentValue(string Section, string key, string as_FilePath = "")
    {

      StringBuilder temp = new StringBuilder(1024);
      if (as_FilePath == "")
      {
        GetPrivateProfileString(Section, key, "", temp, 1024, strFilePath);
      }
      else
      {
        GetPrivateProfileString(Section, key, "", temp, 1024, as_FilePath);
      }
      return temp.ToString();
    }
    /// <summary>
    /// 获取指定小节所有项名和值的一个列表
    /// </summary>
    ///<param name="section">节 段,欲获取的小节。注意这个字串不区分大小写
    ///<param name="buffer">缓冲区 返回的是一个二进制的串,字符串之间是用"\0"分隔的
    ///<param name="nSize">缓冲区的大小
    ///<param name="filePath">初始化文件的名字。如没有指定完整路径名,windows就在Windows目录中查找文件
    /// <returns></returns>
    [DllImport("kernel32")]
    public static extern int GetPrivateProfileSection(string section, byte[] buffer, int nSize, string filePath);
    /// <summary>
    /// 获取指定段section下的所有键值对 返回集合的每一个键形如"key=value"
    /// </summary>
    ///<param name="section">指定的段落
    ///<param name="filePath">ini文件的绝对路径
    /// <returns></returns>
    public static List<string> ReadKeyValues(string section, string as_FilePath = "")
    {
      byte[] buffer = new byte[32767];
      List<string> list = new List<string>();
      int length = 0;
      if (as_FilePath == "")
      {
        length = GetPrivateProfileSection(section, buffer, buffer.GetUpperBound(0), strFilePath);
      }
      else
      {
        length = GetPrivateProfileSection(section, buffer, buffer.GetUpperBound(0), as_FilePath);
      }
      string temp;
      int postion = 0;
      for (int i = 0; i < length; i++)
      {
        if (buffer[i] == 0x00) //以'\0'来作为分隔
        {
          temp = System.Text.ASCIIEncoding.Default.GetString(buffer, postion, i - postion).Trim();
          postion = i + 1;
          if (temp.Length > 0)
          {
            list.Add(temp);
          }
        }
      }
      return list;
    }
    /// <summary>
    /// 删除指定的key
    /// </summary>
    ///<param name="section">要写入的段落名
    ///<param name="key">要删除的键
    ///<param name="fileName">INI文件的完整路径和文件名
    public static void DelKey(string section, string key, string as_FilePath = "")
    {
      if (as_FilePath == "")
      {
        WritePrivateProfileString(section, key, null, strFilePath);
      }
      else
      {
        WritePrivateProfileString(section, key, null, as_FilePath);
      }
    }
    /// <summary>
    /// 返回该配置文件中所有Section名称的集合
    /// </summary>
    public static ArrayList ReadSections()
    {
      byte[] buffer = new byte[65535];
      int rel = GetPrivateProfileSectionNamesA(buffer, buffer.GetUpperBound(0), strFilePath);
      int iCnt, iPos;
      ArrayList arrayList = new ArrayList();
      string tmp;
      if (rel > 0)
      {
        iCnt = 0; iPos = 0;
        for (iCnt = 0; iCnt < rel; iCnt++)
        {
          if (buffer[iCnt] == 0x00)
          {
            tmp = System.Text.ASCIIEncoding.UTF8.GetString(buffer, iPos, iCnt - iPos).Trim();
            iPos = iCnt + 1;
            if (tmp != "")
              arrayList.Add(tmp);
          }
        }
      }
      return arrayList;
    }
  }</string></string></string>

运行结果:

这里写图片描述

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

(0)

相关推荐

  • 微信公众号开发 自定义菜单跳转页面并获取用户信息实例详解

    微信公众号开发 自定义菜单 请先读完本文再进行配置开发 请先前往微信平台开发者文档阅读"网页授权获取用户基本信息"的接口说明 在微信公众账号开发中,往往有定义一个菜单,然后用户点击该菜单就进入用户个人中心的功能,通常应用于各个公众账号中的会员服务. 如何在微信自定义菜单中将用户导航到个人中心页面呢? 首选需要通过用户点击获取用户openid,而通过用户的点击跳转获取用户openid就必须在菜单中动态绑定用户的openid,或者在菜单的跳转URL中填写微信提供的链接,官方给了两个链接类型

  • php微信公众号js-sdk开发应用

    测试js的接口功能,我用的是BAE服务器不是SAE服务器.SAE服务器不能写入文件,测试会出问题. 什么叫js-sdk,我先演示js-sdk接口的具体作用. 我在微信随便打开一片推送文章如下图: 点开第一篇文章 上面就是我们的连接文章,如果我们把这篇文章发送给朋友,显示效果如下图: 分享到朋友圈我们再来看看效果: 为什么同样是文章连接,在公众号.发送给朋友.发送到朋友圈显示的界面效果不一样.公众号的显示效果是因为微信公众帐号在推送的时候调用了微信的消息接口,而后两者是因为页面调用js-sdk相关

  • 微信公众号 提示:Unauthorized API function 问题解决方法

    微信公众号 Unauthorized API function 调用api的返回结果如下: 200 OK Connection: keep-alive Date: Wed, 15 Oct 2014 09:00:17 GMT Server: nginx/1.4.4 Content-Type: application/json; encoding=utf-8 Content-Length: 45 { "errcode": 48001, "errmsg": "a

  • 微信公众号支付H5调用支付解析

    最近项目需要微信支付,然后看了下微信公众号支付,虽然不难,但是细节还是需要注意的,用了大半天时间写了个demo,并且完整的测试了一下支付流程,下面分享一下微信公众号支付的经验. 一.配置公众号微信支付   需要我们配置微信公众号支付地址和测试白名单. 比如:支付JS页面的地址为 http://www.xxx.com/shop/pay/             那此处配置www.xxx.com/shop/pay/ 二.开发流程 借用微信公众号支付api(地址 http://pay.weixin.q

  • java微信公众号开发案例

    微信公众号开发一般是针对企业和组织的,个人一般只能申请订阅号,并且调用的接口有限,下面我们就来简单的描述下接入公众号的步骤: 1.首先你需要一个邮箱在微信公众号平台进行注册:      注册的方式有订阅号.公众号.小程序和企业号,个人我们这里只能选择订阅号 2.注册完后,我们登录到公众号平台--->开发--->基本配置,这里需要填写URL和token,URL就是我们使用服务器的接口: 3.Java Web服务器程序编译好且在服务器上部署可以运行的话,可在微信公众号进行在线接口调试: 1).选择

  • 微信公众号开发 实现点击返回按钮就返回到聊天界面

    话不多说,请看代码 pushHistory(); function pushHistory() { var state = { title: "title", url: "#" }; window.history.pushState(state, "title", "#"); } if (typeof window.addEventListener != "undefined") { window.addE

  • 微信公众号 摇一摇周边功能开发

    ①申请开通摇一摇功能 申请开通摇一摇周边功能.成功提交申请请求后,工作人员会在三个工作日内完成审核.若审核不通过,可以重新提交申请请求.若是审核中,请耐心等待工作人员审核,在审核中状态不能再提交申请请求. 接口代码如下: http请求方式: POST(请使用https协议)https://api.weixin.qq.com/shakearound/account/register?access_token=ACCESS_TOKENPOST数据格式:json POST数据例子: { "name&q

  • php微信公众号开发模式详解

    学习步骤:分四章来讲述这部分内容,下面是每章的大致内容. 1.了解开发模式与编辑模式,开发前的一些准备. 2.开发模式用户.微信服务器.个人服务器是如何交互的.什么是接口. 3.各种接口功能的调用与实现. 4.js-SDK的调用 微信公众号开发两种模式:编辑模式和开发模式.编辑模式比较简单,你不需要操作任何的代码,只需要借助微信提供的功能来管理自己的微信公众号.这种方式开发的页面比较简单,主要用来实现文章的推送等功能.开发者模式则能通过自己的后台服务器与微信关注用户实现更多的交互作用,调用微信的

  • 微信公众号-获取用户信息(网页授权获取)实现步骤

    根据微信公众号开发官方文档: 获取用户信息步骤如下: 1 第一步:用户同意授权,获取code 2 第二步:通过code换取网页授权access_token 3 第三步:刷新access_token(如果需要) 4 第四步:拉取用户信息(需scope为 snsapi_userinfo) 1 获取code 在确保微信公众账号拥有授权作用域(scope参数)的权限的前提下(服务号获得高级接口后,默认拥有scope参数中的snsapi_base和snsapi_userinfo),引导关注者打开如下页面:

  • .NET微信公众号获取OpenID和用户信息

    本文实例为大家分享了微信公众平台实现获取用户OpenID的方法,供大家参考,具体内容如下 Index.aspx.cs代码: public partial class Index : System.Web.UI.Page { //用户id public string openid = ""; //公众号信息部分 public string appid = ConfigurationManager.AppSettings["AppId"]; public string

随机推荐