using DAL.Redis; using Newtonsoft.Json; using Ninject; using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Net; using System.Runtime.Serialization; using System.ServiceModel; using System.ServiceModel.Web; using System.Text; using System.Web; using System.Xml; using WX.CRM.Common; using WX.CRM.DAL.Redis; using WX.CRM.IBLL.Base; using WX.CRM.IBLL.TS; using WX.CRM.IBLL.Wx; using WX.CRM.IBLL.Yun; using WX.CRM.Model.DTO; using WX.CRM.Model.Enum; using WX.CRM.WebHelper.Infrastructure; namespace WxService { // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码、svc 和配置文件中的类名“WxMessageSvr”。 // 注意: 为了启动 WCF 测试客户端以测试此服务,请在解决方案资源管理器中选择 WxMessageSvr.svc 或 WxMessageSvr.svc.cs,然后开始调试。 public class WxMessageSvr : IWxMessageSvr { private const string WxFix = "wxid:"; private const string WxMsgFix = "wxmsgid:"; private RedisSet _redisSet = new RedisSet(); private RedisString _redisMsg = new RedisString(); private readonly PubSub _sub = new PubSub(); public IWX_ALIVE _aliveBll = NinjectControllerFactory.ninjectKernel.Get(); public IWX_ALIVEIMEI _aliveImeiBll = NinjectControllerFactory.ninjectKernel.Get(); public IWX_RCONTACT _rcontact = NinjectControllerFactory.ninjectKernel.Get(); private ISEQUENCES sequencesbll = NinjectControllerFactory.ninjectKernel.Get(); private IYUN_UPGRADEVERSION yun_upgradeversion = NinjectControllerFactory.ninjectKernel.Get(); private IWX_TS_CMD wx_ts_cmd = NinjectControllerFactory.ninjectKernel.Get(); public JsonResult RContactPut(IList content) { try { var url = ConfigurationManager.AppSettings["WeiXinRcontactUpload"]; var para = JsonConvert.SerializeObject(content); WebClient webClient = new WebClient(); webClient.Encoding = Encoding.UTF8; webClient.Headers[HttpRequestHeader.ContentType] = "application/json"; //string result = webClient.UploadString(url, "POST", "{\"jobwxusername\" : \"Ashu|29|7 Years|.NET\"}"); string result = webClient.UploadString(url, "POST", para); //LogHelper.Info("好友内容:" + result); return JsonConvert.DeserializeObject>(result); } catch (Exception ex) { LogHelper.Error(ex.ToString()); return new JsonResult { result = false, retcode = (int)EnumInterfaceErrcode.调用成功但有错误, retmsg = "调用成功但有错误" }; } } public JsonResult FriendPut(IList friends) { try { var url = ConfigurationManager.AppSettings["WxXinFriendsUpload"]; var para = JsonConvert.SerializeObject(friends); WebClient webClient = new WebClient(); webClient.Encoding = Encoding.UTF8; webClient.Headers[HttpRequestHeader.ContentType] = "application/json"; //string result = webClient.UploadString(url, "POST", "{\"jobwxusername\" : \"Ashu|29|7 Years|.NET\"}"); string result = webClient.UploadString(url, "POST", para); //LogHelper.Info("result:" + result); return JsonConvert.DeserializeObject>(result); } catch (Exception ex) { LogHelper.Error(ex.ToString()); return new JsonResult { result = false, retcode = (int)EnumInterfaceErrcode.调用成功但有错误, retmsg = "调用成功但有错误" }; } } public JsonResult AlivePut(alive info) { try { var url = ConfigurationManager.AppSettings["WeiXinUserAlive"]; WebClient webClient = new WebClient(); webClient.Encoding = Encoding.UTF8; webClient.Headers[HttpRequestHeader.ContentType] = "application/json"; string result = webClient.UploadString(url, "POST", JsonConvert.SerializeObject(info)); //string result = webClient.UploadString(url, "POST", "{\"username\":\"test\",\"lasttime\":11}"); //LogHelper.Info("alive:" + result); return JsonConvert.DeserializeObject>(result); } catch (Exception ex) { LogHelper.Error(ex.ToString()); return new JsonResult { result = false, retcode = (int)EnumInterfaceErrcode.调用成功但有错误, retmsg = "调用成功但有错误" }; } } public JsonResult FriendAndRcontactPut(friendAndRcontact friend) { try { var url = ConfigurationManager.AppSettings["FriendAndRcontactPut"]; WebClient webClient = new WebClient(); webClient.Encoding = Encoding.UTF8; webClient.Headers[HttpRequestHeader.ContentType] = "application/json"; string result = webClient.UploadString(url, "POST", JsonConvert.SerializeObject(friend)); //string result = webClient.UploadString(url, "POST", "{\"username\":\"test\",\"lasttime\":11}"); //LogHelper.Info("alive:" + result); return JsonConvert.DeserializeObject>(result); } catch (Exception ex) { LogHelper.Error(ex.ToString()); return new JsonResult { result = false, retcode = (int)EnumInterfaceErrcode.调用成功但有错误, retmsg = "调用成功但有错误" }; } } private static Dictionary> appVersionList; public JsonResult> AppVersionGet(string code) { List nversion = new List(); try { if (appVersionList == null || appVersionList.Count == 0) { appVersionList = new Dictionary>(); XmlDocument doc = new XmlDocument(); doc.Load(HttpContext.Current.Server.MapPath("~/xml/AppVersion.xml")); XmlNode node = doc.DocumentElement; foreach (XmlNode xnode in node.ChildNodes) { string phoneCode = xnode.Attributes["code"].Value; List nlist = new List(); foreach (XmlNode childNode in xnode.ChildNodes) { AppVersion version = new AppVersion(); version.code = phoneCode; version.phoneversion = childNode.Attributes["phoneversion"].Value; version.title = childNode.Attributes["title"].Value; version.version = childNode.Attributes["version"].Value; version.url = childNode.Attributes["file"].Value; version.sysname = childNode.Attributes["sysname"].Value; version.pack = childNode.Attributes["pack"].Value; nlist.Add(version); } if (!appVersionList.ContainsKey(phoneCode)) { appVersionList.Add(phoneCode, nlist); } } } if (!appVersionList.ContainsKey(code)) { return new JsonResult> { result = false, retcode = (int)EnumInterfaceErrcode.参数错误, retmsg = nversion }; } else { nversion = appVersionList[code]; return new JsonResult> { result = true, retcode = (int)EnumInterfaceErrcode.调用成功, retmsg = nversion }; } } catch (Exception e) { LogHelper.Error(e.ToString()); return new JsonResult> { result = false, retcode = (int)EnumInterfaceErrcode.调用成功但有错误, retmsg = nversion }; } } private static Dictionary upgradeappVersionList; public JsonResult UpgradeVersionGet(string code) { UpgradeVersion nversion = new UpgradeVersion(); try { if (upgradeappVersionList == null || upgradeappVersionList.Count == 0) { upgradeappVersionList = new Dictionary(); DataTable tab = yun_upgradeversion.YunVersionGet(); foreach (DataRow item in tab.Rows) { UpgradeVersion woc = new UpgradeVersion(); woc.code = item["code"].ToString(); woc.saledepart = item["saledepart"].ToString(); woc.type = item["type"].ToString(); string urlcode = HttpUtility.UrlEncode(item["url"].ToString()); woc.url = urlcode; woc.version = item["version"].ToString(); if (!upgradeappVersionList.ContainsKey(woc.code)) { upgradeappVersionList.Add(woc.code, woc); } } } if (!upgradeappVersionList.ContainsKey(code)) { return new JsonResult { result = false, retcode = (int)EnumInterfaceErrcode.参数错误, retmsg = nversion }; } else { nversion = upgradeappVersionList[code]; return new JsonResult { result = true, retcode = (int)EnumInterfaceErrcode.调用成功, retmsg = nversion }; } } catch (Exception e) { LogHelper.Error(e.ToString()); return new JsonResult { result = false, retcode = (int)EnumInterfaceErrcode.调用成功但有错误, retmsg = nversion }; } } public JsonResult GetShowBT(string code) { try { string showbt = ConfigurationManager.AppSettings["ShowBT"] == null ? "0" : ConfigurationManager.AppSettings["ShowBT"]; return new JsonResult { result = true, retcode = (int)EnumInterfaceErrcode.调用成功, retmsg = showbt }; } catch (Exception e) { LogHelper.Error(e.ToString()); return new JsonResult { result = false, retcode = (int)EnumInterfaceErrcode.调用成功但有错误, retmsg = "0" }; } } public JsonResult FriendScircleContentGet(string pici) { try { decimal npici = Convert.ToInt64(pici); DataTable tab = wx_ts_cmd.GetFriendScircleTxtByPici(npici);//改成过程逻辑方式 DataTable imgtab = wx_ts_cmd.GetFriendScircleImgList(npici);//获取朋友圈图片信息 FriendScircleModel model = null; if (tab != null && tab.Rows.Count > 0) { model = new FriendScircleModel(); model.pici = Convert.ToInt64(tab.Rows[0]["pici"]); model.txt = HttpUtility.UrlEncode(tab.Rows[0]["txt"].ToString()); if (imgtab != null && imgtab.Rows.Count > 0) { foreach (DataRow item in imgtab.Rows) { if (string.IsNullOrEmpty(model.imgpath)) model.imgpath = item["IMGPATH"].ToString(); else model.imgpath += ";" + item["IMGPATH"].ToString(); } } return new JsonResult { result = true, retcode = (int)EnumInterfaceErrcode.调用成功, retmsg = JsonConvert.SerializeObject(model) }; } else { return new JsonResult { result = false, retcode = (int)EnumInterfaceErrcode.调用成功但有错误, retmsg = "找不到数据" }; } } catch (Exception ex) { LogHelper.Error("获取朋友圈内容失败:" + ex.ToString()); return new JsonResult { result = false, retcode = (int)EnumInterfaceErrcode.调用成功但有错误, retmsg = "调用成功但有错误" }; } } } public class FriendScircleModel { public long pici { get; set; } public string txt { get; set; } public string imgpath { get; set; } } public class UpgradeVersion { public string code { get; set; } public string saledepart { get; set; } public string url { get; set; } public string type { get; set; } public string version { get; set; } } public class AppVersion { public string code { get; set; } public string phoneversion { get; set; } public string version { get; set; } public string title { get; set; } public string url { get; set; } public string sysname { get; set; } public string pack { get; set; } } public class MsgConfig { public long msgCreateTime { get; set; } public long fileCreateTime { get; set; } public long friendCreateTime { get; set; } } public class MessageHisViewModel { public string MSGSVRID { get; set; } public string NICKNAME { get; set; } public string USERNAME { get; set; } public long CREATETIME { get; set; } public string TALKER { get; set; } public string MSG_CONTENT { get; set; } public string MSG_URL { get; set; } public string MSG_TYPE { get; set; } } [ServiceContract] public interface IWxMessageSvr { [OperationContract] [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "RContact/Put")] JsonResult RContactPut(IList content); [OperationContract] [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "Friend/Put")] JsonResult FriendPut(IList content); [OperationContract] [WebInvoke(Method = "*", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "Alive/Put")] JsonResult AlivePut(alive content); [OperationContract] [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "FriendAndRcontactPut/Put")] JsonResult FriendAndRcontactPut(friendAndRcontact friend); [OperationContract] [WebInvoke(Method = "*", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "AppVersion/Get?code={code}")] JsonResult> AppVersionGet(string code); [OperationContract] [WebInvoke(Method = "*", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "UpgradeVersion/Get?code={code}")] JsonResult UpgradeVersionGet(string code); [OperationContract] [WebInvoke(Method = "*", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "ShowBT/Get?code={code}")] JsonResult GetShowBT(string code); [OperationContract] [WebInvoke(Method = "*", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "FriendScircleContent/Get/{pici}")] JsonResult FriendScircleContentGet(string pici); } } [DataContract] public class JsonResult { [DataMember] public bool result { get; set; } [DataMember] public int retcode { get; set; } [DataMember] public T retmsg { get; set; } }