You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

111 lines
3.1 KiB

using BWP.B3WeChat.BO;
using BWP.B3WeChat.Entities;
using BWP.B3WeChat.Utils;
using Forks.EnterpriseServices.BusinessInterfaces;
using Forks.EnterpriseServices.DomainObjects2;
using Forks.EnterpriseServices.DomainObjects2.DQuery;
using Forks.EnterpriseServices.SqlDoms;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using TSingSoft.WebPluginFramework;
namespace BWP.Web.Pages
{
class WeChatReceive : IHttpHandler
{
static Forks.Utils.Logger logger = new Forks.Utils.Logger("InOutMessageUtil");
string echoStr
{
get
{
return HttpContext.Current.Request.QueryString["echoStr"];
}
}
public bool IsReusable
{
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
#region 接入验证
if (!string.IsNullOrEmpty(echoStr))
{
if (InOutMessageUtil.CheckSignature())
{
HttpContext.Current.Response.Write(echoStr);
HttpContext.Current.Response.End();
}
return;
}
#endregion
object result = InOutMessageUtil.GetMessage(context.Request);
if (result is ReceivedMsg)
{
ReceivedMsg msg = result as ReceivedMsg;
string str = string.Empty;
if (msg != null)
{
ReplyMsg mes = new ReplyMsg()
{
CreateTime = ((int)DateTime.Now.Subtract(DateTime.Parse("1970-01-01")).TotalSeconds).ToString(),
Content = msg.Content,
ToUserName = msg.FromUserName,
FromUserName = InOutMessageUtil.config.SelfAppID,
MsgType = "text"
};
str = XmlUtil.Serializer(mes.GetType(), mes);
byte[] arr = Encoding.UTF8.GetBytes(str);
HttpContext.Current.Response.OutputStream.Write(arr, 0, arr.Length);
HttpContext.Current.Response.End();
}
}
else if (result is QRCodeMessage)
{
QRCodeMessage msg = result as QRCodeMessage;
logger.Info("EventKey:" + msg.EventKey + ",FromUserName:" + msg.FromUserName);
UpdateQRCode(msg.EventKey, msg.FromUserName);
logger.Info("关联成功");
}
}
static void UpdateQRCode(string sceneId, string OppenId)
{
var query = new DmoQuery(typeof(QRCode));
query.Where.Conditions.Add(DQCondition.EQ("ID", sceneId));
query.Range = SelectRange.Top(1);
var scene = query.EExecuteScalar<QRCode>();
var user = new CustomerUser();
user.CustomerCode = scene.Customer;
user.CustomerUsername = scene.UserId;
user.OpenID = OppenId;
using (var context = new TransactionContext())
{
context.Session.AddInsertOrUpdate(user);
context.Commit();
}
//var update = new DQUpdateDom(typeof(QRCode));
//logger.Info("sceneId:" + sceneId + ",OppenId" + OppenId);
//update.Where.Conditions.Add(DQCondition.EQ("ID", sceneId));
//update.Columns.Add(new DQUpdateColumn("OppenId", OppenId));
//using (var session = Dmo.NewSession())
//{
// session.ExecuteNonQuery(update);
// session.Commit();
//}
}
}
}