Browse Source

使用新的微信模板发送审批通知

master
yashen 9 years ago
parent
commit
d448ada24c
5 changed files with 78 additions and 10 deletions
  1. +4
    -0
      B3WeChat/BL/IApproveMessageBL.cs
  2. +18
    -2
      B3WeChat/CustomerUserContext.cs
  3. +3
    -2
      B3WeChat/Rpcs/ApproveMessageRpc.cs
  4. +2
    -2
      B3WeChat/Utils/InOutMessageUtil.cs
  5. +51
    -4
      B3WeChat/Utils/SendMessageUtil.cs

+ 4
- 0
B3WeChat/BL/IApproveMessageBL.cs View File

@ -1,5 +1,6 @@
using BWP.B3WeChat.BO; using BWP.B3WeChat.BO;
using BWP.B3WeChat.BO.NamedValueTemplate; using BWP.B3WeChat.BO.NamedValueTemplate;
using BWP.B3WeChat.Utils;
using Forks.EnterpriseServices.BusinessInterfaces; using Forks.EnterpriseServices.BusinessInterfaces;
using Forks.EnterpriseServices.DomainObjects2; using Forks.EnterpriseServices.DomainObjects2;
using Forks.EnterpriseServices.DomainObjects2.DQuery; using Forks.EnterpriseServices.DomainObjects2.DQuery;
@ -53,6 +54,9 @@ namespace BWP.B3WeChat.BL
var del = new DQDeleteDom(typeof(ApproveMessage)); var del = new DQDeleteDom(typeof(ApproveMessage));
del.Where.Conditions.Add(DQCondition.EQ("ID", messageID)); del.Where.Conditions.Add(DQCondition.EQ("ID", messageID));
Session.ExecuteNonQuery(del); Session.ExecuteNonQuery(del);
var message = Load(messageID);
} }


+ 18
- 2
B3WeChat/CustomerUserContext.cs View File

@ -24,6 +24,16 @@ namespace BWP.B3WeChat
} }
} }
string mCustomerName;
public string CustomerName
{
get
{
return mCustomerName;
}
}
public string GetOpenID(string customerUsername) public string GetOpenID(string customerUsername)
{ {
var query = new DQueryDom(new JoinAlias(typeof(CustomerUser))); var query = new DQueryDom(new JoinAlias(typeof(CustomerUser)));
@ -53,10 +63,16 @@ namespace BWP.B3WeChat
var query = new DQueryDom(new JoinAlias(typeof(DeviceAuthentication))); var query = new DQueryDom(new JoinAlias(typeof(DeviceAuthentication)));
query.Where.Conditions.Add(DQCondition.EQ("Ticket", user.UserTag.ToString("N"))); query.Where.Conditions.Add(DQCondition.EQ("Ticket", user.UserTag.ToString("N")));
query.Columns.Add(DQSelectColumn.Field("DeviceNumber")); query.Columns.Add(DQSelectColumn.Field("DeviceNumber"));
query.Columns.Add(DQSelectColumn.Field("Name"));
query.Range = SelectRange.Top(1); query.Range = SelectRange.Top(1);
var deviceNumber = query.EExecuteScalar<string>();
var tuple = query.EExecuteScalar<string,string>();
if (tuple == null)
{
return null;
}
var context = new CustomerUserContext(); var context = new CustomerUserContext();
context.mCustomerCode = deviceNumber;
context.mCustomerCode = tuple.Item1;
context.mCustomerName = tuple.Item2;
if (httpContext != null) if (httpContext != null)
{ {
httpContext.Items[key] = context; httpContext.Items[key] = context;


+ 3
- 2
B3WeChat/Rpcs/ApproveMessageRpc.cs View File

@ -45,9 +45,10 @@ namespace BWP.B3WeChat.Rpcs
var mainSystemConfig = new MainSystemConfig(); var mainSystemConfig = new MainSystemConfig();
var internetAccessAddress = mainSystemConfig.InternetAccessAddress.Value; var internetAccessAddress = mainSystemConfig.InternetAccessAddress.Value;
var originUrl = internetAccessAddress + "app/index.html?messageid=" + message.ID; var originUrl = internetAccessAddress + "app/index.html?messageid=" + message.ID;
var wechatmessage = string.Format("ERP系统给你的用户{0}发送了一个消息待您审批", message.Username);
var timeStr = DateTime.Now.ToLongTimeString(); var timeStr = DateTime.Now.ToLongTimeString();
SendMessageUtil.SendInformInfo(message.OpenID, wechatmessage, timeStr, message.Title, message.Username, BLContext.ClientIP, timeStr, "", originUrl);
SendMessageUtil.SendTodoMessage(openID, context.CustomerName, message.Username, "微信工作流审批", message.CreateTime, originUrl);
#endif #endif
} }


+ 2
- 2
B3WeChat/Utils/InOutMessageUtil.cs View File

@ -107,7 +107,7 @@ namespace BWP.B3WeChat.Utils
return GetRequest<WeiChartServerList>(uriStr); return GetRequest<WeiChartServerList>(uriStr);
} }
public static SendTemplateMessageResult SendTemplateMessage(string openID, string templateID, Dictionary<string, ValueColor> dic, string url = "")
public static void SendTemplateMessage(string openID, string templateID, Dictionary<string, ValueColor> dic, string url = "")
{ {
string uriStr = string.Format("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={0}", TOKEN); string uriStr = string.Format("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={0}", TOKEN);
JavaScriptSerializer jsonHelper = new JavaScriptSerializer(); JavaScriptSerializer jsonHelper = new JavaScriptSerializer();
@ -118,7 +118,7 @@ namespace BWP.B3WeChat.Utils
body.url = url; body.url = url;
body.data = dic; body.data = dic;
string postData = jsonHelper.Serialize(body); string postData = jsonHelper.Serialize(body);
return PostRequest<SendTemplateMessageResult>(uriStr, postData);
PostRequest<SendTemplateMessageResult>(uriStr, postData);
} }
public static void SetCustomMenu(string menuJson) public static void SetCustomMenu(string menuJson)


+ 51
- 4
B3WeChat/Utils/SendMessageUtil.cs View File

@ -8,6 +8,53 @@ namespace BWP.B3WeChat.Utils
{ {
public static class SendMessageUtil public static class SendMessageUtil
{ {
//编号:OPENTM406714250
//标题:流程待办提醒
//{{first.DATA}}
//流程名称:{{keyword1.DATA}}
//提交时间:{{keyword2.DATA}}
//{{remark.DATA}}
public static void SendTodoMessage(string openID,string source,string toUsername,string flowName,DateTime time,string url)
{
var first = string.Format("你接收到来自{0}发送给用户{1}的新的审批任务", source, toUsername);
var keyword1 = flowName;
var keyword2 = time.ToString("yyy-MM-dd HH:mm:ss");
var remark = "你可以点击本消息进入处理界面";
Dictionary<string, ValueColor> dic = new Dictionary<string, ValueColor>();
dic.Add("first", new ValueColor() { value = first, color = "#173177" });
dic.Add("keyword1", new ValueColor() { value = keyword1, color = "#173177" });
dic.Add("keyword2", new ValueColor() { value = keyword2, color = "#173177" });
dic.Add("remark", new ValueColor() { value = remark, color = "#173177" });
InOutMessageUtil.SendTemplateMessage(openID, "qsaZh8axp__2V8Ut8owpUGu-wFH39fHt_DeBqoHiWI4", dic, url);
}
//{{first.DATA}}
//审批类别:{{keyword1.DATA}}
//审批事项:{{keyword2.DATA}}
//审批意见:{{keyword3.DATA}}
//审批结果:{{keyword4.DATA}}
//{{remark.DATA}}
public static void SendApprovetMessage(string openID, string messageid)
{
var keyword1 = "微信审批";
var keyword2 = "同意";
var keyword3 = "";
var keyword4 = "执行成功";
}
public static void SendRejectMessage()
{
}
/// <summary> /// <summary>
/// 发送代办信息 /// 发送代办信息
/// </summary> /// </summary>
@ -17,14 +64,14 @@ namespace BWP.B3WeChat.Utils
/// <param name="delay">未处理时间</param> /// <param name="delay">未处理时间</param>
/// <param name="remark">备注</param> /// <param name="remark">备注</param>
/// <returns></returns> /// <returns></returns>
public static SendTemplateMessageResult SendAgentInfo(string openid, string title, string todeal, string delay, string remark)
public static void SendAgentInfo(string openid, string title, string todeal, string delay, string remark)
{ {
Dictionary<string, ValueColor> dic = new Dictionary<string, ValueColor>(); Dictionary<string, ValueColor> dic = new Dictionary<string, ValueColor>();
dic.Add("first", new ValueColor() { value = title, color = "#173177" }); dic.Add("first", new ValueColor() { value = title, color = "#173177" });
dic.Add("keyword1", new ValueColor() { value = todeal, color = "#173177" }); dic.Add("keyword1", new ValueColor() { value = todeal, color = "#173177" });
dic.Add("keyword2", new ValueColor() { value = delay, color = "#173177" }); dic.Add("keyword2", new ValueColor() { value = delay, color = "#173177" });
dic.Add("remark", new ValueColor() { value = remark, color = "#173177" }); dic.Add("remark", new ValueColor() { value = remark, color = "#173177" });
return InOutMessageUtil.SendTemplateMessage(openid, "uhy7GuF8zwBA6pjvjQWpn02fiKb0o9cq7dO5DWnUuMg", dic);
InOutMessageUtil.SendTemplateMessage(openid, "uhy7GuF8zwBA6pjvjQWpn02fiKb0o9cq7dO5DWnUuMg", dic);
} }
/// <summary> /// <summary>
/// 发送系统提醒 /// 发送系统提醒
@ -38,7 +85,7 @@ namespace BWP.B3WeChat.Utils
/// <param name="when">操作时间</param> /// <param name="when">操作时间</param>
/// <param name="remark">备注</param> /// <param name="remark">备注</param>
/// <returns></returns> /// <returns></returns>
public static SendTemplateMessageResult SendInformInfo(string openid, string title, string informtime, string informcontent, string who,string ip, string when, string remark,string url="")
public static void SendInformInfo(string openid, string title, string informtime, string informcontent, string who, string ip, string when, string remark, string url = "")
{ {
Dictionary<string, ValueColor> dic = new Dictionary<string, ValueColor>(); Dictionary<string, ValueColor> dic = new Dictionary<string, ValueColor>();
dic.Add("first", new ValueColor() { value = title, color = "#173177" }); dic.Add("first", new ValueColor() { value = title, color = "#173177" });
@ -48,7 +95,7 @@ namespace BWP.B3WeChat.Utils
dic.Add("keyword4", new ValueColor() { value = ip, color = "#173177" }); dic.Add("keyword4", new ValueColor() { value = ip, color = "#173177" });
dic.Add("keyword5", new ValueColor() { value = when, color = "#173177" }); dic.Add("keyword5", new ValueColor() { value = when, color = "#173177" });
dic.Add("remark", new ValueColor() { value = remark, color = "#173177" }); dic.Add("remark", new ValueColor() { value = remark, color = "#173177" });
return InOutMessageUtil.SendTemplateMessage(openid, "JEOjjJ-L-hflfWoHEf7dRMlhj7fCs9NoOYf1iTQ03D4", dic,url);
InOutMessageUtil.SendTemplateMessage(openid, "JEOjjJ-L-hflfWoHEf7dRMlhj7fCs9NoOYf1iTQ03D4", dic, url);
} }
} }
} }

Loading…
Cancel
Save