Browse Source

处理取消关注消息,并记录从微信接收到的消息

master
yashen 9 years ago
parent
commit
325e5ea118
5 changed files with 65 additions and 0 deletions
  1. +17
    -0
      B3WeChat.Web/Pages/WeChatReceive.cs
  2. +1
    -0
      B3WeChat/B3WeChat.csproj
  3. +38
    -0
      B3WeChat/BO/DebugInfo.cs
  4. +5
    -0
      B3WeChat/Entities/QRCodeMessage.cs
  5. +4
    -0
      B3WeChat/Utils/InOutMessageUtil.cs

+ 17
- 0
B3WeChat.Web/Pages/WeChatReceive.cs View File

@ -73,6 +73,12 @@ namespace BWP.Web.Pages
else if (result is QRCodeMessage) else if (result is QRCodeMessage)
{ {
QRCodeMessage msg = result as QRCodeMessage; QRCodeMessage msg = result as QRCodeMessage;
if (msg.IsUnsubscribeEvent())
{
Unsubscribe(msg.FromUserName);
return;
}
int scene_id; int scene_id;
if (!msg.TryGetSceneID(out scene_id)) if (!msg.TryGetSceneID(out scene_id))
{ {
@ -101,5 +107,16 @@ namespace BWP.Web.Pages
} }
} }
//用户取消关注时删除用户名与微信号的映射以及发给它的审批消息
private void Unsubscribe(string openID)
{
var delCustomerUser = new DQDeleteDom(typeof(CustomerUser));
delCustomerUser.Where.Conditions.Add(DQCondition.EQ("OpenID", openID));
delCustomerUser.EExecute();
var delApproveMessage = new DQDeleteDom(typeof(ApproveMessage));
delApproveMessage.Where.Conditions.Add(DQCondition.EQ("OpenID", openID));
delApproveMessage.EExecute();
}
} }
} }

+ 1
- 0
B3WeChat/B3WeChat.csproj View File

@ -110,6 +110,7 @@
<Compile Include="BL\ICustomerUserBL.cs" /> <Compile Include="BL\ICustomerUserBL.cs" />
<Compile Include="BO\ApproveMessage.cs" /> <Compile Include="BO\ApproveMessage.cs" />
<Compile Include="BO\ContentTemplate.cs" /> <Compile Include="BO\ContentTemplate.cs" />
<Compile Include="BO\DebugInfo.cs" />
<Compile Include="BO\NamedValueTemplate.cs" /> <Compile Include="BO\NamedValueTemplate.cs" />
<Compile Include="BO\QRCodeScene.cs" /> <Compile Include="BO\QRCodeScene.cs" />
<Compile Include="BO\CustomerUser.cs" /> <Compile Include="BO\CustomerUser.cs" />


+ 38
- 0
B3WeChat/BO/DebugInfo.cs View File

@ -0,0 +1,38 @@
using BWP.B3Frameworks.BO;
using Forks.EnterpriseServices.BusinessInterfaces;
using Forks.EnterpriseServices.DomainObjects2;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
namespace BWP.B3WeChat.BO
{
public class DebugInfo:Base
{
public string Category { get; set; }
[DbColumn(DbType=SqlDbType.NText)]
public string Text { get; set; }
[DbColumn(DbType=SqlDbType.DateTime)]
public DateTime Time { get; set; }
public static void Insert(string category, string text)
{
var info = new DebugInfo()
{
Category = category,
Text = text,
Time = DateTime.Now
};
using (var contex = new TransactionContext())
{
contex.Session.Insert(info);
contex.Commit();
}
}
}
}

+ 5
- 0
B3WeChat/Entities/QRCodeMessage.cs View File

@ -54,6 +54,11 @@ namespace BWP.B3WeChat.Entities
return Event == "subscribe"; return Event == "subscribe";
} }
public bool IsUnsubscribeEvent()
{
return Event == "unsubscribe";
}
public bool IsScanEvent() public bool IsScanEvent()
{ {
return Event == "SCAN"; return Event == "SCAN";


+ 4
- 0
B3WeChat/Utils/InOutMessageUtil.cs View File

@ -1,4 +1,5 @@
using BWP.B3WeChat; using BWP.B3WeChat;
using BWP.B3WeChat.BO;
using BWP.B3WeChat.Entities; using BWP.B3WeChat.Entities;
using Forks.Utils; using Forks.Utils;
using System; using System;
@ -199,6 +200,9 @@ namespace BWP.B3WeChat.Utils
{ {
StreamReader reader = new StreamReader(request.InputStream); StreamReader reader = new StreamReader(request.InputStream);
String xmlData = reader.ReadToEnd(); String xmlData = reader.ReadToEnd();
DebugInfo.Insert("微信消息文本", xmlData);
return ParseWeChatMessage(xmlData); return ParseWeChatMessage(xmlData);
} }


Loading…
Cancel
Save