protected void Button1_Click(object sender, EventArgs e) { try { string openid = ViewState["openid"].ToString(); if (!string.IsNullOrEmpty(openid)) { string ip = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; //ip = "127.0.0.1"; string notify_url = GetNotifyUrl("/Payment/wxpay/WXJSAPIPayNotifyDemo.aspx"); WXJSAPIPay pay = new WXJSAPIPay("VYIGO"); string prepay_id = pay.GetJSAPIPrepayID("我的订单", DateTime.Now.ToString("yyyyMMddHHmmss"), 100, ip, openid, notify_url, attach: txtMobile.Text); string script = "<script>document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() { WeixinJSBridge.invoke('getBrandWCPayRequest'," + pay.GetJSAPIParameters(prepay_id) + ",function(res){ WeixinJSBridge.log(res.err_msg); if(res.err_msg == 'get_brand_wcpay_request:ok' )" + " { alert(res.err_code+res.err_desc+res.err_msg); } });});</script>"; //lblDesc.Text = script; ExceptionLog log = new ExceptionLog(); log.Message = script; ExceptionLogDAL.InsertExceptionLog(log); Response.Write(script); //pay.DirectWXJSAPIPay(this.Response, "我的订单", DateTime.Now.ToString("yyyyMMddHHmmss"), 100, ip, openid, notify_url, attach: txtMobile.Text); } } catch (Exception ex) { lblDesc.Text = ex.Message; //Response.Write(ex.Message); } }
public override void OnPaySucceed(WXJSAPIPayNotifyInfo info) { //ExceptionLog log = new ExceptionLog(); //log.Message = string.Format("Openid:{0},订单号:{1},附加消息:{2}", info.OpenId, info.OutTradeNo, info.Attach); //ExceptionLogDAL.InsertExceptionLog(log); try { srChargeFee.wcRequestData scRequestData = new srChargeFee.wcRequestData(); srChargeFee.wcResponseData scResponseData = new srChargeFee.wcResponseData(); srChargeFee.OtherServiceSoapClient scChargeFee = new srChargeFee.OtherServiceSoapClient(); if (info.Attach.Split('|')[0] == "hfcz") { scRequestData.ChargeType = "hfcz"; } else { scRequestData.ChargeType = "qbcz"; } scRequestData.OrderID = info.OutTradeNo; scRequestData.ChargeNo = info.Attach.Split('|')[1].ToString(); scRequestData.ChargeAmount = info.Attach.Split('|')[2].ToString();// (Int64.Parse(info.TotalFee.ToString()) / 100).ToString(); scRequestData.OpenID = info.OpenId; scResponseData = scChargeFee.PutChargeFee(scRequestData); //log.Message = string.Format("充值结果:{1},充值说明:{2}", scResponseData.Ret, scResponseData.Msg); //ExceptionLogDAL.InsertExceptionLog(log); } catch { ExceptionLog log = new ExceptionLog(); log.Message = string.Format("Openid:{0},订单号:{1},附加消息:{2},出错!", info.OpenId, info.OutTradeNo, info.Attach); ExceptionLogDAL.InsertExceptionLog(log); } }
protected void Page_Load(object sender, EventArgs e) { Dictionary <string, string> sPara = GetRequestGet(); try { if (sPara.Count > 0)//判断是否有带返回参数 { AlipayNotify aliNotify = new AlipayNotify(); bool verifyResult = aliNotify.VerifyReturn(sPara, Request.QueryString["sign"]); if (verifyResult)//验证成功 { ///////////////////////////////////////////////////////////////////////////////////////////////////////////// //请在这里加上商户的业务逻辑程序代码 //——请根据您的业务逻辑来编写程序(以下代码仅作参考)—— //获取支付宝的通知返回参数,可参考技术文档中页面跳转同步通知参数列表 //商户订单号 string out_trade_no = Request.QueryString["out_trade_no"]; //支付宝交易号 string trade_no = Request.QueryString["trade_no"]; //交易状态,只会为"success" string result = Request.QueryString["result"]; //微商易业务逻辑 string url = string.Format("{0}/PalmShop/ShopCode/OrderHandle.aspx?oid={1}", HttpContext.Current.Request.Url.AbsoluteUri.Replace(HttpContext.Current.Request.Url.PathAndQuery, ""), out_trade_no); Response.Redirect(url); //打印页面 //Response.Write("验证成功<br />"); //——请根据您的业务逻辑来编写程序(以上代码仅作参考)—— ///////////////////////////////////////////////////////////////////////////////////////////////////////////// } else//验证失败 { Response.Write("验证失败"); } } else { Response.Write("无返回参数"); } } catch (Exception ex) { ExceptionLog log = new ExceptionLog(); log.Message = "@发生异常" + ex.Message; ExceptionLogDAL.InsertExceptionLog(log); } }
public override void OnPaySucceed(WXJSAPIPayNotifyInfo info) { ExceptionLog log = new ExceptionLog(); log.Message = string.Format("Openid:{0},订单号:{1},附加消息:{2}", info.OpenId, info.OutTradeNo, info.Attach); ExceptionLogDAL.InsertExceptionLog(log); }
public override void OnPaySucceed(AliWapPayCallBackInfo info) { ExceptionLog log = new ExceptionLog(); log.Message = string.Format("[CallBackDemo]订单号:{0},支付宝交易号:{1}", info.out_trade_no, info.trade_no); ExceptionLogDAL.InsertExceptionLog(log); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string return_code = string.Empty; string return_msg = string.Empty; Dictionary <string, string> dict = GetRequestPost(); if (wxpayHelper.VerifyNotify(dict, dict["sign"])) { return_code = "SUCCESS"; if (dict["return_code"] == "SUCCESS") { if (dict["result_code"] == "SUCCESS") { string openid = dict["openid"]; int total_fee = int.Parse(dict["total_fee"]); string trade_type = dict["trade_type"]; string transaction_id = dict["transaction_id"]; string out_trade_no = dict["out_trade_no"]; string attach = dict["attach"]; if (!string.IsNullOrEmpty(openid) && total_fee > 0 && !string.IsNullOrEmpty(transaction_id) && !string.IsNullOrEmpty(out_trade_no)) { ExceptionLog log = new ExceptionLog(); log.Message = string.Format("Openid:{0},订单号:{1},附加消息:{2}", openid, out_trade_no, attach); ExceptionLogDAL.InsertExceptionLog(log); //DisposeOrder(out_trade_no,attach); } else { return_code = "FAIL"; return_msg = "参数格式校验错误"; } } } } else { return_code = "FAIL"; return_msg = "签名失败"; } string returnValue = string.Format("<xml><return_code>{0}</return_code><return_msg>{1}</return_msg></xml>", return_code, return_msg); } }
/// <summary> /// 根据打印码获取客户机ID /// </summary> /// <param name="printCode"></param> /// <returns></returns> public string GetClientIDByPrintCode(string printCode, string siteCode) { string sql = @"SELECT ClientID FROM [HP_PrintCode] WHERE PrintCode=@PrintCode AND SiteCode=@SiteCode AND State=0"; IList <System.Data.SqlClient.SqlParameter> paras = new List <System.Data.SqlClient.SqlParameter>() { new System.Data.SqlClient.SqlParameter("@PrintCode", printCode), new System.Data.SqlClient.SqlParameter("@SiteCode", siteCode) }; ExceptionLogDAL.InsertExceptionLog(new ExceptionLog() { Message = string.Format("{0}||{1}", printCode, siteCode) }); return(DbHelperSQL.GetSingle(sql, paras.ToArray()) as string); }
/// <summary> /// 更新数据 /// </summary> /// <param name="tableName"></param> /// <param name="datas"></param> /// <returns></returns> public static int Update(string tableName, Dictionary <string, object> datas, string where) { int res = 0; if (!string.IsNullOrEmpty(tableName) && datas != null && datas.Count > 0) { StringBuilder values = new StringBuilder(); List <SqlParameter> paraList = new List <SqlParameter>(); bool flag = false; foreach (string key in datas.Keys) { if (flag) { values.Append(","); } values.AppendFormat("{0}=@{0}", key); paraList.Add(new SqlParameter(string.Format("@{0}", key), datas[key])); if (!flag) { flag = true; } } StringBuilder sql = new StringBuilder(); sql.AppendFormat("UPDATE {0} SET {1}", tableName, values.ToString()); if (!string.IsNullOrEmpty(where)) { sql.AppendFormat(" WHERE {0}", where); } ExceptionLogDAL.InsertExceptionLog( new ExceptionLog() { Message = sql.ToString() } ); res = DbHelperSQL.ExecuteSql(sql.ToString(), paraList.ToArray()); } return(res); }
/// <summary> /// 处理回复消息 /// "text":回复文本消息处理,MsgValue对应回复的文本 /// "sub_auto_coupon":回复订阅自动优惠券处理,MsgValue对应回复的图文消息ID /// "auto_news_article":根据文章自动生成图文消息进行回复,MsgValue为类别ID /// "news":回复图文表中的消息,MsgValue为图文消息表ID集,用逗号分隔 /// </summary> /// <param name="replyMsgType"></param> /// <param name="replyMsgValue"></param> /// <param name="customParams"></param> /// <returns></returns> private string ProcessReply(RequestMsgModel msgModel, string replyMsgType, string replyMsgValue) { string res = string.Empty; try { switch (replyMsgType.ToLower()) { case "text": //回复文本消息处理,MsgValue对应回复的文本 TextResponseMsgModel textMsg = new TextResponseMsgModel() { ToUserName = msgModel.FromUserName, FromUserName = msgModel.ToUserName, CreateTime = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString(), Content = replyMsgValue == null ? string.Empty : TransformText(replyMsgValue, msgModel) }; res = textMsg.ToString(); break; case "voice": //回复语音消息处理,MsgValue对应回复的文本 VoiceResponseMsgModel voiceMsg = new VoiceResponseMsgModel() { ToUserName = msgModel.FromUserName, FromUserName = msgModel.ToUserName, CreateTime = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString(), }; Media media = MediaDAL.CreateInstance().GetMediaByID(replyMsgValue); if (media != null && !string.IsNullOrEmpty(media.MediaID)) { voiceMsg.MediaId = media.MediaID; } res = voiceMsg.ToString(); break; case "wxpay_test": //用于微信支付测试 TextResponseMsgModel textMsgx = new TextResponseMsgModel() { ToUserName = msgModel.FromUserName, FromUserName = msgModel.ToUserName, CreateTime = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString(), Content = string.Format("<a href='{0}/Payment/wxpay/wxpayDemo.aspx?openid={1}'>微信支付测试</a>", GetSiteUrl(), msgModel.FromUserName) }; res = textMsgx.ToString(); break; case "transfer_customer_service": //将消息转发到多客服 TransferCustomerServiceResponseMsgModel transferMsg = new TransferCustomerServiceResponseMsgModel() { ToUserName = msgModel.FromUserName, FromUserName = msgModel.ToUserName, CreateTime = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString(), }; res = transferMsg.ToString(); break; case "sub_auto_coupon": //回复订阅自动优惠券处理,MsgValue对应回复的优惠券图文消息ID //SubscribeCouponActHandle sch = new SubscribeCouponActHandle(); SiteActivityDAL dal = new SiteActivityDAL(); SiteActivity activity = dal.GetSiteAct(siteCode, "Coupon"); if (activity != null) { CouponDAL cdal = new CouponDAL(); if (!cdal.ExistCoupon(siteCode, activity.ID, msgModel.FromUserName)) { Coupon coupon = new Coupon() { SiteCode = siteCode, SiteActivityID = activity.ID, OpenID = msgModel.FromUserName, //CouponCode = msgModel.FromUserName, CouponStatus = 0 }; cdal.InsertInfo(coupon); } } CouponNewsDAL nmDAL = new CouponNewsDAL(); CouponNews nm = nmDAL.GetCouponNews(replyMsgValue); if (nm != null) { NewsResponseMsgModel newsModel = new NewsResponseMsgModel() { ToUserName = msgModel.FromUserName, FromUserName = msgModel.ToUserName, CreateTime = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString() }; List <Article> articles = new List <Article>(); articles.Add(new Article() { Title = nm.Title, Description = nm.Description, PicUrl = GetPicUrl(nm.PicUrl), Url = TransformUrl(nm.Url, msgModel) }); newsModel.Articles = articles; res = newsModel.ToString(); } break; case "auto_coupon_category": SiteActivityDAL dalCatList = new SiteActivityDAL(); SiteActivity activityCat = dalCatList.GetSiteAct(siteCode, "Coupon"); if (activityCat != null) { CouponDAL cdal = new CouponDAL(); if (!cdal.ExistCoupon(siteCode, activityCat.ID, msgModel.FromUserName)) { Coupon coupon = new Coupon() { SiteCode = siteCode, SiteActivityID = activityCat.ID, OpenID = msgModel.FromUserName, //CouponCode = msgModel.FromUserName, CouponStatus = 0 }; cdal.InsertInfo(coupon); } } ArticleDAL catDal = new ArticleDAL(); DataSet cdsCat = catDal.GetCategoryList(siteCode, replyMsgValue); if (cdsCat != null && cdsCat.Tables.Count > 0 && cdsCat.Tables[0] != null && cdsCat.Tables[0].Rows.Count > 0) { int i = 0; NewsResponseMsgModel newsModel = new NewsResponseMsgModel() { ToUserName = msgModel.FromUserName, FromUserName = msgModel.ToUserName, CreateTime = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString() }; List <Article> articles = new List <Article>(); foreach (DataRow dr in cdsCat.Tables[0].Rows) { if (++i > 4) { break; } articles.Add(new Article() { Title = dr["Title"].ToString(), Description = dr["Summary"].ToString(), //Description = RemoveHtmlTag(dr["Content"].ToString(), 30), PicUrl = GetPicUrl(dr["Pic"].ToString()), Url = GetArticleUrl(dr["ID"].ToString()) }); } newsModel.Articles = articles; res = newsModel.ToString(); } break; case "auto_news_article": //根据文章自动生成图文消息进行回复,MsgValue为文章ID ArticleDAL aDal = new ArticleDAL(); DataSet ds = aDal.GetArticleDetail(replyMsgValue); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0) { int i = 0; NewsResponseMsgModel newsModel = new NewsResponseMsgModel() { ToUserName = msgModel.FromUserName, FromUserName = msgModel.ToUserName, CreateTime = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString() }; List <Article> articles = new List <Article>(); foreach (DataRow dr in ds.Tables[0].Rows) { if (++i > 4) { break; } articles.Add(new Article() { Title = dr["Title"].ToString(), Description = dr["Summary"].ToString(), //Description = RemoveHtmlTag(dr["Content"].ToString(), 100), PicUrl = GetPicUrl(dr["Pic"].ToString()), Url = GetArticleUrl(dr["ID"].ToString()) }); } newsModel.Articles = articles; res = newsModel.ToString(); } break; case "auto_news_category": //根据类别自动生成图文消息进行回复,MsgValue为类别ID ArticleDAL cDal = new ArticleDAL(); DataSet cds = cDal.GetCategoryList(siteCode, replyMsgValue); if (cds != null && cds.Tables.Count > 0 && cds.Tables[0] != null && cds.Tables[0].Rows.Count > 0) { int i = 0; NewsResponseMsgModel newsModel = new NewsResponseMsgModel() { ToUserName = msgModel.FromUserName, FromUserName = msgModel.ToUserName, CreateTime = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString() }; List <Article> articles = new List <Article>(); foreach (DataRow dr in cds.Tables[0].Rows) { if (++i > 4) { break; } articles.Add(new Article() { Title = dr["Title"].ToString(), Description = dr["Summary"].ToString(), //Description = RemoveHtmlTag(dr["Content"].ToString(), 30), PicUrl = GetPicUrl(dr["Pic"].ToString()), Url = GetArticleUrl(dr["ID"].ToString()) }); } newsModel.Articles = articles; res = newsModel.ToString(); } break; case "coupon": //回复图文表中的消息,MsgValue为图文消息表ID集,用逗号分隔 NewsMsgDAL nmDAL1 = new NewsMsgDAL(); NewsMsg nms = nmDAL1.GetNewsMsg(replyMsgValue); if (nms != null) { NewsResponseMsgModel newsModel = new NewsResponseMsgModel() { ToUserName = msgModel.FromUserName, FromUserName = msgModel.ToUserName, CreateTime = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString() }; List <Article> articles = new List <Article>(); articles.Add(new Article() { Title = nms.Title, Description = nms.Description, PicUrl = GetPicUrl(nms.PicUrl), Url = TransformUrl(nms.Url, msgModel) }); newsModel.Articles = articles; res = newsModel.ToString(); } break; case "news": //回复图文表中的消息,MsgValue为图文消息表ID集,用逗号分隔 NewsMsgDAL nmDALs = new NewsMsgDAL(); IList <NewsMsg> newsMsgs = nmDALs.GetNewsMsgs(replyMsgValue); if (newsMsgs != null) { NewsResponseMsgModel newsModel = new NewsResponseMsgModel() { ToUserName = msgModel.FromUserName, FromUserName = msgModel.ToUserName, CreateTime = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString() }; List <Article> articles = new List <Article>(); foreach (NewsMsg msg in newsMsgs) { articles.Add(new Article() { Title = msg.Title, Description = msg.Description, PicUrl = GetPicUrl(msg.PicUrl), Url = TransformUrl(msg.Url, msgModel) }); } newsModel.Articles = articles; res = newsModel.ToString(); } break; case "url": //根据文章自动生成图文消息进行回复,MsgValue为文章ID DAL.SYS.AccountDAL dalUrl = new DAL.SYS.AccountDAL(); DataSet dsUrl = dalUrl.GetAccountExtData(replyMsgValue); if (dsUrl != null && dsUrl.Tables.Count > 0 && dsUrl.Tables[0] != null && dsUrl.Tables[0].Rows.Count > 0) { int i = 0; NewsResponseMsgModel newsModel = new NewsResponseMsgModel() { ToUserName = msgModel.FromUserName, FromUserName = msgModel.ToUserName, CreateTime = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString() }; List <Article> articles = new List <Article>(); foreach (DataRow dr in dsUrl.Tables[0].Rows) { if (++i > 4) { break; } articles.Add(new Article() { Title = dr["Name"].ToString(), Description = dr["Summary"].ToString(), PicUrl = GetPicUrl(dr["Photo"].ToString()), Url = GetSiteInfo(dr["ID"].ToString()) }); } newsModel.Articles = articles; res = newsModel.ToString(); } break; case "hp_photo_text": //为当前hp_photo对应的照片附加文字信息 PhotoDAL photoDal = new PhotoDAL(); if (photoDal.ExistPhoto(siteCode, msgModel.FromUserName, 0)) { TextRequestMsgModel temp = msgModel as TextRequestMsgModel; string text = temp.Content.Replace("#ms", ""); //附加图片文字 photoDal.UpdateAttachText(siteCode, msgModel.FromUserName, text); TextResponseMsgModel textMsg2 = new TextResponseMsgModel() { ToUserName = msgModel.FromUserName, FromUserName = msgModel.ToUserName, CreateTime = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString(), Content = replyMsgValue == null ? string.Empty : TransformText(replyMsgValue, msgModel) }; res = textMsg2.ToString(); } else { TextResponseMsgModel textMsg2 = new TextResponseMsgModel() { ToUserName = msgModel.FromUserName, FromUserName = msgModel.ToUserName, CreateTime = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString(), Content = "对不起,您暂未参加图片打印活动!" }; res = textMsg2.ToString(); } break; case "hp_photo_ticket": //对当前hp_photo对应的照片进行打印认证 PrintCodeDAL printCodeDAL = new PrintCodeDAL(); TextRequestMsgModel temp1 = msgModel as TextRequestMsgModel; string printCode = temp1.Content.Replace("#dy", ""); string clientID = printCodeDAL.GetClientIDByPrintCode(printCode, siteCode); ExceptionLogDAL.InsertExceptionLog(new ExceptionLog() { Message = clientID }); if (!string.IsNullOrEmpty(clientID)) { PhotoDAL photoDal1 = new PhotoDAL(); photoDal1.UpdatePrintInfo(printCode, clientID, siteCode, msgModel.FromUserName); TextResponseMsgModel textMsg2 = new TextResponseMsgModel() { ToUserName = msgModel.FromUserName, FromUserName = msgModel.ToUserName, CreateTime = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString(), Content = replyMsgValue == null ? string.Empty : TransformText(replyMsgValue, msgModel) }; res = textMsg2.ToString(); //TextResponseMsgModel textMsg2 = new TextResponseMsgModel() //{ // ToUserName = msgModel.FromUserName, // FromUserName = msgModel.ToUserName, // CreateTime = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString(), // Content = "照片打印中,请稍侯..." //}; //res = textMsg2.ToString(); } break; default: break; } } catch (Exception ex) { ExceptionLogDAL.InsertExceptionLog(ex); } return(res); }
/// <summary> /// 图片消息处理 /// </summary> /// <param name="msg"></param> /// <returns></returns> public string ImageMsgReceive(ImageRequestMsgModel msg) { string res = string.Empty; MsgAutoRuleDAL dal = new MsgAutoRuleDAL(); MsgAutoRule rule = dal.GetImageRule(wxConfig.ID); if (rule != null) { switch (rule.MsgType.ToLower()) { case "hp_photo": try { string fileDir = HttpContext.Current.Server.MapPath("/HP_PHOTO/"); if (!Directory.Exists(fileDir)) { Directory.CreateDirectory(fileDir); } ExceptionLog log = new ExceptionLog(); log.Message = weixin.WeiXinConfig.AppId + "}{" + weixin.WeiXinConfig.AppSecret + "}{" + msg.MediaId; ExceptionLogDAL.InsertExceptionLog(log); //string fileName = weixin.SaveAsMedia(msg.MediaId, fileDir); string fileName = weixin.SaveAsFile(msg.PicUrl, fileDir); if (!string.IsNullOrEmpty(fileName)) { Photo p = new Photo() { SiteCode = siteCode, OpenId = msg.FromUserName, Img = fileName }; PhotoDAL photoDal = new PhotoDAL(); photoDal.SaveInfo(p); //回复文本消息 string url = string.Format("{0}/WebService/ImageEdit.aspx?id={1}", GetSiteUrl(), p.ID); string content = string.Format("<a href='{0}'>点击编辑</a>", url); TextResponseMsgModel textMsg = new TextResponseMsgModel() { ToUserName = msg.FromUserName, FromUserName = msg.ToUserName, CreateTime = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString(), Content = content }; res = textMsg.ToString(); } } catch (Exception ex) { ExceptionLogDAL.InsertExceptionLog(ex); } break; case "user_photo": try { string fileDir = HttpContext.Current.Server.MapPath("/USER_PHOTO/"); if (!Directory.Exists(fileDir)) { Directory.CreateDirectory(fileDir); } //string fileName = weixin.SaveAsMedia(msg.MediaId, fileDir); string fileName = weixin.SaveAsFile(msg.PicUrl, fileDir); if (!string.IsNullOrEmpty(fileName)) { UserPhoto photo = new UserPhoto() { Name = fileName, SiteCode = siteCode, OpenId = msg.FromUserName, FilePath = fileName }; UserPhotoDAL uPhotoDal = new UserPhotoDAL(); uPhotoDal.Insert(photo); //回复文本消息 TextResponseMsgModel textMsg = new TextResponseMsgModel() { ToUserName = msg.FromUserName, FromUserName = msg.ToUserName, CreateTime = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString(), Content = rule.MsgValue == null ? string.Empty : TransformText(rule.MsgValue, msg) }; res = textMsg.ToString(); } } catch (Exception ex) { ExceptionLogDAL.InsertExceptionLog(ex); } break; case "user_photo_url": try { string fileDir = HttpContext.Current.Server.MapPath("/USER_PHOTO/"); if (!Directory.Exists(fileDir)) { Directory.CreateDirectory(fileDir); } string fileName = weixin.SaveAsFile(msg.PicUrl, fileDir); if (!string.IsNullOrEmpty(fileName)) { UserPhoto photox = new UserPhoto() { Name = fileName, SiteCode = siteCode, OpenId = msg.FromUserName, FilePath = fileName }; UserPhotoDAL uPhotoDal = new UserPhotoDAL(); uPhotoDal.Insert(photox); //回复文本消息 string url = string.Format("{0}/MicroSite/PhotoPrint.aspx?id={1}", GetSiteUrl(), photox.ID); string content = string.Format("<a href='{0}'>开始打印</a>", url); TextResponseMsgModel textUrlMsg = new TextResponseMsgModel() { ToUserName = msg.FromUserName, FromUserName = msg.ToUserName, CreateTime = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString(), Content = content }; res = textUrlMsg.ToString(); } } catch (Exception ex) { ExceptionLogDAL.InsertExceptionLog(ex); } break; case "user_printphoto_stepone": try { string fileDir = HttpContext.Current.Server.MapPath("/USER_PHOTO/"); if (!Directory.Exists(fileDir)) { Directory.CreateDirectory(fileDir); } string fileName = weixin.SaveAsFile(msg.PicUrl, fileDir); if (!string.IsNullOrEmpty(fileName)) { UserPhoto photox = new UserPhoto() { Name = fileName, SiteCode = siteCode, OpenId = msg.FromUserName, FilePath = fileName }; UserPhotoDAL uPhotoDal = new UserPhotoDAL(); uPhotoDal.Insert(photox); //回复文本消息 string url = string.Format("{0}/MicroSite/PhotoPrintStepOne.aspx?id={1}", GetSiteUrl(), photox.ID); string content = string.Format("<a href='{0}'>开始打印</a>", url); TextResponseMsgModel textUrlMsg = new TextResponseMsgModel() { ToUserName = msg.FromUserName, FromUserName = msg.ToUserName, CreateTime = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString(), Content = content }; res = textUrlMsg.ToString(); } } catch (Exception ex) { ExceptionLogDAL.InsertExceptionLog(ex); } break; default: rule = dal.GetDefaultRule(wxConfig.ID); if (rule != null) { res = ProcessReply(msg, rule.MsgType, rule.MsgValue); } break; } } return(res); }
protected void Page_Load(object sender, EventArgs e) { Dictionary <string, string> sPara = GetRequestPost(); if (sPara.Count > 0)//判断是否有带返回参数 { bool verifyResult = false; AlipayNotify aliNotify = new AlipayNotify(); verifyResult = aliNotify.VerifyNotify(sPara, Request.Form["sign"]); if (verifyResult)//验证成功 { ///////////////////////////////////////////////////////////////////////////////////////////////////////////// //请在这里加上商户的业务逻辑程序代码 //——请根据您的业务逻辑来编写程序(以下代码仅作参考)—— //获取支付宝的通知返回参数,可参考技术文档中服务器异步通知参数列表 //解密(如果是RSA签名需要解密,如果是MD5签名则下面一行清注释掉) //sPara = aliNotify.Decrypt(sPara); //XML解析notify_data数据 try { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(sPara["notify_data"]); //商户订单号 string out_trade_no = xmlDoc.SelectSingleNode("/notify/out_trade_no").InnerText; //支付宝交易号 string trade_no = xmlDoc.SelectSingleNode("/notify/trade_no").InnerText; //交易状态 string trade_status = xmlDoc.SelectSingleNode("/notify/trade_status").InnerText; if (trade_status == "TRADE_FINISHED") { //判断该笔订单是否在商户网站中已经做过处理 //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序 //如果有做过处理,不执行商户的业务程序 //注意: //该种交易状态只在两种情况下出现 //1、开通了普通即时到账,买家付款成功后。 //2、开通了高级即时到账,从该笔交易成功时间算起,过了签约时的可退款时限(如:三个月以内可退款、一年以内可退款等)后。 //微商易业务逻辑 MSProductOrderDAL.UpdateOrderPayState(out_trade_no, "1"); Response.Write("success"); //请不要修改或删除 } else if (trade_status == "TRADE_SUCCESS") { //判断该笔订单是否在商户网站中已经做过处理 //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序 //如果有做过处理,不执行商户的业务程序 //注意: //该种交易状态只在一种情况下出现——开通了高级即时到账,买家付款成功后。 //微商易业务逻辑 MSProductOrderDAL.UpdateOrderPayState(out_trade_no, "1"); Response.Write("success"); //请不要修改或删除 } else { Response.Write(trade_status); } } catch (Exception exc) { ExceptionLog log = new ExceptionLog(); log.Message = "异常:" + exc.Message; ExceptionLogDAL.InsertExceptionLog(log); Response.Write(exc.ToString()); } //——请根据您的业务逻辑来编写程序(以上代码仅作参考)—— ///////////////////////////////////////////////////////////////////////////////////////////////////////////// } else//验证失败 { Response.Write("fail"); } } else { Response.Write("无通知参数"); } }
public override void OnPaySucceed(AliWapPayCallBackInfo info) { ExceptionLog log = new ExceptionLog(); log.Message = string.Format("订单号:{0},支付宝交易号:{1}", info.out_trade_no, info.trade_no); ExceptionLogDAL.InsertExceptionLog(log); if (info.result.ToLower() == "success") { oid = info.out_trade_no; payid = info.trade_no; MSProductOrderDAL ptitleDal = new MSProductOrderDAL(); int paystate = 0; try { paystate = Convert.ToInt32(ptitleDal.GetOrderValueByID("PayState", info.out_trade_no).ToString()); } catch (Exception) { } if (paystate == 0) { bool updatepayway = ptitleDal.UpdateOrderPayWay(info.out_trade_no, "alipay"); bool updateOrderNum = MSProductOrderDAL.UpdateOrderPayState(info.out_trade_no, "1"); MSOrderLogDAL.AddMSOrderLog("订单【" + info.out_trade_no + "】支付成功,支付方式:支付宝支付"); if (updatepayway == true && updateOrderNum == true) { string countcost = string.Empty; string pid = string.Empty; string pname = string.Empty; #region -获取用户数据 string strOpenID = string.Empty; string customerid = string.Empty; try { customerid = ptitleDal.GetOrderValueByID("CustomerID", info.out_trade_no).ToString(); } catch (Exception) { } if (customerid != null && customerid != "") { MSCustomersDAL CustomerDal = new MSCustomersDAL(); try { strOpenID = CustomerDal.GetCustomerValueByID("OpenID", customerid).ToString(); } catch (Exception) { } } #endregion #region -获取产品信息 try { countcost = ptitleDal.GetOrderDetailValueByOID("UnitCost", info.out_trade_no).ToString(); } catch (Exception) { } try { pid = ptitleDal.GetOrderDetailValueByOID("PID", info.out_trade_no).ToString(); } catch (Exception) { } if (pid != null && pid != "") { MSProductDAL ProductDal = new MSProductDAL(); pname = ProductDal.GetMSProductVaueByID("Ptitle", pid).ToString(); } #endregion string strSiteCode = GetSiteCode(); WXConfigDAL dal = new WXConfigDAL(); WeiXinCore.WeiXin wx = WXHelper.CreateWeiXinInstanceBySiteCode(strSiteCode); List <TemplateMessageParam> paramList = new List <TemplateMessageParam>(); paramList.Add(new TemplateMessageParam("first", "我们已收到您的货款,订单号为:" + info.out_trade_no + ";我们将尽快为您打包商品,请耐心等待: )")); paramList.Add(new TemplateMessageParam("orderMoneySum", countcost + " 元")); paramList.Add(new TemplateMessageParam("orderProductName", pname)); paramList.Add(new TemplateMessageParam("Remark", "如有问题请致电400-885-5790或直接在微信留言,小V将第一时间为您服务!")); wx.SendTemplateMessage(strOpenID, "IR3TlAC2Y3lW0jaksuPRwHrVHe5nmbWRcD6ZeUPZPlA", "http://www.vgo2013.com/PalmShop/ShopCode/OrderDetail.aspx?oid=" + info.out_trade_no, paramList.ToArray(), ""); MSOrderLogDAL.AddMSOrderLog("发送模板消息到客户OpenID为【" + strOpenID + "】大致为:我们已收到您的货款" + countcost + "元,产品名称【" + pname + "】我们将尽快为您打包商品,请耐心等待: )"); } } } }
protected void Page_Load(object sender, EventArgs e) { string strChargeType = string.Empty; string strChargeNo = string.Empty; string strChargeAmount = string.Empty; string strOpenID = string.Empty; string strCelWhere = string.Empty; try { if (null == Request.QueryString["openid"]) { if (Session["OpenID"] != null && Session["OpenID"].ToString() != "") { strOpenID = Session["strOpenID"].ToString(); } else { return; } } else { if (Request.QueryString["openid"].ToString().Length > 29 || Request.QueryString["openid"].ToString().Length < 25) { return; } else { strOpenID = Request.QueryString["openid"].ToString(); } } if (null == Request.QueryString["type"]) { return; } else { switch (Request.QueryString["type"].ToString()) { case "0": strChargeType = "话费充值"; break; case "1": strChargeType = "Q币充值"; break; default: strChargeType = "话费充值"; break; } } strChargeNo = Common.Common.NoHtml(Request.Form["ChargeNumber"].ToString()); if (string.IsNullOrEmpty(strChargeNo.Trim()) || strChargeNo == "") { Response.Write("<script>alert('充值号码不能为空!');history.back();</script>"); return; } strChargeAmount = Common.Common.NoHtml(Request.Form["PayFee"].ToString()); string strOtherPay = "0"; if (strChargeType == "话费充值") { strOtherPay = Common.Common.NoHtml(Request.Form["other_price"].Trim()); if (!string.IsNullOrWhiteSpace(strOtherPay)) { strChargeAmount = "其它"; } if (strChargeAmount == "其它") { strChargeAmount = Common.Common.NoHtml(Request.Form["other_price"].ToString()); } } else { strOtherPay = Common.Common.NoHtml(Request.Form["other_QQprice"].Trim()); if (!string.IsNullOrWhiteSpace(strOtherPay)) { strChargeAmount = "其它"; } if (strChargeAmount == "其它") { strChargeAmount = Common.Common.NoHtml(Request.Form["other_QQprice"].ToString()); } } if (string.IsNullOrEmpty(strChargeAmount.Trim()) || strChargeNo == "") { Response.Write("<script>alert('充值金额不能为空!');history.back();</script>"); return; } if (strChargeType == "话费充值") { string strYNLocal = "0691,0692,0870,0871,0872,0873,0874,0875,0876,0877,0878,0879,0883,0886,0887,0888"; string strMobieNO = "134、135、136、137、138、139、147、150、151、152、157、158、159、182、183、184、187、188"; string strMobieCUNO = "130、131、132、145、155、156、185、186"; string strMobieCTNO = "133、153、189、181、180"; strCelWhere = "CMCC"; if (strYNLocal.IndexOf(strChargeNo.Substring(0, 4)) > -1) { strCelWhere = "CT"; } else { if (!IsMobilePhone(strChargeNo)) { Response.Write("<script>alert('请输入正确的缴费号码!');history.back();</script>"); return; } if (strMobieNO.IndexOf(strChargeNo.Substring(0, 3)) > -1) { strCelWhere = "CMCC"; DAL.PublicService.aq_CeleWhere dal = new DAL.PublicService.aq_CeleWhere(); string strLocal = dal.GetLocalStateName(strChargeNo); if (strLocal != "昆明") { Response.Write("<script>alert('移动只能缴昆明本地电话费!');history.back();</script>"); return; } } if (strMobieCUNO.IndexOf(strChargeNo.Substring(0, 3)) > -1) { strCelWhere = "CU"; } if (strMobieCTNO.IndexOf(strChargeNo.Substring(0, 3)) > -1 || strChargeNo.Substring(0, 1) != "1") { strCelWhere = "CT"; } if (strCelWhere != "CMCC") { if (int.Parse(strChargeAmount.Trim()) < 10) { Response.Write("<script>alert('非移动缴费金额不能小于10元!');history.back();</script>"); return; } DAL.PublicService.aq_CeleWhere dal = new DAL.PublicService.aq_CeleWhere(); string strLocal = dal.GetLocalProvinceName(strChargeNo); if (strLocal != "云南") { Response.Write("<script>alert('联通电信只能缴云南省电话费!');history.back();</script>"); return; } } } } else { if (!IsInteger(strChargeNo)) { Response.Write("<script>alert('请输入正确的缴费号码!');history.back();</script>"); return; } } if (strChargeAmount == "其它") { strChargeAmount = Common.Common.NoHtml(Request.Form["other_price"].ToString()); } string text = System.IO.File.ReadAllText(Server.MapPath("../ShopPage/ChargeType.html")); JinianNet.JNTemplate.TemplateContext context = new JinianNet.JNTemplate.TemplateContext(); context.TempData["ChargeType"] = strChargeType; context.TempData["ChargeNo"] = strChargeNo; context.TempData["ChargeAmount"] = strChargeAmount; context.TempData["CelWhere"] = strCelWhere; context.TempData["OpenID"] = strOpenID; JinianNet.JNTemplate.Template t = new JinianNet.JNTemplate.Template(context, text); t.Render(Response.Output); } catch (Exception ex) { Model.SYS.ExceptionLog log = new Model.SYS.ExceptionLog(); log.Message = string.Format("Q币充值出错:" + ex.Message); ExceptionLogDAL.InsertExceptionLog(log); } }
public override void OnPaySucceed(WXJSAPIPayNotifyInfo info) { ExceptionLog log = new ExceptionLog(); log.Message = string.Format("Openid:{0},订单号:{1},附加消息:{2}", info.OpenId, info.OutTradeNo, info.Attach); ExceptionLogDAL.InsertExceptionLog(log); MSProductOrderDAL ptitleDal = new MSProductOrderDAL(); int paystate = 0; try { paystate = Convert.ToInt32(ptitleDal.GetOrderValueByID("PayState", info.OutTradeNo).ToString()); } catch (Exception) { } if (paystate == 0) { bool updatepayway = ptitleDal.UpdateOrderPayWay(info.OutTradeNo, "wxpay"); bool updateOrderNum = MSProductOrderDAL.UpdateOrderPayState(info.OutTradeNo, "1"); MSOrderLogDAL.AddMSOrderLog("订单【" + info.OutTradeNo + "】支付成功,支付方式:微支付"); if (updatepayway == true && updateOrderNum == true) { string countcost = ptitleDal.GetOrderDetailValueByOID("UnitCost", info.OutTradeNo).ToString(); string strSiteCode = "VYIGO"; string pid = string.Empty; string pname = string.Empty; #region -获取产品信息 try { countcost = ptitleDal.GetOrderDetailValueByOID("UnitCost", info.OutTradeNo).ToString(); } catch (Exception) { } try { pid = ptitleDal.GetOrderDetailValueByOID("PID", info.OutTradeNo).ToString(); } catch (Exception) { } if (pid != null && pid != "") { MSProductDAL ProductDal = new MSProductDAL(); pname = ProductDal.GetMSProductVaueByID("Ptitle", pid).ToString(); } #endregion WeiXinCore.WeiXin wx = WXHelper.CreateWeiXinInstanceBySiteCode(strSiteCode); List <TemplateMessageParam> paramList = new List <TemplateMessageParam>(); paramList.Add(new TemplateMessageParam("first", "我们已收到您的货款,订单号为:" + info.OutTradeNo + ";我们将尽快为您打包商品,请耐心等待: )")); paramList.Add(new TemplateMessageParam("orderMoneySum", countcost + " 元")); paramList.Add(new TemplateMessageParam("orderProductName", pname)); paramList.Add(new TemplateMessageParam("Remark", "如有问题请致电400-885-5790或直接在微信留言,小V将第一时间为您服务!")); wx.SendTemplateMessage(info.OpenId, "IR3TlAC2Y3lW0jaksuPRwHrVHe5nmbWRcD6ZeUPZPlA", "http://www.vgo2013.com/PalmShop/ShopCode/OrderDetail.aspx?oid=" + info.OutTradeNo, paramList.ToArray(), ""); MSOrderLogDAL.AddMSOrderLog("发送模板消息到客户OpenID为【" + info.OpenId + "】大致为:我们已收到您的货款" + countcost + "元,产品名称【" + pname + "】我们将尽快为您打包商品,请耐心等待: )"); //JQDialog.SendWeiXinMsg(strSiteCode, info.OpenId, // "您的订单号【" + info.OutTradeNo + "】已于" + // DateTime.Now.ToString("yyyy年MM月dd日 HH:mm:ss") + // "付款成功,支付金额:" + countcost + // "元;在等待卖家发货,详情请进入我的订单查询!"); } } }