日期:2014-05-16  浏览次数:20443 次

哪位做过微信公众账号开发呢,验证成为开发者怎么弄都过不去。

这个是网上的一个验证成为微信开发者的代码,我直接放到VS里,红色部分好像是微信的接口函数什么的,在这里上下文不存在。我没管他,直接保存了后上传到服务器上,接下来验证的时候总是请求URL超时。不知道跟这个错误有没有关系,就是那个ResponseMsg();

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.IO;

public partial class weixin : System.Web.UI.Page
{
    const string Token = "lingduruanjian";
    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 };