ASP.NET MVC4 微信公众平台开发测试一: 验证

2019-03-02 01:01|来源: 网路

背景,想做一个微信公众号的自动回复系统,于是想动手写一下。记录这些,是一边写程序一边写在这里,也是记录一下自己的思路。

微信公众平台开发时,需要进行接口配置,此时需要验证信息,填写信息完毕,会按进行验证。

因开发尚处测试阶段,使用微信的沙箱测试号进行测试。

 

 服务器端,建立了一个WxController,直接将Index的输出改为string,然后按照API说明,代码很简单。

        [HttpGet]
        public string Index(string signature, string timestamp, string nonce, string echoStr)
        {
            string token = "e222318d42294edc8d5b5cf564c017ac";
            string strTemp = token + timestamp + nonce;
            string strSha = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(strTemp, "SHA1");
            if (strSha == signature)
                return echoStr;
            return "";
        }

一步步来,以上代码仅为实现验证,所以,没有使用View页面,直接用字符串返回的方式,发布上传服务器,人为构造几个函数,测试一下程序运行是否正常。

然后进入微信公众平台,配置验证URL。

提交,验证通过 ,界面就改变了。

到这一步,验证的工作就完成了。监控了一下获取的信息,如下:

这时微信验证时产生的数据,此后每次公众平台向我们的服务器发送消息,都要先在这个网址进行验证。

 


转自:http://www.cnblogs.com/Lasko/p/3887140

相关问答

更多
  • 看下柳峰的java微信开发博客吧http://blog.csdn.net/lyq8479/article/details/8944988 http://blog.csdn.net/lyq8479/article/category/1366622/2
  • 它与在应用程序池中设置的权限有关,它们必须正确才能让应用程序在IIS上本地运行。 Application Pools -> Right click Pool -> Advanced Settings -> Process Model -> Identity 我的身份被设置为用于特定应用程序的电子邮件 It was to do with the permissions set in the Application Pool, they must be correct in order for ...
  • 我想这可能会对你有所帮助。 http://pluralsight.com/training/Player?author=scott-allen&name=mvc4-building-m7-security&mode=live&clip=0&course=mvc4-building 您可以在这里获得有关asp.net mvc安全性的更多资源。 http://www.asp.net/mvc/overview/security I think this may help you. http://pluralsig ...
  • 这取决于您需要的定制: 1)尝试已经存在的东西。 只要您使用EF,您可以尝试https://efmembership.codeplex.com 。 没有尝试过,但从初看起来,看起来合理且可配置。 如果上一个不适合,nuget图库上还有其他MembershipProvider实现。 2)如果真的没有任何东西适合你的场景,从现有的nuget画廊,你自己实现会员提供者。 示例可能在这里: http : //blog.ianchivers.com/2012/03/entity-framework-custom-me ...
  • 表格确实会提交。 但是ModelState.IsValid应该返回false ,你应该返回到你的视图而不更新数据: public ActionResult SaveData(Model model) { if (ModelState.IsValid) { // update here // then redirect to view return RedirectToAction("View", new { id = model.ID }); ...
  • 只有两个:.NET 4.0和可选的MVC 4.如果在部署包中包含二进制文件,则可以避免安装MVC 4。 EF5是您的标准.NET 4.0,并且肯定您已经引用它,因此所有需要的二进制文件都将在部署包中 Only two: .NET 4.0 and optionally MVC 4. You can avoid installing MVC 4 if you include binaries in your deployment package. EF5 you standard .NET 4.0 and fo ...
  • 您可以在系统的核心中实现此功能,例如在数据存储区中包含一个字段,通过权限识别创建者和用户。 然后你可以实现自己的authorizeattribute; 公共类CustomAuthenticateAttribute:AuthorizeAttribute { protected override bool AuthorizeCore(HttpContextBase httpContext) { // your own business logic, for instance, check if the ...
  • 这个问题令人愤怒,因为我可以在调试时看到VS中我想要的数据集合。 我更新了测试夹具 - 可以执行模型数据上的断言。 基本上我做了以下事情: 将ActionResult强制转换为JsonResult 使用动态类型,从JsonResult获取返回Kendo.Mvc.UI.DataSourceResult的“数据”。 在使用动态类型之前,仅返回null。 (注意自我,了解有关动态类型的更多信息) 将step2的结果转换为要测试的数据类型。 控制器: public ActionResult EditRead ...
  • 你的问题的答案很简单。 您需要两个帐户控制器,以便调用MVC控制器的客户端(例如浏览器)和调用web api控制器的客户端(例如ajax请求,fiddler等)可以进行身份验证。 如果两个控制器都属于同一个域和应用程序,那么它们默认情况下会在后台使用相同的身份验证机制,即使您仍然可以覆盖此行为。 The answer to your question is rather simple. You need both account controllers so that clients calling the ...
  • 默认的ASP.NET MVC 4“Internet应用程序”项目模板附带一些默认的成员资格功能。 如果您搜索并更新下面的行,则会在您的数据库中创建成员资格表(如果它们尚不存在): WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true); 更多信息: http://aaron-hoffman.blogspot.com/2 ...