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"
}
}
再加多个请求头?("accept","application/json")
另外我不熟悉C#,这个用法里的POST,不需要大写吗?改为大写看看?
报什么错呢?我调用的几个api都是可以的!