ホームページ WeChat アプレット WeChatの開発 C# は WeChat パブリック アカウントとサブスクリプション アカウント インターフェイスのサンプル コードを開発します

C# は WeChat パブリック アカウントとサブスクリプション アカウント インターフェイスのサンプル コードを開発します

Mar 19, 2017 pm 06:02 PM
c# WeChatの公開アカウント

この記事では、主に C#WeChat パブリック アカウントとサブスクリプション アカウントインターフェイスの開発サンプル コードを紹介し、サンプルの形で WeChat インターフェイスの C# の呼び出しと処理スキルを簡単に分析します。必要な友人はそれを参照できます。

この記事では、C# WeChat 公式アカウントおよびサブスクリプション アカウント インターフェイス開発用に開発されたサンプル コードの例について説明します。参考のために皆さんと共有してください。詳細は次のとおりです:

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")
    {
      //微信服务器对接口消息
      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测试(开发者认证)
      WxAuth();
    }
  }
  /// <summary>
  /// 处理信息并应答
  /// </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# は WeChat パブリック アカウントとサブスクリプション アカウント インターフェイスのサンプル コードを開発しますの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

C# を使用した Active Directory C# を使用した Active Directory Sep 03, 2024 pm 03:33 PM

C# を使用した Active Directory のガイド。ここでは、Active Directory の概要と、C# での動作方法について、構文と例とともに説明します。

C# の乱数ジェネレーター C# の乱数ジェネレーター Sep 03, 2024 pm 03:34 PM

C# の乱数ジェネレーターのガイド。ここでは、乱数ジェネレーターの仕組み、擬似乱数の概念、安全な数値について説明します。

C# のアクセス修飾子 C# のアクセス修飾子 Sep 03, 2024 pm 03:24 PM

C# のアクセス修飾子のガイド。 C# のアクセス修飾子の種類について、例と出力とともに説明しました。

C# データ グリッド ビュー C# データ グリッド ビュー Sep 03, 2024 pm 03:32 PM

C# データ グリッド ビューのガイド。ここでは、SQL データベースまたは Excel ファイルからデータ グリッド ビューをロードおよびエクスポートする方法の例について説明します。

C# シリアル化 C# シリアル化 Sep 03, 2024 pm 03:30 PM

C# シリアル化のガイド。ここでは、C# シリアル化オブジェクトの導入、手順、作業、例についてそれぞれ説明します。

C# のパターン C# のパターン Sep 03, 2024 pm 03:33 PM

C# のパターンのガイド。ここでは、C# のパターンの概要と上位 3 種類について、その例とコード実装とともに説明します。

C# の素数 C# の素数 Sep 03, 2024 pm 03:35 PM

C# の素数ガイド。ここでは、C# における素数の導入と例を、コードの実装とともに説明します。

C# の階乗 C# の階乗 Sep 03, 2024 pm 03:34 PM

C# の Factorial のガイド。ここでは、C# での階乗の概要について、さまざまな例とコード実装とともに説明します。

See all articles