?C#微信公眾號與訂閱號接口開發(fā)示例分析-創(chuàng)新互聯(lián)

這篇文章主要介紹了C#微信公眾號與訂閱號接口開發(fā)示例分析,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

成都創(chuàng)新互聯(lián)專注于松江網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供松江營銷型網(wǎng)站建設(shè),松江網(wǎng)站制作、松江網(wǎng)頁設(shè)計、松江網(wǎng)站官網(wǎng)定制、小程序定制開發(fā)服務(wù),打造松江網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供松江網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。

C#微信公眾號與訂閱號接口開發(fā)示例代碼,具體如下:

using System;
using System.Web;
using System.IO;
using System.Text;
using System.Web.Security;
using weixin_api;
public class wxgz_api : IHttpHandler
{
  public void ProcessRequest(HttpContext context)
  {
    context.Response.ContentType = "text/plain";
    string postString = string.Empty;
    if (HttpContext.Current.Request.HttpMethod.ToUpper() == "POST")
    {
      //微信服務(wù)器對接口消息
      using (Stream stream = HttpContext.Current.Request.InputStream)
      {
        Byte[] postBytes = new Byte[stream.Length];
        stream.Read(postBytes, 0, (Int32)stream.Length);
        postString = Encoding.UTF8.GetString(postBytes);
        Handle(postString);
      }
    }
    else
    {
      //微信進行的Get測試(開發(fā)者認證)
      WxAuth();
    }
  }
  /// <summary>
  /// 處理信息并應(yīng)答
  /// </summary>
  private void Handle(string postStr)
  {
    messageHelp help = new messageHelp();
    string responseContent = help.ReturnMessage(postStr);
    HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
    HttpContext.Current.Response.Write(responseContent);
  }
  #region 微信驗證
  public void WxAuth()
  {
    string token = "xxxxxxxx";
    if (string.IsNullOrEmpty(token))
    {
      return;
    }
    string echoString = HttpContext.Current.Request.QueryString["echostr"];
    string signature = HttpContext.Current.Request.QueryString["signature"];
    string timestamp = HttpContext.Current.Request.QueryString["timestamp"];
    string nonce = HttpContext.Current.Request.QueryString["nonce"];
    if (CheckSignature(token, signature, timestamp, nonce))
    {
      if (!string.IsNullOrEmpty(echoString))
      {
        HttpContext.Current.Response.Write(echoString);
        HttpContext.Current.Response.End();
      }
    }
  }
  /// <summary>
  /// 驗證微信簽名
  /// </summary>
  public bool CheckSignature(string token, string signature, string timestamp, string nonce)
  {
    string[] ArrTmp = { token, timestamp, nonce };
    Array.Sort(ArrTmp);
    string tmpStr = string.Join("", ArrTmp);
    tmpStr = FormsAuthentication.HashPasswordForStoringInConfigFile(tmpStr, "SHA1");
    tmpStr = tmpStr.ToLower();
    if (tmpStr == signature)
    {
      return true;
    }
    else
    {
      return false;
    }
  }
  #endregion
  public bool IsReusable
  {
    get
    {
      return false;
    }
  }
}

感謝你能夠認真閱讀完這篇文章,希望小編分享的“C#微信公眾號與訂閱號接口開發(fā)示例分析”這篇文章對大家有幫助,同時也希望大家多多支持創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司,,關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,更多相關(guān)知識等著你來學習!

當前名稱:?C#微信公眾號與訂閱號接口開發(fā)示例分析-創(chuàng)新互聯(lián)
文章分享:http://bm7419.com/article34/dsccpe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機網(wǎng)站導航、網(wǎng)站營銷關(guān)鍵詞優(yōu)化、云服務(wù)器小程序開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作