public ActionResult ROrderDetail(string orderid) { //----- noncestr = CommonMethod.GetCode(16); string jsapi_ticket = Js_sdk_Signature.IsExistjsapi_ticket(WeChatConfig.IsExistAccess_Token2()); timestamp = DateTime.Now.Ticks.ToString().Substring(0, 10);; string url = Request.Url.ToString().Replace("#", ""); JssdkSignature = Js_sdk_Signature.GetjsSDK_Signature(noncestr, jsapi_ticket, timestamp, url); ViewBag.Appid = WeChatConfig.GetKeyValue("appid"); ViewBag.Uri = WeChatConfig.GetKeyValue("shareurl"); ViewBag.noncestr = noncestr; ViewBag.jsapi_ticket = jsapi_ticket; ViewBag.timestamp = timestamp; ViewBag.PageFlag = "PayOrder"; if (string.IsNullOrEmpty(CommonMethod.getCookie("userid")) || string.IsNullOrEmpty(CommonMethod.getCookie("openid"))) { return(Content("对不起,请登陆系统!")); } var order = orderB.Get(o => o.orderNum == orderid); if (order == null) { return(Content("对不起,这个订单是错误的!")); } return(View(VIEW_TG_order.ToViewModel(order))); }
public ActionResult successPay(string ordernum) { var status = false; var openid = CommonMethod.getCookie("openid"); var userid = CommonMethod.getCookie("userid"); var type = Request["paytype"]; var user = weiUserM.GetModelWithOutTrace(u => u.userNum == userid && u.openid == openid); if (user == null) { return(Content("对不起,请登陆系统!")); } var order = orderB.GetModelWithOutTrace(o => o.orderNum == ordernum); if (order == null) { return(Content("对不起,这个订单是错误的!")); } if (string.IsNullOrEmpty(type)) { //添加交易记录 TG_transactionLog transactionlog = new TG_transactionLog(); transactionlog.userId = userid; transactionlog.openid = openid; transactionlog.tranCate = 0; transactionlog.CateName = "微信消费"; transactionlog.tranMoney = order.yunPrice; transactionlog.tranContent = "微信消费(订单号:" + ordernum + ")消费:" + order.total_fee + " 元,预付:" + order.yunPrice + " 元"; transactionlog.orderNum = ordernum; transactionlog.remark4 = "1001"; transactionlog.AddTime = DateTime.Now; transactionlogB.Add(transactionlog); YX_sysNews sysnew = new YX_sysNews(); sysnew.userid = userid; sysnew.orderId = ordernum; sysnew.newsCate = "订单提醒"; sysnew.newsContent = "用户微信支付成功"; sysnew.newsState = 0; sysnew.Addtime = DateTime.Now; OperateContext.Current.BLLSession.IYX_sysNews_MANAGER.Add(sysnew); Common.Tools.GetPage("https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" + WeChatConfig.IsExistAccess_Token2(), WeChatConfig.GetSubcribePostData(openid, transactionlog.tranContent)); } else if (user.isfenxiao >= 1 && user.userYongJin > order.total_fee) { order.ssh_status = 3; order.ispay = 3; order.yunPrice = order.total_fee; order.payTime = DateTime.Now; orderB.Modify(order, "yunPrice", "payTime", "ispay", "ssh_status"); //添加交易记录 TG_transactionLog transactionlog = new TG_transactionLog(); transactionlog.userId = userid; transactionlog.openid = openid; transactionlog.tranCate = 0; transactionlog.CateName = "微信消费"; transactionlog.tranMoney = order.total_fee; transactionlog.tranContent = "会员微信消费(订单号:" + ordernum + ")消费:" + order.total_fee + " 元"; transactionlog.orderNum = ordernum; transactionlog.remark4 = "1002"; transactionlog.AddTime = DateTime.Now; transactionlogB.Add(transactionlog); user.userYongJin = user.userYongJin - order.total_fee; weiUserM.Modify(user, "userYongJin"); YX_sysNews sysnew = new YX_sysNews(); sysnew.userid = userid; sysnew.orderId = ordernum; sysnew.newsCate = "订单提醒"; sysnew.newsContent = "用户微信支付成功"; sysnew.newsState = 0; sysnew.Addtime = DateTime.Now; OperateContext.Current.BLLSession.IYX_sysNews_MANAGER.Add(sysnew); Common.Tools.GetPage("https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" + WeChatConfig.IsExistAccess_Token2(), WeChatConfig.GetSubcribePostData(openid, transactionlog.tranContent)); } else { } List <string> openids = new List <string>() { "oJUBAv7TVJBowlpJs58qBvCNCrAc", "oJUBAv1jDW_8IQyyvYyTjW2Q6o3w", "oJUBAv9bmEB2mFMSZyLkZBaTK540", "oJUBAv3rjppIvGenkn3h1MIo4wts", "oJUBAv7XiorX2muQXNft5ChU1OCk", "oJUBAv2Omhudt9cyqG_f2A1xMhUA" }; foreach (var item in openids) { Common.Tools.GetPage("https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" + WeChatConfig.IsExistAccess_Token2(), WeChatConfig.GetSubcribePostData(item, "用户: " + user.userRelname + " 已成功预约。\n预约订单号:" + order.orderNum + "\n预约时间:" + order.remark4 + " " + order.remark5 + "\n 联系电话:" + user.userTel)); } return(Redirect("/aoshacar/OrderDetail?orderid=" + ordernum)); }
public ActionResult PayOrder(string orderid) { ViewBag.PageFlag = "PayOrder"; var openid = CommonMethod.getCookie("openid"); var userid = CommonMethod.getCookie("userid"); var user = weiUserM.GetModelWithOutTrace(u => u.userNum == userid && u.openid == openid); if (user == null) { return(Content("对不起,请登陆系统!")); } ViewBag.UserType = user.isfenxiao; ViewBag.userYongJin = user.userYongJin; ViewBag.Userid = userid; ViewBag.Openid = openid; var order = orderB.Get(o => o.orderNum == orderid); if (order == null) { return(Content("对不起,这个订单是错误的!")); } //----- noncestr = CommonMethod.GetCode(16); string jsapi_ticket = Js_sdk_Signature.IsExistjsapi_ticket(WeChatConfig.IsExistAccess_Token2()); timestamp = DateTime.Now.Ticks.ToString().Substring(0, 10);; string url = Request.Url.ToString().Replace("#", ""); JssdkSignature = Js_sdk_Signature.GetjsSDK_Signature(noncestr, jsapi_ticket, timestamp, url); ViewBag.Appid = WeChatConfig.GetKeyValue("appid"); ViewBag.Uri = WeChatConfig.GetKeyValue("shareurl"); ViewBag.noncestr = noncestr; ViewBag.jsapi_ticket = jsapi_ticket; ViewBag.timestamp = timestamp; //微信支付代码 // //httpContext var packageReqHandler = new RequestHandler(HttpContext); packageReqHandler.Init(); //时间戳 payTimeSamp = Senparc.Weixin.MP.TenPayLibV3.TenPayV3Util.GetTimestamp(); //随机字符串 sj = CommonMethod.GetCode(16) + "_" + userid; //设置参数 packageReqHandler.SetParameter("body", "商城-购买支付"); //商品信息 127字符 packageReqHandler.SetParameter("appid", PayConfig.AppId); packageReqHandler.SetParameter("mch_id", PayConfig.MchId); packageReqHandler.SetParameter("nonce_str", sj); packageReqHandler.SetParameter("notify_url", PayConfig.NotifyUrl); packageReqHandler.SetParameter("openid", openid); packageReqHandler.SetParameter("out_trade_no", orderid + "_" + CommonMethod.GetCode(4)); //商家订单号 packageReqHandler.SetParameter("spbill_create_ip", Request.UserHostAddress); //用户的公网ip,不是商户服务器IP packageReqHandler.SetParameter("total_fee", (Convert.ToDouble(order.yunPrice) * 100).ToString()); //商品金额,以分为单位(money * 100).ToString() packageReqHandler.SetParameter("trade_type", "JSAPI"); packageReqHandler.SetParameter("attach", CommonMethod.GetCode(28)); //自定义参数 127字符 string sign = packageReqHandler.CreateMd5Sign("key", PayConfig.AppKey); //第一次签名结果 #region 获取package包====================== packageReqHandler.SetParameter("sign", sign); string data = packageReqHandler.ParseXML();//支付发送的数据 XML格式 string prepayXml = Senparc.Weixin.MP.AdvancedAPIs.TenPayV3.Unifiedorder(data); //string prepayXml = WeiXin.GetPage("https://api.mch.weixin.qq.com/pay/unifiedorder", data); var xdoc = new XmlDocument(); xdoc.LoadXml(prepayXml); XmlNode xn = xdoc.SelectSingleNode("xml"); LogHelper.WriteLog(prepayXml); try { string PrepayId = WeChatConfig.GetXMLstrByKey("prepay_id", xdoc); Package = string.Format("prepay_id={0}", PrepayId); LogHelper.WriteLog(Package); } catch (Exception ex) { LogHelper.WriteLog(ex.ToString()); Package = string.Format("prepay_id={0}", ""); } #endregion #region 设置支付参数 输出页面 该部分参数请勿随意修改 ============== var paySignReqHandler = new RequestHandler(HttpContext); paySignReqHandler.SetParameter("appId", PayConfig.AppId); paySignReqHandler.SetParameter("timeStamp", payTimeSamp); paySignReqHandler.SetParameter("nonceStr", sj); paySignReqHandler.SetParameter("package", Package); paySignReqHandler.SetParameter("signType", "MD5"); PaySign = paySignReqHandler.CreateMd5Sign("key", PayConfig.AppKey); #endregion //--------END ViewBag.payTimeSamp = payTimeSamp; ViewBag.sj = sj; ViewBag.Package = Package; ViewBag.PaySign = PaySign; return(View(VIEW_TG_order.ToViewModel(order))); }
/// <summary> /// 创建菜单 /// </summary> public void CreateMenu() { ButtonGroup bg = new ButtonGroup(); List <WeChatMenus> list = new List <WeChatMenus>(); object CreateMenudt = CacheHelper.GetCache("CreateMenudt");//设置主菜单缓存 防止多次访问数据库 if (CreateMenudt != null) { list = (List <WeChatMenus>)CreateMenudt; } else { list = wechatMenus.GetMainMenus(); if (list.Count > 0) { CacheHelper.SetCache("CreateMenudt", list, TimeSpan.FromMinutes(60)); } } // List <WeChatMenus> childlist = new List <WeChatMenus>(); object childl_ist = CacheHelper.GetCache("childlist");//设置子菜单缓存 防止多次访问数据库V1003_TODAY_MUSIC if (childlist.Count > 0) { childlist = (List <WeChatMenus>)childl_ist; } else { childlist = wechatMenus.GetChildMenus(); if (childlist.Count > 0) { CacheHelper.SetCache("childlist", childlist, TimeSpan.FromMinutes(60)); } } // if (list.Count > 0) { foreach (var item in list) { string menuType = item.WX_MenuType; if (menuType != "0") //一级菜单类型不为0时,创建一级菜单 并赋予事件 { if (menuType == "1") //click菜单 { bg.button.Add(new SingleClickButton() { name = item.WX_menuName, key = item.WX_MenusKey_URL, type = ButtonType.click.ToString(),//默认已经设为此类型,这里只作为演示 }); } else//view菜单 { bg.button.Add(new SingleViewButton() { name = item.WX_menuName, url = item.WX_MenusKey_URL, type = ButtonType.view.ToString(),//默认已经设为此类型,这里只作为演示 }); } } else { var subButton = new SubButton() { name = item.WX_menuName }; foreach (var childitem in childlist) { if (childitem.WX_Fid == item.Id) { if (childitem.WX_MenuType == "1")//click菜单 { subButton.sub_button.Add(new SingleClickButton() { key = childitem.WX_MenusKey_URL, name = childitem.WX_menuName }); } else if (childitem.WX_MenuType == "2")////view菜单 { subButton.sub_button.Add(new SingleViewButton() { url = childitem.WX_MenusKey_URL, name = childitem.WX_menuName }); } else { subButton.sub_button.Add(new SingleClickButton() { key = childitem.WX_MenusKey_URL, name = childitem.WX_menuName }); } } } bg.button.Add(subButton); } } var result = CommonApi.CreateMenu(WeChatConfig.IsExistAccess_Token2(), bg); // var result = CommonApi.CreateMenu(FirstAccess_Token(AppId, Appsecret), bg); } }
/// <summary> /// 事件消息回复 /// </summary> public void responseMsg() { string content = ""; //发送的内容 CreateMenu(); //创建菜单 XmlDocument EventOrNews_XML = GetMsgXML(); string EventName = (object)EventOrNews_XML.SelectSingleNode("xml").SelectSingleNode("Event") == null ? "" : EventOrNews_XML.SelectSingleNode("xml").SelectSingleNode("Event").InnerText; //事件类型 string EventKey = (object)EventOrNews_XML.SelectSingleNode("xml").SelectSingleNode("EventKey") == null ? "" : EventOrNews_XML.SelectSingleNode("xml").SelectSingleNode("EventKey").InnerText; //事件KEY值,与自定义菜单接口中KEY值对应 string MsgType = (object)EventOrNews_XML.SelectSingleNode("xml").SelectSingleNode("MsgType") == null ? "" : EventOrNews_XML.SelectSingleNode("xml").SelectSingleNode("MsgType").InnerText; //消息类型 语音为voice 文本为 text string UserOpenId = EventOrNews_XML.SelectSingleNode("xml").SelectSingleNode("FromUserName").InnerText; LogHelper.WriteLog(UserOpenId); #region 关注 if (!string.IsNullOrEmpty(EventName) && EventName.Trim().ToLower() == "subscribe")//关注 - 事件类型 { //发送图文 string newsTitle2 = "欢迎加入傲鲨汽车生活馆"; string newsDescription2 = "“欢迎加入傲鲨汽车生活馆“ "; string newsPicUrl2 = "http://mmbiz.qpic.cn/mmbiz_jpg/x2FJcrdnw52ibeuGbIOJpiadG3ZjERJZDVewfKaklpxlnMOeM8gdcIKzvtWQXdiaDMibxfibkLWmvBJeicgRdhuwaPOw/640?wx_fmt=jpeg&tp=webp&wxfrom=5&wx_lazy=1"; string newsUrl2 = "http://mp.weixin.qq.com/s/LbQOK2MbaY3pM6eUQfW_sQ"; Senparc.Weixin.MP.Entities.Article arc2 = new Senparc.Weixin.MP.Entities.Article(); arc2.Title = newsTitle2; arc2.Description = newsDescription2; arc2.PicUrl = newsPicUrl2; arc2.Url = newsUrl2; List <Senparc.Weixin.MP.Entities.Article> list2 = new List <Senparc.Weixin.MP.Entities.Article>(); list2.Add(arc2); CustomApi.SendNews(WeChatConfig.IsExistAccess_Token2(), UserOpenId, list2); //发送图文结束 LogHelper.WriteLog("subscribe"); int isfenxiao = 0; // int FId = 0; if (EventKey.Contains("qrscene_"))//、用户通过带有场景值的二维码进行的关注事件 添加分享表 上下级关系 { isfenxiao = 1; string[] Uids = EventKey.Split('_');//获取情景值 LogHelper.WriteLog("进去了" + EventKey + "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" + Uids.Length.ToString()); try { FId = Convert.ToInt32(Uids[1]); } catch { FId = 0; } } Senparc.Weixin.MP.AdvancedAPIs.User.UserInfoJson dic = UserApi.Info(WeChatConfig.IsExistAccess_Token2(), UserOpenId); if (weiuserB.GetListasNoTrackingBy(w => w.openid == dic.openid).Count <= 0) { var wechatuser = new MODEL.YX_weiUser(); wechatuser.subscribe = dic.subscribe; wechatuser.openid = dic.openid; wechatuser.nickname = dic.nickname; wechatuser.sex = dic.sex; wechatuser.U_language = dic.language; wechatuser.city = dic.city; wechatuser.province = dic.province; wechatuser.country = dic.country; wechatuser.headimgurl = dic.headimgurl; wechatuser.subscribe_time = DateTime.Now; wechatuser.userSex = dic.sex == 2 ? "女" : "男"; wechatuser.userNum = Common.Tools.Get8Digits(); wechatuser.F_id = 0; wechatuser.isfenxiao = 0; wechatuser.userMoney = 0; wechatuser.userYongJin = 0; wechatuser.TREE_NODE_ID = "144e42158f676695"; weiuserB.Add(wechatuser); } } #endregion #region 其他 if (!string.IsNullOrEmpty(EventName) && EventName.Trim().ToLower() == "unsubscribe")//取消订阅。 { // UserBll.upState(UserOpenId, 1, 0);//修改当前状态 } if (!string.IsNullOrEmpty(MsgType) && MsgType.Trim().ToLower() == "voice") { } if (!string.IsNullOrEmpty(MsgType) && MsgType.Trim().ToLower() == "image") { string touser = UserOpenId; string fromuser = EventOrNews_XML.SelectSingleNode("xml").SelectSingleNode("ToUserName").InnerText; string CreateTime = EventOrNews_XML.SelectSingleNode("xml").SelectSingleNode("CreateTime ").InnerText; HttpContext.Current.Response.Write(GetKeFuXML(touser, fromuser, CreateTime)); } #region CliCK if (!string.IsNullOrEmpty(EventName) && EventName.Trim().ToLower() == "click")//菜单单击事件 { LogHelper.WriteLog("click"); List <WeChatMenus> ClickMenus = new List <WeChatMenus>(); object ClickMenusList = CacheHelper.GetCache("ClickMenusList");//设置单击菜单缓存 防止多次访问数据库 if (ClickMenusList != null) { ClickMenus = (List <WeChatMenus>)ClickMenusList; } else { ClickMenus = wechatMenus.GetClickMenus(); if (ClickMenus != null) { CacheHelper.SetCache("ClickMenusList", ClickMenus, TimeSpan.FromMinutes(60)); } } foreach (var item in ClickMenus) { if (!string.IsNullOrEmpty(EventName) && EventKey.Trim().ToUpper() == item.WX_MenusKey_URL.ToUpper()) { string flat1 = item.flat1.ToString(); //用于匹配那张消息表:例如,YX_text YX_news YX_image等 int Id = item.Id; // string tableName = ""; //表名 switch (flat1) { case "1": tableName = "YX_text"; break; case "2": tableName = "YX_news"; break; case "3": tableName = "YX_image"; break; case "4": tableName = "YX_voice"; break; case "5": tableName = "YX_video"; break; case "6": tableName = "YX_music"; break; } if (tableName == "YX_text")//发送文本消息 { LogHelper.WriteLog(Id.ToString()); LogHelper.WriteLog("YX_text-" + EventKey); MODEL.ViewModel.VIEW_YX_text textdt = new MODEL.ViewModel.VIEW_YX_text(); object text_dt = CacheHelper.GetCache(EventKey);//设置主菜单缓存 防止多次访问数据库V1003_TODAY_MUSIC if (text_dt != null) { textdt = (MODEL.ViewModel.VIEW_YX_text)text_dt; } else { textdt = textM.GetClickMenusText(Id); if (textdt != null) { CacheHelper.SetCache(EventKey, textdt, TimeSpan.FromMinutes(60)); } } if (textdt != null) { string msgContent = textdt.msgContent; Common.Tools.GetPage("https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" + WeChatConfig.IsExistAccess_Token2(), GetSubcribePostData(UserOpenId, msgContent)); } } if (tableName == "YX_news")//发送图文消息 { LogHelper.WriteLog("YX_news-" + EventKey); MODEL.ViewModel.VIEW_YX_news newsdt = new MODEL.ViewModel.VIEW_YX_news(); object news_dt = CacheHelper.GetCache(EventKey);//设置主菜单缓存 防止多次访问数据库V1003_TODAY_MUSIC if (news_dt != null) { newsdt = (MODEL.ViewModel.VIEW_YX_news)news_dt; } else { newsdt = newsM.GetClickMenusNews(Id); if (newsdt != null) { CacheHelper.SetCache(EventKey, newsdt, TimeSpan.FromMinutes(60)); } } if (newsdt != null) { string newsTitle = newsdt.newsTitle; string newsDescription = newsdt.newsDescription; string newsPicUrl = newsdt.newsPicUrl; string newsUrl = newsdt.newsUrl; Senparc.Weixin.MP.Entities.Article arc = new Senparc.Weixin.MP.Entities.Article(); arc.Title = newsTitle; arc.Description = newsDescription; arc.PicUrl = newsPicUrl; arc.Url = newsUrl; List <Senparc.Weixin.MP.Entities.Article> list = new List <Senparc.Weixin.MP.Entities.Article>(); list.Add(arc); CustomApi.SendNews(WeChatConfig.IsExistAccess_Token2(), UserOpenId, list); } } if (tableName == "YX_image")//发送图片消息 { //DataTable imagedt = new DataTable(); //imagedt = wxdb.GetClickMenusMsg(tableName, Id); //if (imagedt != null) //{ //} } if (tableName == "YX_voice")//发送语音消息 { //DataTable voicedt = new DataTable(); //voicedt = wxdb.GetClickMenusMsg(tableName, Id); } if (tableName == "YX_video")//发送视频消息 { //DataTable videodt = new DataTable(); //videodt = wxdb.GetClickMenusMsg(tableName, Id); } if (tableName == "YX_music")//发送音乐消息 { //DataTable musicdt = new DataTable(); //musicdt = wxdb.GetClickMenusMsg(tableName, Id); } } } } #endregion if (!string.IsNullOrEmpty(EventName) && EventName.Trim().ToLower() == "scancode_push")//菜单单击事件 { LogHelper.WriteLog("scancode_push"); } #endregion }
public ActionResult FinishOrder(VIEW_TG_order model) { var order = orderB.GetModelWithOutTrace(o => o.orderNum == model.orderNum); bool status = false; try { var user = userB.GetModelWithOutTrace(u => u.userNum == order.UserId); if (Request["ONLINE"] != null && order != null && user != null) { if (model.total_fee <= 0) { return(this.JsonFormat("SYSERROR", status, "订单的金额不正确")); } if (user.userYongJin < model.total_fee) { return(this.JsonFormat("SYSERROR", status, "用户的余额不足")); } else if (order.ispay < 3) { order.total_fee = model.total_fee; order.yunPrice = model.yunPrice; order.ispay = 3; order.ssh_status = 3; order.payTime = DateTime.Now; order.remark5 = model.remark5; order.remark6 = model.remark6; orderB.Modify(order, "total_fee", "yunPrice", "ispay", "ssh_status", "payTime", "remark5", "remark6"); user.userYongJin = user.userYongJin - order.total_fee; userB.Modify(user, "userYongJin"); //添加交易记录 TG_transactionLog transactionlog = new TG_transactionLog(); transactionlog.userId = user.userNum; transactionlog.openid = user.openid; transactionlog.tranCate = 0; transactionlog.CateName = "到店消费"; transactionlog.tranMoney = order.total_fee; transactionlog.tranContent = "到店消费(订单号:" + order.orderNum + ")消费:" + order.total_fee + " 元"; transactionlog.orderNum = order.orderNum; transactionlog.remark4 = "1003"; transactionlog.AddTime = DateTime.Now; transactionlogB.Add(transactionlog); if (model.IsNotice) { Common.Tools.GetPage("https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" + WeChatConfig.IsExistAccess_Token2(), WeChatConfig.GetSubcribePostData(user.openid, transactionlog.tranContent)); } status = true; } else { status = true; return(this.JsonFormat("/Admin/Order/OrderDetail?ordernum=" + model.orderNum, status, "该订单已经支付了!", true, "SYSSUCCESS")); } } } catch (Exception ex) { return(this.JsonFormat(status, !status, ex.Message + ex.StackTrace)); } return(this.JsonFormat("/Admin/Order/OrderDetail?ordernum=" + model.orderNum, status, "支付成功!", true, "SYSSUCCESS")); }