收藏
回答

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

// 参数
            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);


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;
            }
        }

{
  "Result": true,
  "Info": "{\"errmsg\":\"parameter startTime or endTime is invalid rid: 5f7e9943-69731824-18832adc\",\"errcode\":200002}",
  "CreateDt": "2020-10-08 12:44:53",
  "Data": {
    "name": "测试直播房间1",
    "coverImg": "mIZ6J141w3OWw5sOBwG3NRM06YzG_hD7O4vsKVi85Y3vSvcKEy7C_i6Rd_Q8y4YD",
    "startTime": 1602104393,
    "endTime": 1602107093,
    "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"
  }
}


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

2 个回答

  • 小程序技术专员-cheng
    小程序技术专员-cheng
    2020-10-09

    再加多个请求头?("accept","application/json")

    另外我不熟悉C#,这个用法里的POST,不需要大写吗?改为大写看看?

    2020-10-09
    有用
    回复 2
    • Jnn
      Jnn
      2020-10-10
      还是不行,有C#的demo吗?一直卡在这里
      2020-10-10
      回复
    • 小程序技术专员-cheng
      小程序技术专员-cheng
      2020-10-10回复Jnn
      你先用postman确认下能不能创建,如果可以的话应该是C#写法有问题?
      2020-10-10
      回复
  • 苏格拉底河
    苏格拉底河
    2020-10-14

    报什么错呢?我调用的几个api都是可以的!

    2020-10-14
    有用
    回复
登录 后发表内容
问题标签