html52.com
我爱小程序-开发者交流社区

使用微信扫描自定义二维码会调用后台接口3次,导致会推送3次消息,其实只有第一次有效,如何解决呢?

1、自定义了一个二维码,里面内容为:P-1-A15|510300000400P-1-A15|5103000004002、当使用手机微信扫描此二维码后,会调用后台入口程序3次,入口程序为:

2、当使用手机微信扫描此二维码后,会调用后台入口程序3次,入口程序为:

public ActionResult Index(WeChatRequestModel model)

        {

            FileLog.Debug("【Index】进入公众号Index,参数值:【signature:" + model.signature + "】,【nonce:" + model.nonce + "】,【timestamp:" + model.timestamp + "】,【echostr:" + model.echostr + "】");

            if (Request.HttpMethod.ToLower().Equals("get"))

            {

                string echoStr = model.echostr;

                ////通过验证

                if (CheckSignature(model))

                {

                    if (!string.IsNullOrEmpty(echoStr))

                    {

                        //将随机生成的 echostr 参数 原样输出

                        Response.Write(echoStr);

                        //截止输出流

                        Response.End();

                    }

                }

            }

            else

            {

                if (CheckSignature(model))

                {

                    //处理发送过来的消息并将消息返回

                    Stream requestStream = System.Web.HttpContext.Current.Request.InputStream;

                    //#region 返回空字符串,防止后面处理程序时间太长

                    Response.Write("");

                    //Response.End();

                    //Response.Close();

                    //#endregion

                    //处理程序开始,后面的消息采用接口推送到客户端

                    ReceiveXml(requestStream);

                    Response.End();

                    Response.Close();

                }

            }

            return View();

        }

3、日志结果记录自动调用了3次,其实我只扫了一次:

2021-09-17 10:23:38,533 13494 [30] CGSWeixin.Controllers.VehicleRegController :0 - 【Index】进入公众号Index,参数值:【signature:b4b2f83cc16fc75a6eacc487e9305ef8a6121618】,【nonce:2085640502】,【timestamp:1631845418】,【echostr:】

2021-09-17 10:23:39,578 14539 [55] CGSWeixin.Controllers.VehicleRegController :0 - 【Index】进入公众号Index,参数值:【signature:b4b2f83cc16fc75a6eacc487e9305ef8a6121618】,【nonce:2085640502】,【timestamp:1631845418】,【echostr:】

2021-09-17 10:23:40,405 15366 [53] CGSWeixin.Controllers.VehicleRegController :0 - 【Index】进入公众号Index,参数值:【signature:b4b2f83cc16fc75a6eacc487e9305ef8a6121618】,【nonce:2085640502】,【timestamp:1631845418】,【echostr:】

4、表现出来的效果:

  其实只需要第一次,只有第一次是正确的,不明白为啥会再进去执行一遍 其实只需要第一次,只有第一次是正确的,不明白为啥会再进去执行一遍

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

真正的个人免签约支付接口

云免签H5支付