예제 #1
0
        /// <summary>
        /// 处理订单响应结果
        /// </summary>
        public void BackHandle(HttpRequestBase req, HttpResponseBase resp)
        {
            try
            {
                //1.获取响应内容
                XmlReader   reader = XmlReader.Create(req.InputStream);
                XmlDocument doc    = new XmlDocument();
                doc.Load(reader);

                LogOperate.Write(doc.InnerXml);
                PayBackResult result = new PayBackResult();
                LoadXmlToObject(doc, result);
                //处理结果
                if (result.Result_Code.ToUpper() == "SUCCESS")
                {
                    resp.Write(@"<xml>
                      <return_code><![CDATA[SUCCESS]]></return_code>
                      <return_msg><![CDATA[OK]]></return_msg>
                    </xml>");
                    resp.End();

                    //处理支付成功结果
                    OnPaySuccess?.Invoke(result);
                }
            }
            catch (Exception ex)
            {
                LogOperate.Write(ex);
                throw ex;
            }
        }
예제 #2
0
        /*
         * access_token是公众号的全局唯一票据,公众号调用各接口时都需使用access_token。开发者需要进行妥善保存。
         * access_token的存储至少要保留512个字符空间。
         * access_token的有效期目前为2个小时,需定时刷新,重复获取将导致上次获取的access_token失效。
         */
        /// <summary>
        /// 调用接口,获取access_token
        /// </summary>
        public static void RequestAccessToken()
        {
            string url = new LinkManage().GetAccessToken();

            try
            {
                string           result = NetHelper.Get(url);
                Access_TokenData _data  = result.JsonDeserialezer <Access_TokenData>();
                if (string.IsNullOrEmpty(_data.access_token) == false)
                {
                    //获取成功
                    AccessToken = _data.access_token;
                    NextTime    = DateTime.Now.AddSeconds(_data.expires_in - 10);
                    //测试代码
                    LogOperate.Write("获取access_token成功:" + AccessToken);
                }
                else
                {
                    throw new Exception("反序列化Access_TokenData对象失败:" + result);
                }
            }
            catch (Exception ex)
            {
                LogOperate.Write("获取AccessToken失败," + ex.Message);
                if ((DateTime.Now - NextTime).TotalMinutes >= 10)
                {
                    EnableRun = false;
                }
                NextTime = DateTime.Now;
            }
        }
예제 #3
0
 /// <summary>
 /// 获取jsapi_ticket
 /// 1.有效期为7200秒
 /// </summary>
 public static void RequestJsApi_Ticket()
 {
     try
     {
         string  url    = new LinkManage().GetJsApi_Ticket();
         string  result = NetHelper.Get(url);
         JObject obj    = JObject.Parse(result);
         try
         {
             string ticket = (string)obj["ticket"];
             if (string.IsNullOrEmpty(ticket) == false)
             {
                 Jsapi_Ticket = ticket;
                 return;
             }
             throw new Exception("获取ticket为空");
         }
         catch (Exception ex)
         {
             throw new Exception("反序列化获取jsapi_ticket失败," + ex.Message + ",返回内容:" + result);
         }
     }
     catch (Exception ex)
     {
         LogOperate.Write("获取jsapi_ticket失败," + ex.Message);
         if ((DateTime.Now - NextTime).TotalMinutes >= 10)
         {
             EnableRun = false;
         }
         NextTime = DateTime.Now;
     }
 }
예제 #4
0
        /// <summary>
        /// 签名处理------统一下单---key不处理大小写
        /// </summary>
        /// <param name="dic"></param>
        /// <returns></returns>
        public static string GetPaySign(Dictionary <string, string> dic)
        {
            ConfigInfo config = ConfigInfo.GetInfo();

            string[] tempList = dic.OrderBy(q => q.Key).Select(q => q.Key + "=" + q.Value).ToArray();
            string   signTemp = string.Join("&", tempList);

            //追加apikey
            signTemp += "&key=" + config.APIKey;

            LogOperate.Write(signTemp);
            return(Common.SecurityHelper.MD5(signTemp));
        }
예제 #5
0
        /// <summary>
        /// 创建订单
        /// </summary>
        public void CreateOrder(string orderid, decimal amount, string openid, string trade_type = "JSAPI", string body = "测试下单")
        {
            try
            {
                OrderInfo order = new OrderInfo();
                order.Out_Trade_No     = orderid;
                order.Total_Fee        = Convert.ToInt32(amount * 100);
                order.Spbill_create_ip = GetWebClientIp();
                order.OpenID           = openid;
                //根据客户端确定是否类型
                order.Trade_Type = trade_type;
                //回调地址
                order.Notify_Url = BackHandleUrl;
                order.Attach     = "竹笛舰店";
                order.Body       = body;
                //签名处理
                order.Sign = ConfigInfo.GetSign(GetSendDic(order));
                string data = GetSendData(order);
                //LogOperate.Write("所有请求参数:" + data);
                //提交请求
                string result = NetHelper.Post(_link.GetPayUnifiedOrder(), data);
                //LogOperate.Write(result);
                if (string.IsNullOrEmpty(result))
                {
                    throw new Exception("微信服务器响应结果为空");
                }


                //读取返回的Xml数据结果
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(result);
                OrderResult orderResult = new OrderResult();
                LoadXmlToObject(doc, orderResult);
                if (orderResult.Return_Code.ToUpper() == "SUCCESS" && orderResult.Result_Code.ToUpper() == "SUCCESS")
                {
                    LogHelper.Debug("下单成功后发出" + orderResult.Code_Url + "_" + orderResult.Return_Code);
                    //下单成功后出发
                    OnCreateOrderSuccess?.Invoke(orderResult);
                }
                else
                {
                    throw new Exception($"统一下单失败{orderResult.Err_Code}:" + orderResult.Err_Code_Des);
                }
            }
            catch (Exception ex)
            {
                LogOperate.Write(ex);
                throw ex;
            }
        }
예제 #6
0
 /// <summary>
 /// 修改配置信息
 /// </summary>
 /// <returns></returns>
 public static void UpdateInfo(ConfigInfo con)
 {
     config = con;
     //序列化到磁盘
     try
     {
         //保存到磁盘
         string filename = ConfigValue.DataPath + "wxconfig.xml";
         XmlSerializerHelper _serialize = new XmlSerializerHelper(filename);
         _serialize.Serialize <ConfigInfo>(con);
     }
     catch (Exception ex)
     {
         LogOperate.Write("序列化配置配置信息异常," + ex.Message);
     }
 }
예제 #7
0
 /// <summary>
 /// 获取配置信息
 /// </summary>
 /// <returns></returns>
 public static ConfigInfo GetInfo()
 {
     try
     {
         //从磁盘加载对象
         string filename = ConfigValue.DataPath + "wxconfig.xml";
         XmlSerializerHelper _serialize = new XmlSerializerHelper(filename);
         ConfigInfo          config     = _serialize.Deserialize <ConfigInfo>();
         return(config);
     }
     catch (Exception ex)
     {
         LogOperate.Write("加载 ConfigInfo 失败," + ex.Message);
         throw new Exception("加载微信配置文件失败", ex);
     }
 }
예제 #8
0
        /// <summary>
        /// 保存用户信息--非供应商
        /// </summary>
        /// <param name="target"></param>
        /// <returns></returns>
        public ActionResult Save_One(string Code, string NickName, string LoginPwd, string Pwd2, string RecommendCode, string smscode)
        {
            try
            {
                LogOperate.Write("注册开始:" + CookieHelper.GetCookieValue("headimgurl"));
                //判断手机验证码
                if (!DB.XmlConfig.XmlSite.IsJiHuo)
                {
                    string code = Session["smscode"] as string;
                    if (string.IsNullOrEmpty(code))
                    {
                        throw new Exception("验证码过期");
                    }
                    if (code != ReqHelper.GetString("smscode"))
                    {
                        throw new Exception("验证码不正确");
                    }
                }

                //if (DB.XmlConfig.XmlSite.IsJiHuo)
                //{
                //var code = Tools.getCookie("gif");
                //if (string.IsNullOrEmpty(code))
                //    throw new Exception("验证码过期");
                //if (code != smscode)
                //    throw new Exception("验证码不正确");

                //}
                var DataBase = new Member_Info();
                DataBase.Code             = Code;
                DataBase.NickName         = NickName;
                DataBase.LoginPwd         = LoginPwd;
                DataBase.Pwd2             = Pwd2;
                DataBase.RecommendCode    = RecommendCode;
                DataBase.CreateMemberId   = "00";
                DataBase.CreateMemberName = "admin";
                DataBase.CreateTime       = DateTime.Now;
                //赋值省市区
                if (DataBase.ProvId != null)
                {
                    DataBase.ProvName = DB.Area_Province.FindEntity(DataBase.ProvId).name;
                }
                if (DataBase.CityId != null)
                {
                    DataBase.CityName = DB.Area_City.FindEntity(DataBase.CityId).name;
                }
                if (DataBase.CountyId != null)
                {
                    DataBase.CountyName = DB.Area_County.FindEntity(DataBase.CountyId).name;
                }
                DataBase.Code   = DataBase.Code.Trim();
                DataBase.Mobile = DataBase.Mobile;
                var json = DB.Member_Info.Save(DataBase, Enums.LoginType.nologin, "", "", 0, 0, 0, 0);
                if (json.Status == "n")
                {
                    return(Error(json.Msg));
                }
                else
                {
                    //重新保存cookie
                    User_Shop.SetUser(DataBase);
                    return(Success("注册成功"));
                }
            }
            catch (Exception ex)
            {
                LogOperate.Write(ex);
                return(Error(ex));
            }
        }
예제 #9
0
        public ActionResult OAuthHandle()
        {
            ConfigInfo  config = ConfigInfo.GetInfo();
            OAuthManage _oauth = new OAuthManage(config.AppID, config.AppSecret, new LinkManage().GetUserOAthHandle());

            string recirecturl = Url_Shop.GetRecirectUrl();

            LogHelper.Debug("OAuthHandle-redirecturl:" + recirecturl);
            string result = "";

            try
            {
                //注册事件处理
                _oauth.OnError = (e) =>
                {
                    string    msg   = "";
                    Exception inner = e;
                    while (inner != null)
                    {
                        msg  += inner.Message;
                        inner = inner.InnerException;
                    }
                    result = msg;
                    LogOperate.Write(msg);
                };
                _oauth.OnGetTokenSuccess = (token) =>
                {
                    result += "<br/>";
                    result += token.ToJsonString();
                    LogOperate.Write("获取token成功:" + result);
                };
                //特别处理获取用户信息成功
                _oauth.OnGetUserInfoSuccess = (user) =>
                {
                    result += "<br/>";
                    result += user.ToJsonString();
                    CookieHelper.SetCookie("openid", user.openid, 1);
                    CookieHelper.SetCookie("nickname", user.nickname, 1);
                    CookieHelper.SetCookie("headimgurl", user.headimgurl, 1);
                    //判断openid的用户是否存在
                    Member_Info model = DB.Member_Info.GetModelByOpenID(user.openid);
                    if (model != null)
                    {
                        //保存信息到客户端同步登录
                        User_Shop.SetUser(model);
                    }
                    else
                    {
                        if (model == null)
                        {
                            //如果是游客,返回登录
                            if (string.IsNullOrEmpty(recirecturl))
                            {
                                recirecturl = $"http://{Request.Url.Host}/mobile/login";
                            }
                        }
                        else
                        {
                            model.OpenID = user.openid;
                            if (string.IsNullOrEmpty(model.NickName))
                            {
                                model.NickName = user.nickname;
                            }
                            model.Photo = user.headimgurl;
                            DB.Member_Info.Update(model);

                            //保存信息到客户端同步登录
                            User_Shop.SetUser(model);
                            recirecturl = Url_Mobile.GetUserCenter();
                        }
                    }
                };
                //第二步
                _oauth.GetAccess_Token();
                //第三步
                _oauth.GetUserInfo();
                //显示结果
                ViewBag.msg = result;

                if (string.IsNullOrEmpty(recirecturl))
                {
                    recirecturl = $"http://{Request.Url.Host}/mobile";
                }

                return(Redirect(recirecturl));
            }
            catch (Exception ex)
            {
                string    msg   = "";
                Exception inner = ex;
                while (inner != null)
                {
                    msg  += inner.Message;
                    inner = inner.InnerException;
                }
                return(Content(result + "----->" + msg + "<br />" + ex.StackTrace));
            }
        }