liuhongfeifa 2018-11-08 19:51 采纳率: 0%
浏览 540
已采纳

微信服务器二次修改的时候总是提示token验证失败

第一次验证是通过的,消息推送也非常好,最近换了服务器和域名,想变更过来,但每次修改总是提示token验证失败,改回原来的服务器和域名也不行了,查找了很多方法都不行,原直接傻傻,码代如下请各位大神赐教,在线等,非常着急
using System;
using System.Collections.Generic;
using System.Web;
using System.IO;
using System.Text;
using System.Net;

namespace fz_police.Web
{
///
/// Summary description for wx
///

public class wx : IHttpHandler
{
    public void ProcessRequest(HttpContext param_context)
    {
        //InterfaceTest();
        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);
            }
        }
    }

    /// <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);
    }

    //成为开发者url测试,返回echoStr
    public void InterfaceTest()
    {
        string token = "fzgonganweixin";
        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"];


        //HttpContext.Current.Response.Clear();
        if (!string.IsNullOrEmpty(echoString))
        {
            HttpContext.Current.Response.ContentType = "text/plain";
            HttpContext.Current.Response.Charset = "UTF-8";
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(echoString);
            HttpContext.Current.Response.End();
        }
    }



    public bool IsReusable
    {
        get
        {
            return false;
        }
    }


}

}

  • 写回答

2条回答 默认 最新

  • liuhongfeifa 2018-11-09 01:42
    关注

    我真晕,第一次验证通过后把它给注释了,您能否发一下完整代码我参考一下,

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵