using Bwp.MainSystem.BO;
|
|
using BWP.B3WeChat.BO;
|
|
using BWP.B3WeChat.Utils;
|
|
using Forks.EnterpriseServices.DomainObjects2;
|
|
using Forks.EnterpriseServices.DomainObjects2.DQuery;
|
|
using Forks.EnterpriseServices.JsonRpc;
|
|
using Forks.EnterpriseServices.SqlDoms;
|
|
using Forks.Utils;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using TSingSoft.WebPluginFramework;
|
|
|
|
namespace BWP.B3WeChat.Rpcs
|
|
{
|
|
[Rpc]
|
|
public static class ClientRpc
|
|
{
|
|
static string GetDeviceNumber()
|
|
{
|
|
var user = BLContext.User;
|
|
var query = new DQueryDom(new JoinAlias(typeof(DeviceAuthentication)));
|
|
query.Where.Conditions.Add(DQCondition.EQ("Ticket", user.UserTag.ToString("N")));
|
|
query.Columns.Add(DQSelectColumn.Field("DeviceNumber"));
|
|
query.Range = SelectRange.Top(1);
|
|
var deviceNumber = query.EExecuteScalar<string>();
|
|
return deviceNumber;
|
|
}
|
|
|
|
|
|
[Rpc]
|
|
public static void Send(string username, string content)
|
|
{
|
|
string oppenid = GetOpenId(username).ToString();
|
|
string[] param = content.Split('|');
|
|
switch (param[0])
|
|
{
|
|
case "SendAgentInfo": SendMessageUtil.SendAgentInfo(oppenid, param[1], param[2], param[3], param[4]); break;
|
|
}
|
|
}
|
|
|
|
static int GetOpenId(string username)
|
|
{
|
|
string customer = GetDeviceNumber();
|
|
var query = new DQueryDom(new JoinAlias(typeof(QRCodeScene)));
|
|
query.Columns.Add(DQSelectColumn.Field("OppenId"));
|
|
query.Where.Conditions.Add(DQCondition.EQ("Customer", customer));
|
|
query.Where.Conditions.Add(DQCondition.EQ("UserId", username));
|
|
query.Range = SelectRange.Top(1);
|
|
var OppenId = query.EExecuteScalar<int?>();
|
|
if (!OppenId.HasValue)
|
|
{
|
|
throw new Exception("未找到该微信用户或者" + username + "未关联微信");
|
|
}
|
|
return OppenId.Value;
|
|
}
|
|
|
|
[Rpc]
|
|
public static String GetQRCodeUrl(string username)
|
|
{
|
|
string url = string.Empty;
|
|
string customer = GetDeviceNumber();
|
|
int sceneId = GetSceneId(customer, username);
|
|
string ticket = InOutMessageUtil.GenerateEQCode(30, sceneId);
|
|
url = string.Format("https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket={0}", ticket);
|
|
return url;
|
|
}
|
|
|
|
static int GetSceneId(string customer, string username)
|
|
{
|
|
var query = new DQueryDom(new JoinAlias(typeof(QRCodeScene)));
|
|
query.Columns.Add(DQSelectColumn.Field("ID"));
|
|
query.Where.Conditions.Add(DQCondition.EQ("Customer", customer));
|
|
query.Where.Conditions.Add(DQCondition.EQ("UserId", username));
|
|
query.Range = SelectRange.Top(1);
|
|
var sceneId = query.EExecuteScalar<int?>();
|
|
if (!sceneId.HasValue)
|
|
{
|
|
using (var session = Dmo.NewSession())
|
|
{
|
|
QRCodeScene newSence = new QRCodeScene()
|
|
{
|
|
Customer = customer,
|
|
UserId = username,
|
|
};
|
|
session.Insert(newSence);
|
|
session.Commit();
|
|
sceneId = newSence.ID;
|
|
}
|
|
}
|
|
return sceneId.Value;
|
|
}
|
|
|
|
|
|
}
|
|
}
|