收藏
回答

C#建直播间parameter startTime or endTime is invalid?

C#.net代码如下:

return await Senparc.Weixin.MP.ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
{
	var urlFormat = string.Format("https://api.weixin.qq.com/wxaapi/broadcast/room/create?access_token={0}", accessToken.AsUrlData());
				
	var result = await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync(null, urlFormat, data, CommonJsonSendType.POST, timeOut: timeOut);

	return result;
				
}, accessTokenOrAppId);


这个创建直播间接口,不能用微信组件post过去吗???

当前时间是2020-08-13 13:03:00

直播开始时间 2020-08-13 15:00:00

直播结束时间 2020-08-13 16:00:00

调试情况(图片不清晰请放大看):

错误日志如下:

微信 POST 请求发生错误!错误代码:200002,说明:parameter startTime or endTime is invalid rid: 5f34c975-207cd6f4-0a61eec7

Senparc.Weixin.Exceptions.ErrorJsonResultException: 微信 POST 请求发生错误!错误代码:200002,说明:parameter startTime or endTime is invalid rid: 5f34c975-207cd6f4-0a61eec7

   在 Senparc.Weixin.CommonAPIs.CommonJsonSend.<>c.<.cctor>b__6_1(String apiUrl, String returnText)

   在 Senparc.CO2NET.HttpUtility.Post.d__5`1.MoveNext()

--- End of stack trace from previous location where exception was thrown ---


回答关注问题邀请回答
收藏

3 个回答

  • 落雨林
    落雨林
    2020-08-13

    有遇上同样问题的吗?我这里卡住很久了。。。 欢迎一起讨论


    ----------------------已解决------------------------------

    检查了微信封装的组件Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync,提交数据时默认Header中的ContentType是text/xml,需要自己另外封装接口 request.ContentType =“application/json; charset=UTF-8”

    上代码:


    2020-08-13
    有用 1
    回复 3
    • Jnn
      Jnn
      2020-10-08
      你好,我用你的代码测试了下,还是不成功,能帮我看看哪里不对吗
      public static string PostTest(string url, object data)
              {
                  Encoding encoding = Encoding.UTF8;
                  var reqJson = JsonConvert.SerializeObject(data,
                      new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, DateFormatString = "yyyy-MM-dd HH:mm:ss" });
                  byte[] buffer = encoding.GetBytes(reqJson);

                  HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                  request.Method = "Post";
                  request.ContentType = "application/json; charset=UTF-8";
                  request.ContentLength = buffer.Length;
                  request.Timeout = 60000;

                  HttpWebResponse response = null;
                  request.GetRequestStream().Write(buffer, 0, buffer.Length);
                  response = (HttpWebResponse) request.GetResponse();

                  using (StreamReader reader=new StreamReader(response.GetResponseStream(), encoding))
                  {
                      var reaponseString = reader.ReadToEnd();
                      response.Close();
                      return reaponseString;
                  }
              }
      2020-10-08
      回复
    • Jnn
      Jnn
      2020-10-08
      // 参数
                  DateTime dtNow = DateTime.Now;
                  int startTime = WXHelper.ConvertToTimeStamp(dtNow.AddHours(1));
                  int endTime = WXHelper.ConvertToTimeStamp(dtNow.AddHours(2));
                  var o = new
                  {
                      name = "测试直播房间1",
                      coverImg = "mIZ6J141w3OWw5sOBwG3NRM06YzG_hD7O4vsKVi85Y3vSvcKEy7C_i6Rd_Q8y4YD",
                      startTime = WXHelper.ConvertToTimeStamp(dtNow.AddMinutes(15)),
                      endTime = WXHelper.ConvertToTimeStamp(dtNow.AddHours(1)),
                      anchorName = "测试直播Name",
                      anchorWechat = "JnnJinn",
                      subAnchorWechat = "",
                      shareImg = "",
                      feedsImg = "",
                      isFeedsPublic = "1",
                      type = "1",
                      screenType = "1",
                      closeLike = "1",
                      closeGoods = "1",
                      closeComment = "1",
                      closeReplay = "1",
                      closeShare = "1",
                      closeKf = "1",
                  };
                  var token = Wechat.GetAccessToken(WechatAppType.MP, false);
                  var url = string.Format("https://api.weixin.qq.com/wxaapi/broadcast/room/create?access_token={0}", token);
      2020-10-08
      回复
    • Jnn
      Jnn
      2020-10-08
      2020-10-08
      回复
  • 苏格拉底河
    苏格拉底河
    2020-10-14

    很明显 参数 开始时间 格式不对 我找一下 我以前写的


      //转换为时间戳 

                string sTime = Utils.getTimestamp(Utils.ObjectToDateTime(model.startTime));

                string eTime = Utils.getTimestamp(Utils.ObjectToDateTime(model.endTime));

    另外传参数的时候,加上“”

    2020-10-14
    有用
    回复
  • 四月
    四月
    2020-08-18

    请告知如下错误如何处理。怎么修改都不行

    2020-08-18
    有用
    回复 1
    • 🌱
      🌱
      2020-09-29
      请问你解决了吗? 我也是Java后台写的
      2020-09-29
      回复
登录 后发表内容
问题标签