Callback page value problem after successful WeChat payment in c# (netcore version problem)

Problem:
When using the callback page after successful WeChat payment in the WeChat official account, there is a problem when obtaining the callback parameters. Through the generated log file, it is found that the error is reported, and the parameters passed in (the callback page is a post request) are not obtained as expected.
And I searched a lot of information on the Internet, and found that there is no problem with what I wrote, but I just couldn't get the value. Later, I used Bing (search engine https://cn.bing.com/) to search and finally found the answer. I have to say that compared with Baidu's search results, Bing is indeed much stronger than Baidu in terms of professional knowledge (personal feeling ), personally recommend students who need to search for professional problems can use it

Closer to home:
because I am using the latest version of VS net5.0, the problem of getting parameters on the payment callback page I encountered is actually because the code needs to be added after netcore 3.0:

 #region 
        //注意:如果用以下读取流的方法,.net core 3.0 以后一定要加下边那段
        //.net core 3.0以后需加下边这段,否则Stream会报错
        var syncIOFeature = context.Features.Get<IHttpBodyControlFeature>();
        if (syncIOFeature != null)
        {
    
    
            syncIOFeature.AllowSynchronousIO = true;
        }
        #endregion

        //接收从微信后台POST过来的数据
        System.IO.Stream s = context.Request.Body;
        int count = 0;
        byte[] buffer = new byte[1024];
        StringBuilder builder = new StringBuilder();
        while ((count = s.Read(buffer, 0, 1024)) > 0)
        {
    
    
            builder.Append(Encoding.UTF8.GetString(buffer, 0, count));
        }
        s.Flush();
        s.Close();
        s.Dispose();
        _logger.LogWarning($"GetNotifyData Receive data from WeChat :{
      
      builder.ToString()}");

The above is just a piece of code for obtaining parameters.
Complete code reference: https://www.cnblogs.com/sylvia-/p/12773927.html

Guess you like

Origin blog.csdn.net/qq_37213281/article/details/119817907
Recommended