TG.WXCRM.V4/WxYunService/WxMessageSvr.svc.cs

403 lines
17 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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<string> _redisSet = new RedisSet<string>();
private RedisString<string> _redisMsg = new RedisString<string>();
private readonly PubSub _sub = new PubSub();
public IWX_ALIVE _aliveBll = NinjectControllerFactory.ninjectKernel.Get<IWX_ALIVE>();
public IWX_ALIVEIMEI _aliveImeiBll = NinjectControllerFactory.ninjectKernel.Get<IWX_ALIVEIMEI>();
public IWX_RCONTACT _rcontact = NinjectControllerFactory.ninjectKernel.Get<IWX_RCONTACT>();
private ISEQUENCES sequencesbll = NinjectControllerFactory.ninjectKernel.Get<ISEQUENCES>();
private IYUN_UPGRADEVERSION yun_upgradeversion = NinjectControllerFactory.ninjectKernel.Get<IYUN_UPGRADEVERSION>();
private IWX_TS_CMD wx_ts_cmd = NinjectControllerFactory.ninjectKernel.Get<IWX_TS_CMD>();
public JsonResult<string> RContactPut(IList<rcontact> 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<JsonResult<string>>(result);
}
catch (Exception ex)
{
LogHelper.Error(ex.ToString());
return new JsonResult<string> { result = false, retcode = (int)EnumInterfaceErrcode., retmsg = "调用成功但有错误" };
}
}
public JsonResult<string> FriendPut(IList<friend> 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<JsonResult<string>>(result);
}
catch (Exception ex)
{
LogHelper.Error(ex.ToString());
return new JsonResult<string> { result = false, retcode = (int)EnumInterfaceErrcode., retmsg = "调用成功但有错误" };
}
}
public JsonResult<string> 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<JsonResult<string>>(result);
}
catch (Exception ex)
{
LogHelper.Error(ex.ToString());
return new JsonResult<string> { result = false, retcode = (int)EnumInterfaceErrcode., retmsg = "调用成功但有错误" };
}
}
public JsonResult<string> 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<JsonResult<string>>(result);
}
catch (Exception ex)
{
LogHelper.Error(ex.ToString());
return new JsonResult<string> { result = false, retcode = (int)EnumInterfaceErrcode., retmsg = "调用成功但有错误" };
}
}
private static Dictionary<string, List<AppVersion>> appVersionList;
public JsonResult<List<AppVersion>> AppVersionGet(string code)
{
List<AppVersion> nversion = new List<AppVersion>();
try
{
if (appVersionList == null || appVersionList.Count == 0)
{
appVersionList = new Dictionary<string, List<AppVersion>>();
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<AppVersion> nlist = new List<AppVersion>();
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<List<AppVersion>> { result = false, retcode = (int)EnumInterfaceErrcode., retmsg = nversion };
}
else
{
nversion = appVersionList[code];
return new JsonResult<List<AppVersion>> { result = true, retcode = (int)EnumInterfaceErrcode., retmsg = nversion };
}
}
catch (Exception e)
{
LogHelper.Error(e.ToString());
return new JsonResult<List<AppVersion>> { result = false, retcode = (int)EnumInterfaceErrcode., retmsg = nversion };
}
}
private static Dictionary<string, UpgradeVersion> upgradeappVersionList;
public JsonResult<UpgradeVersion> UpgradeVersionGet(string code)
{
UpgradeVersion nversion = new UpgradeVersion();
try
{
if (upgradeappVersionList == null || upgradeappVersionList.Count == 0)
{
upgradeappVersionList = new Dictionary<string, UpgradeVersion>();
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<UpgradeVersion> { result = false, retcode = (int)EnumInterfaceErrcode., retmsg = nversion };
}
else
{
nversion = upgradeappVersionList[code];
return new JsonResult<UpgradeVersion> { result = true, retcode = (int)EnumInterfaceErrcode., retmsg = nversion };
}
}
catch (Exception e)
{
LogHelper.Error(e.ToString());
return new JsonResult<UpgradeVersion> { result = false, retcode = (int)EnumInterfaceErrcode., retmsg = nversion };
}
}
public JsonResult<string> GetShowBT(string code)
{
try
{
string showbt = ConfigurationManager.AppSettings["ShowBT"] == null ? "0" : ConfigurationManager.AppSettings["ShowBT"];
return new JsonResult<string> { result = true, retcode = (int)EnumInterfaceErrcode., retmsg = showbt };
}
catch (Exception e)
{
LogHelper.Error(e.ToString());
return new JsonResult<string> { result = false, retcode = (int)EnumInterfaceErrcode., retmsg = "0" };
}
}
public JsonResult<string> 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<string> { result = true, retcode = (int)EnumInterfaceErrcode., retmsg = JsonConvert.SerializeObject(model) };
}
else
{
return new JsonResult<string> { result = false, retcode = (int)EnumInterfaceErrcode., retmsg = "找不到数据" };
}
}
catch (Exception ex)
{
LogHelper.Error("获取朋友圈内容失败:" + ex.ToString());
return new JsonResult<string> { 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<string> RContactPut(IList<rcontact> content);
[OperationContract]
[WebInvoke(Method = "POST",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "Friend/Put")]
JsonResult<string> FriendPut(IList<friend> content);
[OperationContract]
[WebInvoke(Method = "*",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "Alive/Put")]
JsonResult<string> AlivePut(alive content);
[OperationContract]
[WebInvoke(Method = "POST",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "FriendAndRcontactPut/Put")]
JsonResult<string> FriendAndRcontactPut(friendAndRcontact friend);
[OperationContract]
[WebInvoke(Method = "*",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "AppVersion/Get?code={code}")]
JsonResult<List<AppVersion>> AppVersionGet(string code);
[OperationContract]
[WebInvoke(Method = "*",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "UpgradeVersion/Get?code={code}")]
JsonResult<UpgradeVersion> UpgradeVersionGet(string code);
[OperationContract]
[WebInvoke(Method = "*",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "ShowBT/Get?code={code}")]
JsonResult<string> GetShowBT(string code);
[OperationContract]
[WebInvoke(Method = "*",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "FriendScircleContent/Get/{pici}")]
JsonResult<string> FriendScircleContentGet(string pici);
}
}
[DataContract]
public class JsonResult<T>
{
[DataMember]
public bool result { get; set; }
[DataMember]
public int retcode { get; set; }
[DataMember]
public T retmsg { get; set; }
}