changwen313 2017-06-04 11:55 采纳率: 100%
浏览 1660
已结题

C# 调用微信现金红包接口类网页没有任何反馈是什么意思?有没有大神给指导一下。

   //请求api 带证书的方法
    /// </summary>
    /// <param name="URL"></param>
    /// <param name="strPostdata"></param>
    /// <param name="strEncoding"></param>
    /// <returns></returns>

    public bool CheckValidationResult(
        Object sender,
        X509Certificate certificate,
        X509Chain chain,
        SslPolicyErrors sslPolicyErrors
    )
    {
        //   Always   accept   
        return true;
    }


    public   string OpenReadWithHttps(string URL, string strPostdata, string strEncoding)
    {
        try
        {
            Encoding encoding = Encoding.UTF8;

            string cert = @"C:\zhengshu\apiclient_cert.p12";
            string password = "xxxxxxxxxx";//这里是填写的是 微信支付商户号

            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
            X509Certificate cer = new X509Certificate(cert, password);
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
            request.ClientCertificates.Add(cer);


            request.Method = "post";

            request.Accept = "text/html, application/xhtml+xml, */*";

            request.ContentType = "application/x-www-form-urlencoded";


            byte[] buffer = encoding.GetBytes(strPostdata);

            request.ContentLength = buffer.Length;

            request.GetRequestStream().Write(buffer, 0, buffer.Length);

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            using (StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.GetEncoding(strEncoding)))
            {
                return reader.ReadToEnd();
            }
        }
        catch (Exception e)
        {

            return "";
        }

    }

//调用OpenReadWithHttps方法  其中sendxml已经构造好了没有问题
 Class1 ojb = new Class1();
  ojb.OpenReadWithHttps(url, sendxml, "UTF-8");
现在就是网页没有认为反馈,按道理腾讯是不是应该回馈一个xml?我这里哪里又问题,请大神帮忙给看看。调用证书这块有没有问题,我将证书C:\zhengshu\apiclient_cert.p12放到这里目录里并安装了。
  • 写回答

5条回答 默认 最新

  • Go 旅城通票 2017-06-04 12:18
    关注

    没返回内容可能是执行到catch语句了,在catch中用IO将错误信息写入文件中看是否报错

      catch (Exception e)
            {
    File.WriteText("错误日志物理路径",e.Message,Encoding.UTF8);///
                return "";
            }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch