c# 调用微吼直播API
程序员文章站
2022-12-25 15:30:18
/// /// 调用微吼直播API /// /// /// /// 接口地址 /// Json格式的参数(公共参数+接口参数) /// public string GetLiveList(string appKey,string secrectKey,string url,string paramJ... ......
/// <summary> /// 调用微吼直播api /// </summary> /// <param name="appkey"></param> /// <param name="secrectkey"></param> /// <param name="url">接口地址</param> /// <param name="paramjson">json格式的参数(公共参数+接口参数)</param> /// <returns></returns> public string getlivelist(string appkey,string secrectkey,string url,string paramjson) { //unix时间戳 datetime dt = new datetime(1970, 1, 1, 0, 0, 0, datetimekind.utc); int time = (int)(datetime.now.addhours(-8) - dt).totalseconds; string timestamp = time.tostring(); //对参数key进行升序排序 paramjson = stortjson(paramjson); //把json字符串转换成dictionary对象 var objjson = jsonconvert.deserializeobject<dictionary<string, object>>(paramjson); //签名字符串 string sign = secrectkey; foreach (var temp in objjson) { sign += temp.key + temp.value; } sign += secrectkey; //对签名字符串进行md5加密 var signmd5 = formsauthentication.hashpasswordforstoringinconfigfile(sign, "md5"); //把md5密文转换成全小写(加密出来的md5是大写,调用微吼api接口需要小写) signmd5 = signmd5.tolower(); //把签名放进dictionary对象 objjson.add("sign", signmd5); //请求参数 string completeurl = string.empty; foreach (var temp in objjson) { completeurl += temp.key + "=" + temp.value + "&"; } completeurl = completeurl.substring(0, completeurl.length - 1); httpwebrequest request = (httpwebrequest)webrequest.create(url); request.method = "post"; request.contenttype = "application/x-www-form-urlencoded"; request.protocolversion = httpversion.version10; byte[] data = encoding.utf8.getbytes(completeurl); request.contentlength = data.length; stream newstream = request.getrequeststream(); newstream.write(data, 0, data.length); newstream.close(); httpwebresponse response = null; int httpstatus = 200; string content; try { response = (httpwebresponse)request.getresponse(); httpstatus = (int)response.statuscode; streamreader reader = new streamreader(response.getresponsestream(), encoding.utf8); content = reader.readtoend(); } catch (webexception e) { response = (httpwebresponse)e.response; httpstatus = (int)response.statuscode; using (stream errdata = response.getresponsestream()) { using (streamreader reader = new streamreader(errdata)) { content = reader.readtoend(); } } } return content; }
/// <summary> /// 对json字符串进行排序 /// </summary> /// <param name="json"></param> /// <returns></returns> public static string stortjson(string json) { var dic = jsonconvert.deserializeobject<sorteddictionary<string, object>>(json); sorteddictionary<string, object> keyvalues = new sorteddictionary<string, object>(dic); keyvalues.orderby(m => m.value);//升序 //keyvalues.orderbydescending(m => m.key);//降序 return jsonconvert.serializeobject(keyvalues); }
上一篇: 不放心自己
下一篇: Code First 更新数据库 记录
推荐阅读
-
C#调用微信接口的相关代码
-
使用C#调用系统API实现内存注入的代码
-
微吼入选百度AI加速器 加速AI与直播深度融合
-
c#两种方式调用google地球,调用COM API以及调用GEPLUGIN 与js交互,加载kml文件,dae文件。将二维高德地图覆盖到到三维谷歌地球表面。
-
C#调用百度API实现活体检测的方法
-
C# 调用百度 API 进行活体检测
-
C#调用Windows API(示例:显示任务管理器里的程序名称)
-
C#调用新浪微博API实例代码
-
c#两种方式调用google地球,调用COM API以及调用GEPLUGIN 与js交互,加载kml文件,dae文件。将二维高德地图覆盖到到三维谷歌地球表面。
-
C#微信开发之获取接口调用凭据