由于工作需要,平台要集成WeLink的会议管理和通讯录管理功能,通过一段时间的努力终于完成,在这个过程中,收获不少,汇总一下这次的经验,如果有同样需要的人,可以参考一下。
WeLink是华为开发的一款协同办公软件,集成有视频会议,即时通讯,屏幕共享,通讯录,还有一站式企业服务等功能,具体介绍可以参考华为官网。
1、华为会议集成
1.开发文档
实现效果:第三方应用通过输入API网关接入地址、会议用户帐号等相关参数进行预约会议,预约成功后即可获得入会链接。点击链接入会,系统自动调起华为会议客户端进入会议,实现一键入会。
一键入会业务流程:
- 初始化参数,填入API网关接入地址、用户帐号等参数。
- 第三方向网关APIG发起预约会议请求,并传入预约会议初始化参数。
- 网关APIG接收请求后,向CloudPortal发起预约会议请求。
- CloudPortal预约会议成功后,向APIG网关返回会议信息。
- 网关APIG将收到的会议信息返回给第三方。
- 预约会议成功后,获取conferenceID以及密码。为了实现链接入会,第三方向网关APIG发起会议鉴权请求。
- 网关APIG接收请求后,向CloudPortal发送会议鉴权请求。
- CloudPortal会议鉴权成功后,向APIG网关返回认证信息。
- 网关APIG将收到的认证信息返回给第三方,获取鉴权随机数(random)和下一跳url(siteUrl)。
- 构造华为会议客户端的自定义URL Protocol,然后拉起华为客户端并加入会议。
2.代码详解
我们这里以通过账号密码获取token接口为例,讲解一下代码这块的写法
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 /// <summary> 2 /// 通过账号密码获取token 3 /// </summary> 4 /// <param name="request">body参数</param> 5 /// <returns></returns> 6 public M_accessTokeninfoResponse GetMeetingToken(M_proxyRequest request) 7 { 8 M_accessTokeninfoResponse response = Action.Execute<M_accessTokeninfoResponse>(request); 9 return response; 10 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 public T Execute<T>(ApiRequest request) where T : ApiResponse 2 { 3 var jsonResult = ExecuteGetJsonStr(request); 4 return JsonConvert.DeserializeObject<T>(jsonResult); 5 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 public class M_accessTokeninfoResponse : ApiResponse 2 { 3 4 public string accessToken { get; set; } 5 public string tokenIp { get; set; } 6 public string validPeriod { get; set; } 7 public string expireTime { get; set; } 8 public string createTime { get; set; } 9 public user user { get; set; } 10 public int clientType { get; set; } 11 public string forceLoginInd { get; set; } 12 public string firstLogin { get; set; } 13 public string pwdExpired { get; set; } 14 public string daysPwdAvailable { get; set; } 15 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 public class M_proxyRequest : ApiRequest 2 { 3 public string account { get; set; } 4 public string authServerType { get; set; } 5 public string authType { get; set; } 6 public int clientType { get; set; } 7 public int createTokenType { get; set; } 8 public string pwd { get; set; } 9 10 public override string GetApiMethod() 11 { 12 return "/v1/usg/acs/auth/proxy"; 13 } 14 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 public abstract class ApiRequest 2 { 3 public abstract string GetApiMethod(); 4 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 public class ApiResponse 2 { 3 //public string access_token { get; set; } 4 //public Int32 expires_in { get; set; } 5 public string code { get; set; } 6 public string message { get; set; } 7 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 public string ExecuteGetJsonStr(ApiRequest request) 2 { 3 var url = GetRequestUrl(request); 4 var jsonData = GetRequestParamJsonStr(request); 5 6 return HttpWebRequestHelper.PostJsonToUrl(url, jsonData); 7 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 private string GetRequestUrl(ApiRequest request) 2 { 3 StringBuilder urlSb = new StringBuilder(meetingsUrl); 4 urlSb.Append(request.GetApiMethod()); 5 return urlSb.ToString(); 6 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 public string GetRequestParamJsonStr(ApiRequest request) 2 { 3 var jsonResult= JsonConvert.SerializeObject(request); 4 if (jsonResult=="{}") 5 { 6 return ""; 7 } 8 else 9 { 10 return jsonResult; 11 } 12 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 public static class HttpWebRequestHelper 2 { 3 #region PostJson方法 4 /// <summary> 5 /// post传递json数据 6 /// 无token时 7 /// </summary> 8 /// <param name="url">要请求的URL地址</param> 9 /// <param name="postData">json数据</param> 10 /// <returns></returns> 11 public static string PostJsonToUrl(string url, string postData) 12 { 13 string result = ""; 14 //解决请求被中止:无法建立SSL / TLS安全通道问题 15 System.Net.ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072; 16 17 HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); 18 19 req.Method = "POST"; 20 req.Timeout = 60000;//设置请求超时时间,单位为毫秒 21 req.ContentType = "application/json"; 22 req.UserAgent = "Apache-HttpClient/4.5.3 (Java/1.8.0_191)"; 23 SetHeaderValue(req.Headers, "Connection", "keep-alive"); 24 SetHeaderValue(req.Headers, "X-Request-ID", Guid.NewGuid().ToString("N")); 25 SetHeaderValue(req.Headers, "Accept-Language", "zh_CN"); 26 27 byte[] data = Encoding.UTF8.GetBytes(postData); 28 29 req.ContentLength = data.Length; 30 ServicePointManager.CertificatePolicy = new AcceptAllCertificatePolicy(); 31 32 using (Stream reqStream = req.GetRequestStream()) 33 { 34 reqStream.Write(data, 0, data.Length); 35 } 36 37 HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); 38 39 Stream stream = resp.GetResponseStream(); 40 41 //获取响应内容 42 using (StreamReader reader = new StreamReader(stream, Encoding.UTF8)) 43 { 44 result = reader.ReadToEnd(); 45 } 46 47 return result; 48 } 49 }
3.注意事项
.net 4.0 无法建立SSL / TLS安全通道问题,解决方案如下
1 //解决请求被中止:无法建立SSL / TLS安全通道问题 2 System.Net.ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
ServicePointManager.CertificatePolicy = new AcceptAllCertificatePolicy();
参考博客文档:https://www.cnblogs.com/SuperMetalMax/p/7286044.html
2、实现效果
会议管理页面
一键入会效果
视频会议效果图
屏幕共享,白板共享,程序共享等
屏幕共享效果