using System; using System.Collections.Generic; using System.ServiceModel; using System.ServiceModel.Web; using WX.CRM.BLL.Wx; using WX.CRM.Common; using WX.CRM.IBLL.Wx; using WX.CRM.Model.Entity; using WX.CRM.Model.Enum; namespace WxService { // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码、svc 和配置文件中的类名“WeiXinService”。 // 注意: 为了启动 WCF 测试客户端以测试此服务,请在解决方案资源管理器中选择 WeiXinService.svc 或 WeiXinService.svc.cs,然后开始调试。 public class WeiXinService : IWeiXinService { IWX_USERIMEI wx_UserIMEI_BL = new WX_USERIMEI_BL(); IWX_UINCONFIG iwx_Uinconfig = new WX_UINCONFIG_BL(); ValidationErrors errors = new ValidationErrors(); public bool BatchInsertUserIMEI(string imeis) { if (string.IsNullOrWhiteSpace(imeis)) { return false; } return wx_UserIMEI_BL.BatchInsert(imeis); } public JsonResult> GetWxUinConfig() { try { List list = null; string cacheKey = "catch_uincConfigAllList"; if (CacheHelper.Exists(cacheKey)) { list = CacheHelper.Get>(cacheKey); } else { list = iwx_Uinconfig.GetAllUinConfigList(); } return new JsonResult> { result = true, retcode = Convert.ToInt32(EnumInterfaceErrcode.调用成功), retmsg = list }; } catch (System.Exception e) { LogHelper.Error(e.Message); return new JsonResult> { result = true, retcode = Convert.ToInt32(EnumInterfaceErrcode.系统错误), retmsg = null }; } } public JsonResult Insert(string uin, string userName, string wxPath) { try { LogHelper.Info(String.Format("uin:{0},userNmae:{1},wxPath:{2}", uin, userName, wxPath)); if (uin != null && !iwx_Uinconfig.IsHaveUin(uin)) { bool flag = iwx_Uinconfig.Update(ref errors, new WX_UINCONFIG() { UIN = uin, USERNAME = userName, WX_PATH = wxPath }); if (flag) { string cacheKey = "cache_uincConfigAllList"; CacheHelper.Set>(cacheKey, null); } return new JsonResult { result = true, retcode = (int)EnumInterfaceErrcode.调用成功, retmsg = "调用成功" }; } return new JsonResult { result = true, retcode = (int)EnumInterfaceErrcode.调用成功, retmsg = "插入失败!" }; } catch (System.Exception e) { LogHelper.Error(e.Message); return new JsonResult { result = false, retcode = (int)EnumInterfaceErrcode.系统错误, retmsg = null }; } } } [ServiceContract] public interface IWeiXinService { [OperationContract] [WebInvoke(Method = "*", ResponseFormat = WebMessageFormat.Json, UriTemplate = "BatchInsertUserIMEI?imeis={imeis}")] bool BatchInsertUserIMEI(string imeis); [OperationContract] [WebInvoke(Method = "*", ResponseFormat = WebMessageFormat.Json, UriTemplate = "GetWxUinConfig")] JsonResult> GetWxUinConfig(); [OperationContract] [WebInvoke(Method = "*", ResponseFormat = WebMessageFormat.Json, UriTemplate = "Insert?uin={uin}&userName={userName}&wxPath={wxPath}")] JsonResult Insert(string uin, string userName, string wxPath); } }