//定义变量
HttpRequest Request;
HttpResponse Response;
HttpServerUtility Server;
HttpContext Context; protected string token = string.Empty;
private string postStr = string.Empty;//接受微信公众平台发送过来的消息
string sendXML = string.Empty;//要回复给微信公众平台的消息
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
string FromUserName = string.Empty;//接受微信公众用户的微信账号
string MsgType = string.Empty;//接受微信公众用户发送过来的消息类型
string Content = string.Empty;//接受微信公众用户发送过来的类容 private Chain.BLL.WeiXinLog weiXinLogBLL = new Chain.BLL.WeiXinLog();
private Chain.Model.WeiXinLog weiXinLogModel = new Chain.Model.WeiXinLog(); private Chain.BLL.Mem memBll = new Chain.BLL.Mem();
private Chain.Model.Mem memModel = new Chain.Model.Mem(); private Chain.BLL.WeiXinRule weiXinRuleBLL = new Chain.BLL.WeiXinRule();
private Chain.Model.WeiXinRule ruleModel = new Chain.Model.WeiXinRule();
public void ProcessRequest(HttpContext context)
{
context.Response.Buffer = true;
context.Response.ExpiresAbsolute = DateTime.Now.AddDays(-);
context.Response.AddHeader("pragma", "no-cache");
context.Response.AddHeader("cache-control", "");
context.Response.CacheControl = "no-cache";
context.Response.ContentType = "text/plain";
Request = context.Request;
Response = context.Response;
Server = context.Server;
Context = context; try
{
//Log(GetAllParameter()); //客户端发送过来的消息
Stream s = System.Web.HttpContext.Current.Request.InputStream;
byte[] b = new byte[s.Length];
s.Read(b, , (int)s.Length);
postStr = Encoding.UTF8.GetString(b);
token = PubFunction.curParameter.strWeiXinToken; Log(postStr); if (Request.HttpMethod.ToLower() == "get")
{
//Get请求
if (Request.QueryString["signature"] != null && !string.IsNullOrEmpty(Request.QueryString["signature"].ToString()))
{
UrlValid();
}
}
else
{
//Post请求
//对消息(事件消息,文本消息)进行分析目前只对 关注(事件)、申请(文本)做处理
SendMsg();
}
}
catch (Exception ex)
{
Log(ex.ToString());
}
}
/// <summary>
/// 消息发送(响应请求)
/// </summary>
public void SendMsg()
{
xmlDoc.LoadXml(postStr);
MsgType = xmlDoc.GetElementsByTagName("MsgType")[].InnerText;
FromUserName = xmlDoc.GetElementsByTagName("FromUserName")[].InnerText; try
{
weiXinLogModel = weiXinLogBLL.GetModel(FromUserName);
if (weiXinLogModel == null)
{
//微信用户不存在“上一次”操作记录
weiXinLogModel = new WeiXinLog();
NoLastOperating();
}
else
{
//微信用户存在“上一次”操作记录
YesLastOperating(postStr);
}
sendXML = sendXML == "" ? ResponseSendStr.Text(postStr, weiXinRuleBLL.ErrorStr()) : sendXML; }
catch (Exception e)
{
Log(e.ToString());
}
finally
{
Log(sendXML);
}
Response.Write(sendXML);
}
/// <summary>
/// 微信用户存在“上一次”操作记录
/// </summary>
private void YesLastOperating( string postStr)
{ if (MsgType == "event")
{
//事件消息
AttentionNews(postStr);
}
else
{
//获取微信用户存在“上一次”操作记录
weiXinLogModel = weiXinLogBLL.GetModel(FromUserName);
switch (weiXinLogModel.StatusCode)
{
case "":
Do0ForApplicationMember();
break;
case "":
Do1ForApplicationMemberByReplyTelNumber();
break;
case "":
Do2MemberTransform();
break;
case "":
Do3ForMemberTransformByReplyTelNumberOrMemberCard();
break;
}
}
}
/// <summary>
/// 微信用户不存在“上一次”操作记录
/// </summary>
private void NoLastOperating()
{
if (MsgType == "event")
{
//事件消息
AttentionNews(postStr);
}
else if (MsgType == "text")
{
//文本消息
TextNews();
}
else
{
//其他消息处理 暂无
}
}
/// <summary>
/// 绘制微信会员卡
/// </summary>
public void DrawImage(Chain.Model.Mem mem, string FromUserName)
{
DrawImage(mem, "~/Upload/WeiXin/Images/bg.jpg", "~/Upload/WeiXin/Images/" + mem.MemWeiXinCard + ".jpg");
DrawImage(mem, "~/Upload/WeiXin/Images/memCard.jpg", "~/Upload/WeiXin/Images/" + mem.MemWeiXinCard + "-MemCard.jpg"); //Bitmap smallWeiXin = new Bitmap(130, 130); //System.Drawing.Image weixinImg = Web.Common.QRCodeImage.CreateQRCode(mem.MemCard); //Graphics g = Graphics.FromImage(smallWeiXin); //g.DrawImage(weixinImg, new Point(-35, -35));//130 * 130 //string savePath = Server.MapPath("~/Upload/WeiXin/Images/" + FromUserName + ".jpg"); //Bitmap bigWeiXin = new Bitmap(200, 200);
//g = Graphics.FromImage(bigWeiXin);
//g.DrawImage(smallWeiXin, new Rectangle(0, 0, 200, 200), new Rectangle(0, 0, 130, 130), GraphicsUnit.Pixel); //string bg = Server.MapPath("~/Upload/WeiXin/Images/bg.jpg"); //#region 背景图为非位图的处理
//System.Drawing.Image bgImg = System.Drawing.Image.FromFile(bg, true);
//Bitmap bmp = new Bitmap(bgImg.Width, bgImg.Height, PixelFormat.Format32bppArgb);
//g = Graphics.FromImage(bmp);
//g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
//g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
//g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
////g.DrawImage(bgImg, 0, 0);
//g.DrawImage(bgImg, new Rectangle(0, 0, bgImg.Width, bgImg.Height), new Rectangle(0, 0, bgImg.Width, bgImg.Height), GraphicsUnit.Pixel);
//#endregion //g.DrawImage(bigWeiXin, new RectangleF(50, 60, 200, 200), new RectangleF(0, 0, 200, 200), GraphicsUnit.Pixel); //g.DrawString("NO:" + mem.MemCard + "", new Font("微软雅黑", 34F, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, new PointF(280, 70)); //画会员卡号
//g.DrawString("积分:" + mem.MemCard + "", new Font("微软雅黑", 30F, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, new PointF(280, 115)); //积分
//g.DrawString("余额:" + mem.MemMoney.ToString("F2") + "", new Font("微软雅黑", 30F, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, new PointF(280, 160));//余额
//string pastStr = mem.MemPastTime.ToString("yyyy-MM-dd") == "2900-01-01" ? "有效期:永久有效" : "有效期:" + mem.MemPastTime.ToString("yyyy-MM-dd");//MemIsPast,MemPastTime False
//g.DrawString(pastStr, new Font("微软雅黑", 30F, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, new PointF(280, 205));//有效期 //bmp.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
} public void DrawImage(Chain.Model.Mem member, string sourceUrl, string targetUrl)
{
Bitmap smallWeiXin = new Bitmap(, ); System.Drawing.Image weixinImg = Web.Common.QRCodeImage.CreateQRCode(member.MemCard); Graphics g = Graphics.FromImage(smallWeiXin); g.DrawImage(weixinImg, new Point(-, -));//130 * 130 string savePath = System.Web.HttpContext.Current.Server.MapPath(targetUrl); Bitmap bigWeiXin = new Bitmap(, );
g = Graphics.FromImage(bigWeiXin);
g.DrawImage(smallWeiXin, new Rectangle(, , , ), new Rectangle(, , , ), GraphicsUnit.Pixel); string bg = System.Web.HttpContext.Current.Server.MapPath(sourceUrl); #region 背景图为非位图的处理
System.Drawing.Image bgImg = System.Drawing.Image.FromFile(bg, true);
Bitmap bmp = new Bitmap(bgImg.Width, bgImg.Height, PixelFormat.Format32bppArgb);
g = Graphics.FromImage(bmp);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
g.DrawImage(bgImg, new Rectangle(, , bgImg.Width, bgImg.Height), new Rectangle(, , bgImg.Width, bgImg.Height), GraphicsUnit.Pixel);
#endregion g.DrawImage(bigWeiXin, new RectangleF(, , , ), new RectangleF(, , , ), GraphicsUnit.Pixel); g.DrawString("NO:" + member.MemCard + "", new Font("微软雅黑", 34F, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, new PointF(, )); //画会员卡号
g.DrawString("积分:" + member.MemPoint + "", new Font("微软雅黑", 30F, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, new PointF(, )); //积分
g.DrawString("余额:" + member.MemMoney.ToString("F2") + "", new Font("微软雅黑", 30F, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, new PointF(, ));//余额
string pastStr = member.MemPastTime.ToString("yyyy-MM-dd") == "2900-01-01" ? "有效期:永久有效" : "有效期:" + member.MemPastTime.ToString("yyyy-MM-dd");//MemIsPast,MemPastTime False
g.DrawString(pastStr, new Font("微软雅黑", 30F, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, new PointF(, ));//有效期 bmp.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
}
/// <summary>
/// 会员注册
/// -1:卡号重复 -2:手机号码重复 -6:卡面号重复 1:没有重复项目
/// </summary>
public int MemRegister(bool isSMSVcode)
{
Mem memModel = new Mem();
string strTemp = isSMSVcode ? memModel.MemCard = weiXinLogModel.RecordContent : memModel.MemCard = this.Content;
memModel.MemPassword = DESEncrypt.Encrypt("");
memModel.MemName = "";
memModel.MemSex = true;
memModel.MemIdentityCard = "";
strTemp = isSMSVcode ? memModel.MemMobile = weiXinLogModel.RecordContent : memModel.MemMobile = this.Content;
memModel.MemPhoto = "";
memModel.MemBirthdayType = true;
memModel.MemBirthday = Convert.ToDateTime("1900-1-1 0:00:00");
memModel.MemIsPast = false;
memModel.MemPastTime = Convert.ToDateTime("2900-1-1 0:00:00");
memModel.MemPoint = ;
memModel.MemPointAutomatic = true;
memModel.MemMoney = ;
memModel.MemEmail = "";
memModel.MemAddress = "";
memModel.MemState = ;
memModel.MemRecommendID = ;
memModel.MemLevelID = ;
memModel.MemShopID = ;
memModel.MemCreateTime = DateTime.Now;
memModel.MemRemark = "";
memModel.MemUserID = ;
memModel.MemTelePhone = "";
memModel.MemWeiXinCard = FromUserName;
memModel.MemQRCode = "";
memModel.MemProvince = "";
memModel.MemCity = "";
memModel.MemCounty = "";
memModel.MemVillage = ""; return memBll.Add(memModel);
}
/// <summary>
/// 记录日志
/// </summary>
public void Log(string logText)
{
try
{
string fileName = DateTime.Now.ToShortDateString().Replace("-", "") + "_" + DateTime.Now.Hour + "_" + DateTime.Now.Minute / ;
string fullPath = Server.MapPath("~/Upload/Log/" + fileName + ".txt");
logText = DateTime.Now.ToString() + "\r\n" + logText;
File.AppendAllText(fullPath, logText + "\r\n\r\n");
}
catch (Exception ex)
{
PubFunction.SaveSysLog(, , "微信接口错误", ex.ToString() + " " + ex.StackTrace.ToString(), , DateTime.Now, PubFunction.ipAdress);
}
}
/// <summary>
/// 将单条新闻消息加入到集合
/// </summary>
public List<Chain.Model.WeiXinNews> GetModel(string NewsTitle, string NewsDesc, string NewsUrlFirst, string NewsUrlSecond)
{
List<Chain.Model.WeiXinNews> list = new List<WeiXinNews>();
Chain.Model.WeiXinNews model = new WeiXinNews();
model.NewsTitle = NewsTitle;
model.NewsDesc = NewsDesc;
model.NewsUrlFirst = NewsUrlFirst;
model.NewsUrlSecond = NewsUrlSecond;
list.Add(model);
return list;
}
 /// <summary>
/// 响应微信公众平台的验证
/// </summary>
protected void UrlValid()
{
string signature = Request.QueryString["signature"].ToString();
string timestamp = Request.QueryString["timestamp"].ToString();
string nonce = Request.QueryString["nonce"].ToString();
string echostr = Request.QueryString["echostr"].ToString();
// 将token、timestamp、nonce三个参数进行字典序排序
List<string> list = new List<string>();
list.Add(token);
list.Add(timestamp);
list.Add(nonce);
list.Sort();
//将三个参数字符串拼接成一个字符串进行sha1加密
string newSignature = "";
foreach (var item in list)
{
newSignature += item;
}
byte[] StrRes = Encoding.UTF8.GetBytes(newSignature);
System.Security.Cryptography.HashAlgorithm iSHA = new System.Security.Cryptography.SHA1CryptoServiceProvider();
StrRes = iSHA.ComputeHash(StrRes);
StringBuilder EnText = new StringBuilder();
foreach (byte iByte in StrRes)
{
EnText.AppendFormat("{0:x2}", iByte);
}
//获得加密后的字符串与signature对比,标识该请求来源于微信
if (signature == EnText.ToString())
Response.Write(echostr);
else
Response.Write("error"); PubFunction.SaveSysLog(, , "微信接口验证", string.Format("signature={0}&timestamp={1}&nonce={2}&echostr={3}&newSignature={4}&StrRes={5}", signature, timestamp, nonce, echostr, newSignature, EnText.ToString()), , DateTime.Now, PubFunction.ipAdress);
}
 /// <summary>
/// 事件消息 回复
/// </summary>
private void AttentionNews(string postStr)
{
string Event = xmlDoc.GetElementsByTagName("Event")[].InnerText;
if (Event == "subscribe") //关注
{
StringBuilder tempSb = new StringBuilder();
tempSb.AppendLine(PubFunction.curParameter.strWeiXinSalutatory).AppendLine().AppendLine(weiXinRuleBLL.AttentionStr());
sendXML = ResponseSendStr.Text(postStr, tempSb.ToString());
}
else if (Event == "CLICK")
{
this.MenuClick();
}
else
{
//其他事件 例如:取消关注
}
}
/// <summary>
/// 文本消息 回复
/// </summary>
private void TextNews()
{
Content = xmlDoc.GetElementsByTagName("Content")[].InnerText.Trim();
if (Content == "")
{
//回复 申请会员卡
ApplicationMemberCard();
}
else if (Content == "")
{
//doto 回复 已有会员卡转微信会员卡
ConvertWeiXinMember(postStr);
}
else
{
//回复 未知的文本
UnknownTextNewsHandle(postStr, Content);
}
}
/// <summary>
/// 申请会员卡
/// </summary>
private void ApplicationMemberCard()
{
Chain.Model.Mem mem = memBll.GetMemByWeiXinCard(FromUserName);
if (mem == null)
{
//微信会员不存在 提示注册信息
sendXML = ResponseSendStr.Text(postStr, "您已进入会员申请模式," + weiXinRuleBLL.Reply1());//发送手机号码
//记录微信日志
GiveWeiXinLodAssignment("", , "", "", );
weiXinLogBLL.Add(weiXinLogModel);
}
else
{
//微信会员已存在 发送微信会员卡
string NewsDesc = string.IsNullOrEmpty(PubFunction.curParameter.strWeiXinShopName) ? "" : PubFunction.curParameter.strWeiXinShopName;
NewsDesc = NewsDesc == "" ? "您的微信会员卡" : "您的" + NewsDesc + "微信会员卡";//您的【五维月凡】微信会员卡
Card(mem, "会员卡查询", NewsDesc);
}
}
/// <summary>
/// 处理未知文本消息
/// </summary>
private void UnknownTextNewsHandle(string postStr, string Content)
{
ruleModel = weiXinRuleBLL.GetModelByNewsRuleID(Content);
if (ruleModel != null)
{
if (ruleModel.RuleNewsType == "text")
{
//回复的是文本消息
sendXML = ResponseSendStr.Text(postStr, ruleModel.RuleContent);
}
else if (ruleModel.RuleNewsType == "news")
{
//回复的是图文消息
List<Chain.Model.WeiXinNews> newsList = new Chain.BLL.WeiXinNews().GetModelList("NewsRuleID=" + ruleModel.RuleID);
sendXML = ResponseSendStr.News(postStr, newsList);
}
else
{
//其他消息类型 例如:音乐等
}
}
}
/// <summary>
/// 给微信日志模型赋值
/// </summary>
private void GiveWeiXinLodAssignment(string RecordContent, int RecordContentType, string StatusCode, string RandomCode, int ErrorTimes)
{
weiXinLogModel.MemWeiXinCard = FromUserName;
weiXinLogModel.RecordContent = RecordContent;
weiXinLogModel.RecordContentType = RecordContentType;
weiXinLogModel.StatusCode = StatusCode;
weiXinLogModel.RandomCode = RandomCode;
weiXinLogModel.ErrorTimes = ErrorTimes;
weiXinLogModel.WeiXinLogCreateTime = DateTime.Now;
}
/// <summary>
/// 已有会员转微信会员
/// </summary>
private void ConvertWeiXinMember(string postStr)
{
Chain.Model.Mem mem = memBll.GetMemByWeiXinCard(FromUserName);
if (mem != null)
{
//微信会员已存在 提示:您已是微信会员
sendXML = ResponseSendStr.Text(postStr, "您已是微信会员");
}
else
{
sendXML = ResponseSendStr.Text(postStr, "您已进入转微信会员模式," + weiXinRuleBLL.Reply2());//请发送您的手机号或卡号 GiveWeiXinLodAssignment("", , "", "", );
weiXinLogBLL.Add(weiXinLogModel);
}
}
/// <summary>
/// 执行 0 对应的方法:申请会员卡
/// </summary>
private void Do0ForApplicationMember()
{
Content = xmlDoc.GetElementsByTagName("Content")[].InnerText.Trim();
if (System.Text.RegularExpressions.Regex.IsMatch(Content, @"^1[3|4|5|8]\d{9}$"))//用户输入的是手机号码
{
Chain.Model.Mem mem = memBll.GetModelByMemMobile(Content);
if (mem != null)
{
//该手机号已被注册 不可用
sendXML = ResponseSendStr.Text(postStr, "该手机号已被注册,请重新输入一个新的手机号");
}
else
{
//该手机号未被注册 可以用
if (PubFunction.curParameter.bolWeiXinSMSVcode)
{
//启用短信验证 要发送短信
if (PubFunction.curParameter.bolSms)
{
//系统短信功能已开启
if (SMSInfo.GetBalance(false) == "")
{
//短信余额不足
sendXML = ResponseSendStr.Text(postStr, "商家短信不足,发送短信验证码失败,请与商家联系");
weiXinLogBLL.Delete(FromUserName);
}
else
{
//短信余额充足
string smsVCode = GetRandomCode();
string NewsDesc = string.IsNullOrEmpty(PubFunction.curParameter.strWeiXinShopName) ? "" : PubFunction.curParameter.strWeiXinShopName;
NewsDesc = "温馨提示,欢迎您注册" + NewsDesc + "微信会员," + "您的" + NewsDesc + "微信会员短信验证码是:" + smsVCode;
sendXML = ResponseSendStr.Text(postStr, "请发送短信验证码");
SMSInfo.Send_GXSMS(false, Content, NewsDesc, "");
#region 发送短信
Chain.Model.SmsLog modelSms = new Chain.Model.SmsLog();
modelSms.SmsMemID = ;
modelSms.SmsMobile = Content;
modelSms.SmsContent = NewsDesc;
modelSms.SmsTime = DateTime.Now;
modelSms.SmsShopID = ;
modelSms.SmsUserID = ;
modelSms.SmsAmount = PubFunction.GetSmsAmount(NewsDesc);
modelSms.SmsAllAmount = modelSms.SmsAmount;
Chain.BLL.SmsLog bllSms = new Chain.BLL.SmsLog();
bllSms.Add(modelSms);
#endregion GiveWeiXinLodAssignment(Content, , "", smsVCode, );
weiXinLogBLL.Update(weiXinLogModel);
}
}
else
{
//系统短信功能未开启
sendXML = ResponseSendStr.Text(postStr, "系统短信功能暂未开启,发送短信验证码失败,请与商家联系");
weiXinLogBLL.Delete(FromUserName);
}
}
else
{
//未启用短信验证 直接办卡成功 删除微信日志
int isOk = MemRegister(false);
if (isOk > )
{
DoCard("恭喜您会员卡办理成功");
}
else
{
string strErr = "系统错误,会员办卡失败!";
switch (isOk)
{
case -:
strErr = "会员卡号重复,会员办卡失败!";
break;
case -:
strErr = "手机号码重复,会员办卡失败!";
break;
case -:
strErr = "卡面号重复,会员办卡失败!";
break;
default:
break;
}
sendXML = ResponseSendStr.Text(postStr, strErr);
}
}
}
}
else
{
GiveWeiXinLodAssignment("", , "", "", weiXinLogModel.ErrorTimes + );
ErrorNewsHandle("由于您的误操作次数过多,会员申请模式已退出", "您发送的手机号格式有误,请重新发送");
}
}
/// <summary>
/// 执行 1 对应的方法:申请会员卡之后回复了“手机号号码“
/// </summary>
private void Do1ForApplicationMemberByReplyTelNumber()
{
Content = xmlDoc.GetElementsByTagName("Content")[].InnerText.Trim();
if (!PubFunction.curParameter.bolWeiXinSMSVcode || weiXinLogModel.RandomCode == Content)
{
//短信验证成功
int isOk = MemRegister(true);
if (isOk > )
{
DoCard("恭喜您会员卡办理成功");
}
else
{
string strErr = "系统错误,会员办卡失败!";
switch (isOk)
{
case -:
strErr = "会员卡号重复,会员办卡失败!";
break;
case -:
strErr = "手机号码重复,会员办卡失败!";
break;
case -:
strErr = "卡面号重复,会员办卡失败!";
break;
default:
break;
}
sendXML = ResponseSendStr.Text(postStr, strErr);
}
}
else
{
//短信验证失败
GiveWeiXinLodAssignment(weiXinLogModel.RecordContent, weiXinLogModel.RecordContentType, weiXinLogModel.StatusCode, weiXinLogModel.RandomCode, weiXinLogModel.ErrorTimes + );
ErrorNewsHandle("由于您的误操作次数过多,会员申请模式已退出", "您发送的短信验证码有误,请重新发送");
}
}
/// <summary>
/// 执行 2 对应的方法:“申请已有会员转微信会员”
/// </summary>
private void Do2MemberTransform()
{
Content = xmlDoc.GetElementsByTagName("Content")[].InnerText.Trim();
memModel = memBll.GetModelByMemCard(Content);
if (memModel != null)
{
//根据会员卡号查找到会员 找到
sendXML = ResponseSendStr.Text(postStr, "请发送您的会员卡密码,如果密码为空请回复 # 号");
GiveWeiXinLodAssignment(memModel.MemCard, , "", "", );
weiXinLogBLL.Update(weiXinLogModel);
}
else
{
//根据会员卡号查找会员 没找到
Chain.Model.Mem mem = memBll.GetModelByMemMobile(Content);
if (mem != null)
{
//根据会员电话查找会员 找到
//启用短信验证 要发送短信
if (PubFunction.curParameter.bolWeiXinSMSVcode)
{
if (PubFunction.curParameter.bolSms)
{
//系统短信功能已开启
if (SMSInfo.GetBalance(false) == "")
{
//短信余额不足
string strTemplet = string.Format("由于本系统短信剩余条数不足,无法给您发送短信验证码;\r\n您的会员卡号为:{0}****{1},请发送您的会员卡密码,如果密码为空请回复 # 号", mem.MemCard.Substring(, ), mem.MemCard.Substring(mem.MemCard.Length - , ));
sendXML = ResponseSendStr.Text(postStr, strTemplet);
GiveWeiXinLodAssignment(mem.MemCard, , "", "", );
weiXinLogBLL.Update(weiXinLogModel);
}
else
{
//短信余额充足
string smsVCode = GetRandomCode();
string NewsDesc = string.IsNullOrEmpty(PubFunction.curParameter.strWeiXinShopName) ? "" : PubFunction.curParameter.strWeiXinShopName;
NewsDesc = "温馨提示,欢迎您申请从店铺会员转" + NewsDesc + "微信会员," + "您的" + NewsDesc + "微信会员短信验证码是:" + smsVCode;
sendXML = ResponseSendStr.Text(postStr, "请发送短信验证码");
SMSInfo.Send_GXSMS(false, Content, NewsDesc, "");
#region 发送短信
Chain.Model.SmsLog modelSms = new Chain.Model.SmsLog();
modelSms.SmsMemID = Convert.ToInt32(mem.MemID);
modelSms.SmsMobile = Content;
modelSms.SmsContent = NewsDesc;
modelSms.SmsTime = DateTime.Now;
modelSms.SmsShopID = ;
modelSms.SmsUserID = ;
modelSms.SmsAmount = PubFunction.GetSmsAmount(NewsDesc);
modelSms.SmsAllAmount = modelSms.SmsAmount;
Chain.BLL.SmsLog bllSms = new Chain.BLL.SmsLog();
bllSms.Add(modelSms);
#endregion GiveWeiXinLodAssignment(Content, , "", smsVCode, );
weiXinLogBLL.Update(weiXinLogModel);
}
}
else
{
//系统短信功能未开启
string strTemplet = string.Format("由于本系统短信功能暂未开启,无法给您发送短信验证码;\r\n您的会员卡号为:{0}****{1},请发送您的会员卡密码,如果密码为空请回复 # 号", mem.MemCard.Substring(, ), mem.MemCard.Substring(mem.MemCard.Length - , ));
sendXML = ResponseSendStr.Text(postStr, strTemplet);
GiveWeiXinLodAssignment(mem.MemCard, , "", "", );
weiXinLogBLL.Update(weiXinLogModel);
}
}
else
{
//未启用短信验证 直接转微信会员 删除微信日志
memModel = memBll.GetMemInfoByMobile(this.Content);
memModel.MemWeiXinCard = FromUserName;
memBll.Update(memModel);
DoCard("恭喜您已转移成微信会员");
}
}
else
{
//根据会员电话查找会员 没找到
GiveWeiXinLodAssignment(weiXinLogModel.RecordContent, weiXinLogModel.RecordContentType, weiXinLogModel.StatusCode, weiXinLogModel.RandomCode, weiXinLogModel.ErrorTimes + );
ErrorNewsHandle("由于您的错误操作次数过多,转微信会员模式已退出", "您发送的手机号或卡号在系统中没找着,请重新发送");
}
}
}
/// <summary>
/// 执行 3 对应的方法:申请已有会员转微信会员之后回复了“手机号或会员卡号”
/// </summary>
private void Do3ForMemberTransformByReplyTelNumberOrMemberCard()
{
string Content = xmlDoc.GetElementsByTagName("Content")[].InnerText.Trim();//获取待验证的内容
if (weiXinLogModel.RecordContentType == )//待验证的内容是会员的卡号密码
{
//string pwd = Chain.Common.DEncrypt.DESEncrypt.Encrypt(Content == "#" ? "" : Content);
string pwd = Chain.Common.DEncrypt.DESEncrypt.Encrypt(Content == "#" ? "" : Content == "#" ? "" : Content);
memModel = memBll.GetModelByMemCard(weiXinLogModel.RecordContent);
if (pwd == memModel.MemPassword)
{
memModel.MemWeiXinCard = weiXinLogModel.MemWeiXinCard;
memBll.Update(memModel);
DoCard("恭喜您已转移成微信会员");
}
else
{
GiveWeiXinLodAssignment(weiXinLogModel.RecordContent, , "", "", weiXinLogModel.ErrorTimes + );
ErrorNewsHandle("由于您的错误操作次数过多,转微信会员模式已退出", "您发送的会员卡密码不正确,请重新发送");
}
}
else//待验证的内容是短信随机验证码
{
if (!PubFunction.curParameter.bolWeiXinSMSVcode || weiXinLogModel.RandomCode == Content)
{
memModel = memBll.GetMemInfoByMobile(weiXinLogModel.RecordContent);
memModel.MemWeiXinCard = weiXinLogModel.MemWeiXinCard;
memBll.Update(memModel);
DoCard("恭喜您已转移成微信会员");
}
else
{
GiveWeiXinLodAssignment(weiXinLogModel.RecordContent, , weiXinLogModel.StatusCode, weiXinLogModel.RandomCode, weiXinLogModel.ErrorTimes + );
ErrorNewsHandle("由于您的错误操作次数过多,转微信会员模式已退出", "您发送的短信验证码有误,请重新发送");
}
}
}
 /// <summary>
/// 返回短信验证码
/// </summary>
private string GetRandomCode()
{
Random random = new Random();
string result = string.Empty;
for (int i = ; i < ; i++)
{
result += random.Next(, );
}
return result;
}
/// <summary>
/// 发卡
/// </summary>
private void Card(Chain.Model.Mem mem, string NewsTitle, string NewsDesc)
{
DrawImage(mem, FromUserName);
#region 会员卡查询 图文模型列表
string NewsUrlFirst = "http://" + PubFunction.curParameter.strDoMain + "/Upload/WeiXin/Images/" + FromUserName + ".jpg" + "?id=" + Guid.NewGuid();
//string NewsUrlSecond = "http://" + PubFunction.curParameter.strDoMain + "/WeiXin/MemberManipulate.aspx?MemWeiXinCard=" + FromUserName;
string NewsUrlSecond = "http://" + PubFunction.curParameter.strDoMain + "/ReceptionPage/index.aspx?MemWeiXinCard=" + FromUserName;
List<Chain.Model.WeiXinNews> newsList = GetModel(NewsTitle, NewsDesc, NewsUrlFirst, NewsUrlSecond);
#endregion
sendXML = ResponseSendStr.News(postStr, newsList);//出示会员卡
}
        /// <summary>
/// 对用户错误次数的处理
/// </summary>
private void ErrorNewsHandle(string errorTimesExceed, string errorTimesNoExceed)
{
if (weiXinLogModel.ErrorTimes >= )
{
sendXML = ResponseSendStr.Text(postStr, errorTimesExceed);
weiXinLogBLL.Delete(FromUserName);
}
else
{
sendXML = ResponseSendStr.Text(postStr, errorTimesNoExceed);
weiXinLogBLL.Update(weiXinLogModel);
}
}
        /// <summary>
/// 办卡
/// </summary>
private void DoCard(string NewsTitle)
{
Chain.Model.Mem mem = memBll.GetMemByWeiXinCard(FromUserName);
string NewsDesc = string.IsNullOrEmpty(PubFunction.curParameter.strWeiXinShopName) ? "" : PubFunction.curParameter.strWeiXinShopName;
NewsDesc = NewsDesc == "" ? "您的微信会员卡" : "您的" + NewsDesc + "微信会员卡";//您的【五维月凡】微信会员卡
Card(mem, NewsTitle, NewsDesc);
weiXinLogBLL.Delete(FromUserName);
}
        /// <summary>
/// 微网站
/// </summary>
private void WZZ()
{
if (this.memBll.GetMemByWeiXinCard(this.FromUserName) == null)
{
this.sendXML = ResponseSendStr.Text(this.postStr, "您目前还不是微会员,只有微会员才可以访问微网站");
}
else
{
string xml = File.ReadAllText(Server.MapPath("WWZ.xml"));
System.Xml.XmlDocument xmlWZZDoc = new System.Xml.XmlDocument();
xmlWZZDoc.LoadXml(xml);
string NewsTitle = xmlWZZDoc.GetElementsByTagName("NewsTitle")[].InnerText;
string NewsDesc = xmlWZZDoc.GetElementsByTagName("NewsDesc")[].InnerText;
string NewsUrlFirst = string.Concat(new object[] { "http://", PubFunction.curParameter.strDoMain, xmlWZZDoc.GetElementsByTagName("NewsUrlFirst")[].InnerText, "?id=", Guid.NewGuid() });
string NewsUrlSecond = "http://" + PubFunction.curParameter.strDoMain + xmlWZZDoc.GetElementsByTagName("NewsUrlSecond")[].InnerText + "?MemWeiXinCard=" + this.FromUserName;
List<WeiXinNews> newsList = this.GetModel(NewsTitle, NewsDesc, NewsUrlFirst, NewsUrlSecond);
this.sendXML = ResponseSendStr.News(this.postStr, newsList);
}
}
        /// <summary>
/// 微信菜单
/// </summary>
private void MenuClick()
{
this.weiXinLogBLL.Delete(this.FromUserName);
string EventKey = this.xmlDoc.GetElementsByTagName("EventKey")[].InnerText.Trim();
if (EventKey == "")
{
this.ApplicationMemberCard();
}
else if (EventKey == "")
{
this.ConvertWeiXinMember(this.postStr);
}
else if (EventKey == "")
{
this.WZZ();
}
else
{
this.UnknownTextNewsHandle(this.postStr, EventKey);
}
}
        /// <summary>
/// 获取所有的get和post等参数信息
/// </summary>
/// <returns></returns>
private string GetAllParameter()
{
string Para = string.Empty;
Para += "{QueryString}";
for (int i = ; i < Request.QueryString.AllKeys.Length; i++)
{
Para += Request.QueryString.Keys[i] + ":" + Request.QueryString[Request.QueryString.Keys[i]].ToString() + ";";
}
Para += "{Form}";
for (int i = ; i < Request.Form.AllKeys.Length; i++)
{
Para += Request.Form.Keys[i] + ":" + Request.Form[Request.Form.Keys[i]].ToString() + ";";
}
//Para += "{ServerVariables}";
//for (int i = 0; i < Request.ServerVariables.Count; i++)
//{
// Para += Request.ServerVariables.Keys[i] + ":" + Request.ServerVariables[i].ToString() + ";";
//}
return Para;
}

微信Api的更多相关文章

  1. 使用delphi+intraweb进行微信开发5—准备实现微信API,先从获取AccessToken开始

    在前4讲中我们已经使iw开发的应用成功和微信进行了对接,再接下来的章节中我们开始逐一尝试和实现微信的各个API,开始前先来点准备工作 首先需要明确的是,微信的API都是通过https调用实现的,分为p ...

  2. 总结的一些微信API接口

    本文给大家介绍的是个人总结的一些微信API接口,包括微信支付.微信红包.微信卡券.微信小店等,十分的全面,有需要的小伙伴可以参考下. 1. [代码]index.php <?php include ...

  3. 微信api退款操作

    状况:证书加载进去,本地调试退款成功,然而发不到iis上却是不成功. 分析:定然是iis配置问题. 问题一:证书加载不进去,出现“内部错误” 解决:在iis中找到对应的应用连接池,右键高级设置,找到“ ...

  4. C# 数字证书微信API调用使用参考事例

    X.509 v.3 证书的方法.一个比较完整的调用  微信  API的示例: private stringGetResponseResult()         { string strRespons ...

  5. 一个用得比较广的微信API的XXE外部实体注入漏洞

    文件地址: https://github.com/dodgepudding/wechat-php-sdk/raw/master/wechat.class.php 代码: <?php /** * ...

  6. 面向对象的全套“企业微信”api接口的代码实现,网上太多“面向过程”微信api接口的代码,这个开源给需要的人用

    有段时间没有写文章了. 一直以来,微信的热门是看得到的,很多人都需要与微信的api对接. 今天我这里就分享全套的企业微信api接口的代码. 关于微信api,网上已经有很多实现的了. 但是我今天之所以还 ...

  7. 01: 企业微信API开发前准备

    目录:企业微信API其他篇 01: 企业微信API开发前准备 02:消息推送 03: 通讯录管理 04:应用管理 目录: 1.1 术语介绍 1.2 开发步骤 1.1 术语介绍返回顶部 参考文档:htt ...

  8. IOS微信API异常:unrecognized selector sent to instance 0x17005c9b0'

    开发IOS整合微信API的时候,在运行程序的过程中可能会在注册你的APPID的时候抛出此异常而导致程序崩溃. 异常描述 [7661:2826851] *** Terminating app due t ...

  9. 微信程序开发系列教程(三)使用微信API给微信用户发文本消息

    这个系列的第二篇教程,介绍的实际是被动方式给微信用户发文本消息,即微信用户关注您的公众号时,微信平台将这个关注事件通过一个HTTP post发送到您的微信消息服务器上.您对这个post请求做了应答(格 ...

  10. java 微信api开发

    最近使用了一个很好的微信api框架,比较好使. 源码地址:https://github.com/chanjarster/weixin-java-tools/wiki 微信公众平台:微信公众平台开发文档 ...

随机推荐

  1. maven项目导入eclipse

    maven项目的配置文件 web java文件都在src下面 src/main/java src/main/webapp src/main/webapp/web-inf 导入后要重新添加jar包,设置 ...

  2. 中文系统下,UTF-8编码文本文件读取导致的错误

    一.UTF-8编码文件读取导致的错误 有个txt文件,里面内容为: aaa bbb ccc 以UTF-8编码方式打开txt文件,顺序读取,将里面的值放到一个hashset中,并判断aaa是否在在has ...

  3. 如何让Form窗体接收KeyDown事件?

    在使用.Net Framework编写窗体应用程序的时候,有时有需要响应窗体的按键消息.当窗体上没有任何其他控件的时候,窗体是可以直接响应这些消息的. 但是当窗体上有其他控件时,会发现窗体再也不会响应 ...

  4. 常用自动化测试工具介绍(支持B/S、C/S)

    一.功能测试工具1.QTP测试工具 全名HP QuickTest Professional software ,最新的版本为HP QuickTest Professional 11.0 QTP是qui ...

  5. javaSE学习博客与笔记

    equals和==的区别 Java中equals和==的区别 java中的数据类型,可分为两类: 1.基本数据类型,也称原始数据类型.byte,short,char,int,long,float,do ...

  6. 菜鸟-教你把Acegi应用到实际项目(9)-实现FilterInvocationDefinition

    在实际应用中,开发者有时需要将Web资源授权信息(角色与授权资源之间的定义)存放在RDBMS中,以便更好的管理.事实上,我觉得一般的企业应用都应当如此,因为这样可以使角色和Web资源的管理更灵活,更自 ...

  7. 剑指Offer:面试题8——旋转数组的最小值(java实现)

    题目描述: 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转. 输入 一个递增排序的数组的一个旋转 输出 旋转数组的最小元素. 例如数组{3,4,5,1,2}为{1,2,3,4,5}的 ...

  8. android 提高进程优先级 拍照永不崩溃(闪退)

    首先科普一下Android系统进程的优先级: 当系统的内存不足时, android系统将根据进程优先级选择杀死一些不太重要的进程. 进程优先级从高到低分别为: 1. 前台进程. 以下的进程为前台进程: ...

  9. 使用MonkeyTest对Android客户端进行压力测试 自动化代码

    1.monkey命令简介 Monkey是Android中的一个命令行工具,可以运行在模拟器里或实际设备中.它向系统发送伪随机的用户事件流(如按键输入.触摸屏输入.手势输入等),实现对正在开发的应用程序 ...

  10. Android Studio使用中的小常识

    1.如何继承抽象类? 1.1新建一个类如下: public class PersonDBOpenHelper{ } 1.2手写extends 你继承的类名 public class PersonDBO ...