Commit 2309e33e authored by 吴春's avatar 吴春

1

parent ddfdc1bc
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mall.WeChat.Common
{
/// <summary>
/// 微信事件接受的类
/// </summary>
public class WechatMessage
{
/// <summary>
/// 本公众帐号
/// </summary>
public string ToUserName { get; set; }
/// <summary>
/// appid
/// </summary>
public string Appid { get; set; }
/// <summary>
/// Token
/// </summary>
public string Token { get; set; }
/// <summary>
/// EncodingAESKey
/// </summary>
public string EncodingAESKey { get; set; }
/// <summary>
/// 用户帐号
/// </summary>
public string FromUserName { get; set; }
/// <summary>
/// 发送时间戳
/// </summary>
public string CreateTime { get; set; }
/// <summary>
/// 发送的文本内容
/// </summary>
public string Content { get; set; }
/// <summary>
/// 消息的类型
/// </summary>
public string MsgType { get; set; }
/// <summary>
/// 事件类型,subscribe(订阅)、unsubscribe(取消订阅)、scan(二维码扫描事件)、location(上报地理位置事件)、click(菜单点击事件)
/// </summary>
public string EventName { get; set; }
/// <summary>
/// 这两个属性会在后面的讲解中提到
/// </summary>
public string Ticket { get; set; }
/// <summary>
/// 事件KEY值,qrscene_为前缀,后面为二维码的参数值
/// </summary>
public string EventKey { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.IO;
using System.Net;
namespace Mall.Common.Pay.WeChatPat
{
public class Cryptography
{
public static UInt32 HostToNetworkOrder(UInt32 inval)
{
UInt32 outval = 0;
for (int i = 0; i < 4; i++)
outval = (outval << 8) + ((inval >> (i * 8)) & 255);
return outval;
}
public static Int32 HostToNetworkOrder(Int32 inval)
{
Int32 outval = 0;
for (int i = 0; i < 4; i++)
outval = (outval << 8) + ((inval >> (i * 8)) & 255);
return outval;
}
/// <summary>
/// 解密方法
/// </summary>
/// <param name="Input">密文</param>
/// <param name="EncodingAESKey"></param>
/// <returns></returns>
///
public static string AES_decrypt(String Input, string EncodingAESKey, ref string appid)
{
byte[] Key;
Key = Convert.FromBase64String(EncodingAESKey + "=");
byte[] Iv = new byte[16];
Array.Copy(Key, Iv, 16);
byte[] btmpMsg = AES_decrypt(Input, Iv, Key);
int len = BitConverter.ToInt32(btmpMsg, 16);
len = IPAddress.NetworkToHostOrder(len);
byte[] bMsg = new byte[len];
byte[] bAppid = new byte[btmpMsg.Length - 20 - len];
Array.Copy(btmpMsg, 20, bMsg, 0, len);
Array.Copy(btmpMsg, 20+len , bAppid, 0, btmpMsg.Length - 20 - len);
string oriMsg = Encoding.UTF8.GetString(bMsg);
appid = Encoding.UTF8.GetString(bAppid);
return oriMsg;
}
public static String AES_encrypt(String Input, string EncodingAESKey, string appid)
{
byte[] Key;
Key = Convert.FromBase64String(EncodingAESKey + "=");
byte[] Iv = new byte[16];
Array.Copy(Key, Iv, 16);
string Randcode = CreateRandCode(16);
byte[] bRand = Encoding.UTF8.GetBytes(Randcode);
byte[] bAppid = Encoding.UTF8.GetBytes(appid);
byte[] btmpMsg = Encoding.UTF8.GetBytes(Input);
byte[] bMsgLen = BitConverter.GetBytes(HostToNetworkOrder(btmpMsg.Length));
byte[] bMsg = new byte[bRand.Length + bMsgLen.Length + bAppid.Length + btmpMsg.Length];
Array.Copy(bRand, bMsg, bRand.Length);
Array.Copy(bMsgLen, 0, bMsg, bRand.Length, bMsgLen.Length);
Array.Copy(btmpMsg, 0, bMsg, bRand.Length + bMsgLen.Length, btmpMsg.Length);
Array.Copy(bAppid, 0, bMsg, bRand.Length + bMsgLen.Length + btmpMsg.Length, bAppid.Length);
return AES_encrypt(bMsg, Iv, Key);
}
private static string CreateRandCode(int codeLen)
{
string codeSerial = "2,3,4,5,6,7,a,c,d,e,f,h,i,j,k,m,n,p,r,s,t,A,C,D,E,F,G,H,J,K,M,N,P,Q,R,S,U,V,W,X,Y,Z";
if (codeLen == 0)
{
codeLen = 16;
}
string[] arr = codeSerial.Split(',');
string code = "";
int randValue = -1;
Random rand = new Random(unchecked((int)DateTime.Now.Ticks));
for (int i = 0; i < codeLen; i++)
{
randValue = rand.Next(0, arr.Length - 1);
code += arr[randValue];
}
return code;
}
private static String AES_encrypt(String Input, byte[] Iv, byte[] Key)
{
var aes = new RijndaelManaged();
//秘钥的大小,以位为单位
aes.KeySize = 256;
//支持的块大小
aes.BlockSize = 128;
//填充模式
aes.Padding = PaddingMode.PKCS7;
aes.Mode = CipherMode.CBC;
aes.Key = Key;
aes.IV = Iv;
var encrypt = aes.CreateEncryptor(aes.Key, aes.IV);
byte[] xBuff = null;
using (var ms = new MemoryStream())
{
using (var cs = new CryptoStream(ms, encrypt, CryptoStreamMode.Write))
{
byte[] xXml = Encoding.UTF8.GetBytes(Input);
cs.Write(xXml, 0, xXml.Length);
}
xBuff = ms.ToArray();
}
String Output = Convert.ToBase64String(xBuff);
return Output;
}
private static String AES_encrypt(byte[] Input, byte[] Iv, byte[] Key)
{
var aes = new RijndaelManaged();
//秘钥的大小,以位为单位
aes.KeySize = 256;
//支持的块大小
aes.BlockSize = 128;
//填充模式
//aes.Padding = PaddingMode.PKCS7;
aes.Padding = PaddingMode.None;
aes.Mode = CipherMode.CBC;
aes.Key = Key;
aes.IV = Iv;
var encrypt = aes.CreateEncryptor(aes.Key, aes.IV);
byte[] xBuff = null;
#region 自己进行PKCS7补位,用系统自己带的不行
byte[] msg = new byte[Input.Length + 32 - Input.Length % 32];
Array.Copy(Input, msg, Input.Length);
byte[] pad = KCS7Encoder(Input.Length);
Array.Copy(pad, 0, msg, Input.Length, pad.Length);
#endregion
#region 注释的也是一种方法,效果一样
//ICryptoTransform transform = aes.CreateEncryptor();
//byte[] xBuff = transform.TransformFinalBlock(msg, 0, msg.Length);
#endregion
using (var ms = new MemoryStream())
{
using (var cs = new CryptoStream(ms, encrypt, CryptoStreamMode.Write))
{
cs.Write(msg, 0, msg.Length);
}
xBuff = ms.ToArray();
}
String Output = Convert.ToBase64String(xBuff);
return Output;
}
private static byte[] KCS7Encoder(int text_length)
{
int block_size = 32;
// 计算需要填充的位数
int amount_to_pad = block_size - (text_length % block_size);
if (amount_to_pad == 0)
{
amount_to_pad = block_size;
}
// 获得补位所用的字符
char pad_chr = chr(amount_to_pad);
string tmp = "";
for (int index = 0; index < amount_to_pad; index++)
{
tmp += pad_chr;
}
return Encoding.UTF8.GetBytes(tmp);
}
/**
* 将数字转化成ASCII码对应的字符,用于对明文进行补码
*
* @param a 需要转化的数字
* @return 转化得到的字符
*/
static char chr(int a)
{
byte target = (byte)(a & 0xFF);
return (char)target;
}
private static byte[] AES_decrypt(String Input, byte[] Iv, byte[] Key)
{
RijndaelManaged aes = new RijndaelManaged();
aes.KeySize = 256;
aes.BlockSize = 128;
aes.Mode = CipherMode.CBC;
aes.Padding = PaddingMode.None;
aes.Key = Key;
aes.IV = Iv;
var decrypt = aes.CreateDecryptor(aes.Key, aes.IV);
byte[] xBuff = null;
using (var ms = new MemoryStream())
{
using (var cs = new CryptoStream(ms, decrypt, CryptoStreamMode.Write))
{
byte[] xXml = Convert.FromBase64String(Input);
byte[] msg = new byte[xXml.Length + 32 - xXml.Length % 32];
Array.Copy(xXml, msg, xXml.Length);
cs.Write(xXml, 0, xXml.Length);
}
xBuff = decode2(ms.ToArray());
}
return xBuff;
}
private static byte[] decode2(byte[] decrypted)
{
int pad = (int)decrypted[decrypted.Length - 1];
if (pad < 1 || pad > 32)
{
pad = 0;
}
byte[] res = new byte[decrypted.Length - pad];
Array.Copy(decrypted, 0, res, 0, decrypted.Length - pad);
return res;
}
}
}
This diff is collapsed.
......@@ -111,7 +111,7 @@ namespace Mall.Model.Entity.TradePavilion
/// <summary>
/// 性质
/// </summary>
public ProjectTypeEnum ProjectType { get; set; }
public int? ProjectType { get; set; }
/// <summary>
/// 面积要求
......@@ -214,7 +214,7 @@ namespace Mall.Model.Entity.TradePavilion
/// <summary>
/// 是否已在成都落地 0-否,1-是,-1未填写
/// </summary>
public int IsInChengdu { get; set; }
public int? IsInChengdu { get; set; }
/// <summary>
/// 奖项来源ids
......
......@@ -67,6 +67,11 @@ namespace Mall.Model.Extend.TradePavilion
/// </summary>
public string ProjectName { get; set; }
/// <summary>
/// 分类名称
/// </summary>
public string CategoryName { get; set; }
/// <summary>
/// 首店数量
/// </summary>
......
......@@ -685,6 +685,9 @@ namespace Mall.Module.TradePavilion
var inserCModel = model.RefMapperTo<RB_Building_Carrier_Extend>();
inserCModel.ID = 0;
inserCModel.UserId = cmodel.CreateBy;
inserCModel.BuiltUpArea = model.BuiltUpArea ?? 0;
inserCModel.AreaRequirement = model.AreaRequirement ?? 0;
if (model.OpenTime.HasValue)
{
if (model.OpenTime.Value <= System.DateTime.Now)
......@@ -793,7 +796,8 @@ namespace Mall.Module.TradePavilion
var blist = brand_EnterpriseRepository.GetBrandEnterpriseListRepository(new RB_Brand_Enterprise_Extend() { TenantId = model.TenantId, MallBaseId = model.MallBaseId, UserId = userId });
model.BrandModel = blist.FirstOrDefault().RefMapperTo<RB_BrandEnterpriseApplyFor_Extend>();
model.BrandModel.BrandClassId = blist.FirstOrDefault().CategoryId;
model.BrandModel.ClassName = blist.FirstOrDefault().CategoryName;
if (model.BrandModel != null)
{
if (!string.IsNullOrWhiteSpace(model.BrandModel.CustomerType))
......@@ -834,16 +838,17 @@ namespace Mall.Module.TradePavilion
}
else if (model.FirstShopType == 2)
{
var clist = building_CarrierRepository.GetBuildingCarrierListRepository(new RB_Building_Carrier_Extend() { TenantId = model.TenantId, MallBaseId = model.MallBaseId, UserId = userId });
var clist = building_CarrierRepository.GetBuildingCarrierListRepository(new RB_Building_Carrier_Extend() {OpeningStatus=-1,TenantId = model.TenantId, MallBaseId = model.MallBaseId, UserId = userId });;
if (clist.Any())
{
model.CarrierModel = clist.FirstOrDefault().RefMapperTo<RB_CarrierEnterpriseApplyFor_Extend>();
var metroList = carrierEnterpriseMetroApplyForRepository.GetCarrierMetroList(new RB_CarrierEnterpriseMetroApplyFor_Extend { TenantId = model.TenantId, MallBaseId = model.MallBaseId, CarrierId = model.CarrierModel.ID });
model.CarrierModel.CarrierMetroList = new List<RB_CarrierEnterpriseMetroApplyFor_Extend>();
if (metroList != null && metroList.Any())
{
model.CarrierModel.CarrierMetroList = metroList.RefMapperToList<RB_CarrierEnterpriseMetroApplyFor_Extend>();
}
// model.CarrierModel.BuiltUpArea = clist.FirstOrDefault().BuiltUpArea;
//var metroList = carrierEnterpriseMetroApplyForRepository.GetCarrierMetroList(new RB_CarrierEnterpriseMetroApplyFor_Extend { TenantId = model.TenantId, MallBaseId = model.MallBaseId, CarrierId = model.CarrierModel.ID });
//model.CarrierModel.CarrierMetroList = new List<RB_CarrierEnterpriseMetroApplyFor_Extend>();
//if (metroList != null && metroList.Any())
//{
// model.CarrierModel.CarrierMetroList = metroList.RefMapperToList<RB_CarrierEnterpriseMetroApplyFor_Extend>();
//}
if (!string.IsNullOrWhiteSpace(model.CarrierModel.Banner))
{
model.CarrierModel.BannerList = JsonConvert.DeserializeObject<List<string>>(model.CarrierModel.Banner);
......
......@@ -155,6 +155,10 @@ WHERE 1=1
{
builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Building_Carrier_Extend.CategoryId), query.CategoryId);
}
if (query.UserId > 0)
{
builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Building_Carrier_Extend.UserId), query.UserId);
}
if (!string.IsNullOrEmpty(query.QStartDate))
{
builder.AppendFormat(" AND A.{0}>='{1}' ", nameof(RB_Building_Carrier_Extend.OpenTime), query.QStartDate);
......
......@@ -4,6 +4,7 @@ using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Xml;
using Google.Protobuf.WellKnownTypes;
using Mall.Common;
using Mall.Common.API;
......@@ -11,10 +12,12 @@ using Mall.Common.Pay.WeChatPat;
using Mall.Common.Plugin;
using Mall.Module.User;
using Mall.WebApi.Filter;
using Mall.WeChat.Common;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using Org.BouncyCastle.Crypto.Generators;
namespace Mall.WebApi.Controllers.AppletWeChat
{
......@@ -536,97 +539,68 @@ namespace Mall.WebApi.Controllers.AppletWeChat
/// <returns></returns>
[HttpPost]
[HttpGet]
public void EventMessageCall(string signature,string echostr,string timestamp,string nonce)
public void EventMessageCall(int MallBaseId, int TenantId, string signature, string echostr, string timestamp, string nonce, string openid, string encrypt_type, string msg_signature)
{
try
{
int qrCodeType = 0;
int userId = 0;
string textpl = "";
string content = "你好!";
string sToken = "f87f2b2a8c474c06908b5c937068b506";
string sAppID = "wxaeb077c07ed6f30d";
string sEncodingAESKey = "9FgR0wMXxe6wXBB5hwgpn2mZM6sQMi3E3Vk5sxrXEAL";
var request = _accessor.HttpContext.Request;
// var inputStream = request.Body;
var str = new StreamReader(request.Body);
string postStr = str.ReadToEnd();
LogHelper.Write("我是返回信息:" + postStr);
lock (_lock)
{
WechatMessage wx = WXBizMsgCrypt.GetWxMessage(postStr, timestamp, nonce, signature, encrypt_type, msg_signature, openid);
if (!string.IsNullOrWhiteSpace(wx.EventKey))// 用户未关注时,进行关注后的事件推送;事件KEY值,qrscene_为前缀,后面为二维码的参数值
{
textpl = ReceivedText(wx.FromUserName, wx.ToUserName, content);
if (encrypt_type.ToLower() == "aes".ToLower())//加密模式需要先解密
{
var ret = new WXBizMsgCrypt(sToken, sEncodingAESKey, sAppID);
int r = ret.EncryptMsg(textpl, timestamp, nonce, ref textpl);
if (r != 0)
{
LogHelper.WriteInfo("GetWxMessage_消息加密失败:");
textpl = "";
}
}
}
var requestMsg = Request.HttpContext.Items[GlobalKey.UserPostInfo];
var req = new RequestHandler();
LogHelper.WriteInfo("_accessor:" + _accessor);
LogHelper.WriteInfo("requestMsg:" + JsonHelper.Serialize(requestMsg));
var res = new ResponseHandler(_accessor);
#region 先注释
// string timestamp = "";
// string nonce = "";
// string echostr = "";
// string signature = "";
string encrypt_type = "";
string msg_signature = "";
string openid = "";
//try
//{
// signature = res.GetParameter("signature");
//}
//catch (Exception ex)
//{
// signature = "";
// LogHelper.WriteInfo("signature" + JsonHelper.Serialize(ex));
//}
//try
//{
// timestamp = res.GetParameter("timestamp");
//}
//catch (Exception ex)
//{
// LogHelper.WriteInfo("timestamp" + JsonHelper.Serialize(ex));
// timestamp = "";
//}
//try
//{
// nonce = res.GetParameter("nonce");
//}
//catch (Exception ex)
//{
// nonce = "";
// LogHelper.WriteInfo("nonce" + JsonHelper.Serialize(ex));
//}
//try
//{
// encrypt_type = res.GetParameter("encrypt_type");
//}
//catch (Exception ex)
//{
// encrypt_type = "";
// LogHelper.WriteInfo("encrypt_type" + JsonHelper.Serialize(ex));
//}
//try
//{
// msg_signature = res.GetParameter("msg_signature");
//}
//catch (Exception ex)
//{
// msg_signature = "";
// LogHelper.WriteInfo("msg_signature" + JsonHelper.Serialize(ex));
//}
//try
//{
// openid = res.GetParameter("openid");
//}
//catch (Exception ex)
//{
// openid = "";
// LogHelper.WriteInfo("openid" + JsonHelper.Serialize(ex));
//}
#endregion
//var str = new StreamReader(System.Web.HttpContext.Current.Request.InputStream);
//string postStr = str.ReadToEnd();
//lock (_lock)
//{
// WechatMessageHelper.WXOpera(postStr, timestamp, nonce, signature, encrypt_type, msg_signature, openid);
//}
}
}
catch (Exception ex)
{
LogHelper.Write(ex.ToString());
var response = HttpContext.Response;
response.WriteAsync("echostr is null");
// response.Flush();
//response.BodyWriter("");
}
}
/// <summary>
/// 接收消息
/// </summary>
/// <param name="FromUserName"></param>
/// <param name="ToUserName"></param>
/// <param name="Content"></param>
/// <returns></returns>
public static string ReceivedText(string FromUserName, string ToUserName, string Content)
{
string textpl = string.Empty;
textpl = "<xml>" +
"<ToUserName><![CDATA[" + FromUserName + "]]></ToUserName>" +
"<FromUserName><![CDATA[" + ToUserName + "]]></FromUserName>" +
"<CreateTime>" + (int)(DateTime.Now - DateTime.Parse("1970-1-1")).TotalSeconds + "</CreateTime>" +
"<MsgType><![CDATA[text]]></MsgType>" +
"<Content><![CDATA[" + Content + "]]></Content>" +
"<MsgId>" + (int)(DateTime.Now - DateTime.Parse("1970-1-1")).TotalSeconds + "</MsgId>" +
"</xml>";
return textpl;
}
}
}
\ No newline at end of file
......@@ -1844,7 +1844,7 @@ namespace Mall.WebApi.Controllers.TradePavilion
ID = parms.GetInt("ID", 0),
};
//query.MallBaseId = RequestParm.MallBaseId;
// query.TenantId = RequestParm.TenantId;
// query.TenantId = RequestParm.TenantId;
var extModel = carrierModule.GetCarrierModel(query);
if (userInfo == null)
{
......@@ -1873,7 +1873,7 @@ namespace Mall.WebApi.Controllers.TradePavilion
extModel.Address,
extModel.LatAndLon,
extModel.Developers,
OpenTime = extModel.OpenTime.HasValue ? extModel.OpenTime.Value.ToString("yyyy-MM-dd HH:mm") : "",
OpenTime = extModel.OpenTime.HasValue ? extModel.OpenTime.Value.ToString("yyyy-MM-dd HH:mm") : "",
extModel.ProjectType,
ProjectTypeName = extModel.ProjectType.GetEnumName(),
extModel.CarrierSize,
......@@ -2102,7 +2102,7 @@ namespace Mall.WebApi.Controllers.TradePavilion
ID = parms.GetInt("ID", 0),
};
// query.MallBaseId = req.MallBaseId;
// query.MallBaseId = req.MallBaseId;
//query.TenantId = req.TenantId;
query.RanQi = -1;
query.KongTiao = -1;
......@@ -3115,7 +3115,7 @@ namespace Mall.WebApi.Controllers.TradePavilion
var query = new RB_Brand_Enterprise_Extend()
{
BrandName = parms.GetStringValue("BrandName"),
ProjectType = (Common.Enum.TradePavilion.ProjectTypeEnum)parms.GetInt("ProjectType", 0),
//ProjectType = (Common.Enum.TradePavilion.ProjectTypeEnum)parms.GetInt("ProjectType", 0),
CategoryId = parms.GetInt("BrandClassId", 0),
BrandEnterpriseType = parms.GetInt("BrandEnterpriseType", 1),
};
......@@ -3284,6 +3284,8 @@ namespace Mall.WebApi.Controllers.TradePavilion
{
var userInfo = AppletUserInfo;
RB_Brand_Enterprise_Extend query = JsonConvert.DeserializeObject<RB_Brand_Enterprise_Extend>(RequestParm.msg.ToString());
query.ProjectType = query?.ProjectType ?? 0;
query.IsInChengdu = query?.IsInChengdu ?? 0;
if (query.ID <= 0)
{
return ApiResult.ParamIsNull("请传递品牌id");
......@@ -3296,10 +3298,12 @@ namespace Mall.WebApi.Controllers.TradePavilion
{
return ApiResult.Failed("请上传Logo");
}
if (query.BrandClassId == 0)
{
return ApiResult.Failed("请选择品牌分类");
}
query.CategoryId = query.BrandClassId;
if (query.BannerList != null && query.BannerList.Any())
{
query.Banner = JsonConvert.SerializeObject(query.BannerList);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment