search
HomeWeChat AppletWeChat Development.Net development WeChat public platform certification 'become a developer' example detailed explanation

This article mainly provides a detailed analysis of the "Become a Developer" .Net code for the certification of WeChat public platform development. Interested friends can refer to

.Net to realize the development of WeChat public service platform. Certification, certification to become a developer, the specific content is as follows

These codes will be used once when starting the certification, and will not be used in the future:

const string Token = "XXXXX";//你的token 
protected void Page_Load(object sender, EventArgs e) 
{ 
  string postStr = ""; 
  if (Request.HttpMethod.ToLower() == "post") 
  { 
    System.IO.Stream s = System.Web.HttpContext.Current.Request.InputStream; 
    byte[] b = new byte[s.Length]; 
    s.Read(b, 0, (int)s.Length); 
    postStr = System.Text.Encoding.UTF8.GetString(b); 
    if (!string.IsNullOrEmpty(postStr)) 
    { 
      //ResponseMsg(postStr); 
      Response.Write(ResponseMsg(postStr)); 
      Response.End(); 
    } 
   //WriteLog("postStr:" + postStr); 
  } 
  else 
  { 
    Valid(); 
  } 
}    
 
/// <summary> 
/// 验证微信签名 
/// </summary> 
/// * 将token、timestamp、nonce三个参数进行字典序排序 
/// * 将三个参数字符串拼接成一个字符串进行sha1加密 
/// * 开发者获得加密后的字符串可与signature对比,标识该请求来源于微信。 
/// <returns></returns> 
private bool CheckSignature() 
{ 
  string signature = Request.QueryString["signature"].ToString(); 
  string timestamp = Request.QueryString["timestamp"].ToString(); 
  string nonce = Request.QueryString["nonce"].ToString(); 
  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; 
  } 
} 
.private void Valid() 
{ 
  string echoStr = Request.QueryString["echoStr"].ToString(); 
  if (CheckSignature()) 
  { 
    if (!string.IsNullOrEmpty(echoStr)) 
    { 
      Response.Write(echoStr); 
      Response.End(); 
    } 
  } 
}    
 
/// <summary> 
/// 写日志(用于跟踪) 
/// </summary> 
private void WriteLog(string strMemo) 
{ 
  string filename = Server.MapPath("/logs/log.txt"); 
  if (!Directory.Exists(Server.MapPath("//logs//"))) 
    Directory.CreateDirectory("//logs//"); 
  StreamWriter sr = null; 
  try 
  { 
    if (!File.Exists(filename)) 
    { 
      sr = File.CreateText(filename); 
    } 
    else 
    { 
      sr = File.AppendText(filename); 
    } 
    sr.WriteLine(strMemo); 
  } 
  catch 
  { 
 
  } 
  finally 
  { 
    if (sr != null) 
      sr.Close(); 
  } 
}

The above is the detailed content of .Net development WeChat public platform certification 'become a developer' example detailed explanation. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools