public ActionResult WeixinPayNotifyUrl()
        {
            Stream       st       = Request.InputStream;
            StreamReader sr       = new StreamReader(st);
            string       SRstring = sr.ReadToEnd();

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(SRstring);
            sr.Close();

            string return_code = doc.GetElementsByTagName("return_code")[0].InnerText;

            //如果返回成功
            if (return_code == "SUCCESS")
            {
                string result_code = doc.GetElementsByTagName("result_code")[0].InnerText;
                if (result_code == "SUCCESS")
                {
                    IOrderBLL orderBll = BLLFactory <IOrderBLL> .GetBLL("OrderBLL");

                    string orderNo = doc.GetElementsByTagName("out_trade_no")[0].InnerText;
                    var    order   = orderBll.GetEntity(o => o.PayTradeNo == orderNo);
                    if (order != null && order.OrderStatus == ConstantParam.OrderStatus_NOPAY)
                    {
                        //获取商家账户信息
                        var wxAccount = order.Shop.ShopAccounts.Where(a => a.AccountType == ConstantParam.PROPERTY_ACCOUNT_WeChat).FirstOrDefault();
                        if (wxAccount != null)
                        {
                            //获取商家账户信息
                            string WeixinPayKey = wxAccount.AccountKey;
                            //组装签名字符串
                            StringBuilder signStr = new StringBuilder();
                            signStr.Append("appid=" + doc.GetElementsByTagName("appid")[0].InnerText + "&");
                            signStr.Append("bank_type=" + doc.GetElementsByTagName("bank_type")[0].InnerText + "&");
                            signStr.Append("cash_fee=" + doc.GetElementsByTagName("cash_fee")[0].InnerText + "&");
                            signStr.Append("fee_type=" + doc.GetElementsByTagName("fee_type")[0].InnerText + "&");
                            signStr.Append("is_subscribe=" + doc.GetElementsByTagName("is_subscribe")[0].InnerText + "&");
                            signStr.Append("mch_id=" + doc.GetElementsByTagName("mch_id")[0].InnerText + "&");
                            signStr.Append("nonce_str=" + doc.GetElementsByTagName("nonce_str")[0].InnerText + "&");
                            signStr.Append("openid=" + doc.GetElementsByTagName("openid")[0].InnerText + "&");
                            signStr.Append("out_trade_no=" + orderNo + "&");
                            signStr.Append("result_code=" + result_code + "&");
                            signStr.Append("return_code=" + return_code + "&");
                            signStr.Append("time_end=" + doc.GetElementsByTagName("time_end")[0].InnerText + "&");
                            signStr.Append("total_fee=" + doc.GetElementsByTagName("total_fee")[0].InnerText + "&");
                            signStr.Append("trade_type=" + doc.GetElementsByTagName("trade_type")[0].InnerText + "&");
                            signStr.Append("transaction_id=" + doc.GetElementsByTagName("transaction_id")[0].InnerText + "&");
                            signStr.Append("key=" + WeixinPayKey);
                            string sign = PropertyUtils.GetMD5Str(signStr.ToString()).ToUpper();
                            //签名验证成功
                            if (doc.GetElementsByTagName("sign")[0].InnerText == sign)
                            {
                                //更新订单状态
                                order.OrderStatus = ConstantParam.OrderStatus_RECEIPT;
                                order.PayWay      = 1;
                                order.PayDate     = DateTime.Now;
                                if (orderBll.Update(order))
                                {
                                    IShopBLL shopBLL = BLLFactory <IShopBLL> .GetBLL("ShopBLL");

                                    var ShopUserId = shopBLL.GetEntity(s => s.Id == order.ShopId).ShopUserId;

                                    //推送给订单所属商家
                                    IShopUserPushBLL userPushBLL = BLLFactory <IShopUserPushBLL> .GetBLL("ShopUserPushBLL");

                                    var userPush = userPushBLL.GetEntity(p => p.UserId == ShopUserId);
                                    if (userPush != null)
                                    {
                                        string registrationId = userPush.RegistrationId;
                                        string alert          = "订单号为" + order.OrderNo + "的订单已支付,点击查看详情";
                                        //通知信息
                                        PropertyUtils.SendPush("订单支付通知", alert, ConstantParam.MOBILE_TYPE_SHOP, registrationId);
                                    }
                                }
                            }
                        }
                    }
                    return(Content("success"));
                }
            }
            return(Content("fail"));
        }
Exemple #2
0
        public ApiResultModel Login(OwnerLoginModel model)
        {
            ApiResultModel resultModel = new ApiResultModel();

            try
            {
                //根据用户名查找用户
                IShopUserBLL shopUserBll = BLLFactory <IShopUserBLL> .GetBLL("ShopUserBLL");

                var user = shopUserBll.GetEntity(u => u.UserName == model.UserName && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT);

                //1.判断用户名是否正确
                if (user == null)
                {
                    resultModel.Msg = APIMessage.NAME_ERROR;
                    return(resultModel);
                }

                //2.判断密码是否正确
                string md5Str = PropertyUtils.GetMD5Str(model.Password);
                if (user.Password != md5Str)
                {
                    resultModel.Msg = APIMessage.PWD_ERROR;
                    return(resultModel);
                }

                //产生随机令牌
                var token = System.Guid.NewGuid().ToString("N");
                //更新用户令牌和最近登录时间及Token失效时间
                user.Token            = token;
                user.LatelyLoginTime  = DateTime.Now;
                user.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid")));
                shopUserBll.Update(user);

                //返回登录用户的ID和用户名以及令牌
                resultModel.result = new
                {
                    token        = token,
                    userId       = user.Id,
                    userName     = user.UserName,
                    IsCreateShop = user.Shops.Count > 0,
                    ShopId       = user.Shops.FirstOrDefault() == null ? -1 : user.Shops.FirstOrDefault().Id,
                    IsGreenType  = user.Shops.FirstOrDefault() == null ? false : user.Shops.FirstOrDefault().Type.Contains(ConstantParam.SHOP_TYPE_0.ToString())
                };

                //推送设备管理
                IShopUserPushBLL userPushBll = BLLFactory <IShopUserPushBLL> .GetBLL("ShopUserPushBLL");

                var userPush  = userPushBll.GetEntity(p => p.UserId == user.Id);
                var userPush1 = userPushBll.GetEntity(p => p.RegistrationId == model.RegistrationId);
                if (userPush != null)
                {
                    userPush.RegistrationId = model.RegistrationId;
                    userPushBll.Update(userPush);
                }
                else if (userPush1 != null)
                {
                    userPush1.UserId = user.Id;
                    userPushBll.Update(userPush1);
                }
                else
                {
                    userPush = new T_ShopUserPush()
                    {
                        UserId         = user.Id,
                        RegistrationId = model.RegistrationId
                    };
                    userPushBll.Save(userPush);
                }
            }
            catch
            {
                resultModel.Msg = APIMessage.REQUEST_EXCEPTION;
            }
            return(resultModel);
        }