调用协议:Http协议 调用方式:CRM中新分派线索(实时)或者线索未及时更新(定时,每天执行一次)时,调用APP标准消息接口推送信息,成功后返回标记已通知过。 接口调用方法如下: { "apikey":"xxxsadfsd", "identifier":"com.xx.xx",//向移动应用平台申请 "receiverType":"NAME", "receiverValue":"12313",//接收人员工号,多个以逗号分隔 "title":"aaaaa012",//消息标题 "content":"您有一条新任务aaa",//消息内容 "msgType":"CHAT" } 调用地址:https://xx.xx.com:9780/mapservice/appPush/sendMsg
string url = "https://xx.xx.com:9780/mapservice/appPush/sendMsg"; string param = "{\"apikey\": \"xxsad121\",\"identifier\": \"com.xx.xs\",\"receiverType\": \"NAME\",\"receiverValue\": \"" + ownerUser["employeeid"].ToString() + "\",\"title\": \"您有一条信息\", \"content\": \" " + messageTitle + "\",\"msgType\": \"CHAT\"}"; Log.WriteLog(param); string callback = PostLead(url, param); Log.WriteLog(callback); System.Web.Script.Serialization.JavaScriptSerializer json = new System.Web.Script.Serialization.JavaScriptSerializer(); LeadJson leadjson = json.Deserialize<LeadJson>(callback); if (leadjson.result == "True") { Log.WriteLog(leadjson.result); //userService.Update(entity); } public static string PostLead(string url, string param) { ServicePointManager.ServerCertificateValidationCallback = RemoteCertificateValidate; string strURL = url; System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)WebRequest.Create(strURL); request.Method = "POST"; request.ContentType = "application/json;charset=UTF-8"; string paraUrlCoded = param; byte[] payload; payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded); request.ContentLength = payload.Length; Stream writer = request.GetRequestStream(); writer.Write(payload, 0, payload.Length); writer.Close(); System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse(); System.IO.Stream s= response.GetResponseStream(); string StrDate = ""; string strValue = ""; StreamReader Reader = new StreamReader(s, Encoding.UTF8); while ((StrDate = Reader.ReadLine()) != null) { strValue += StrDate + "\r\n"; } return strValue; } public class LeadJson { public String result { get; set; } } //调用Https WebService发布后使用时报“基础连接已经关闭: 未能为 SSL/TLS 安全通道建立信任关系”证书验证失败的解决过程 不加这句话为报错 The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. private static bool RemoteCertificateValidate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors error) { // trust any certificate!!! System.Console.WriteLine("Warning, trust any certificate"); //为了通过证书验证,总是返回true return true; }
时间: 2024-11-02 21:37:44