Beispiel #1
0
        private OpResult GetCompanyPayInfo(int cid, string storeid, int apicode, out string mapCid, bool isCallback = false)
        {
            mapCid = string.Empty;
            var _cid   = cid.ToString();
            var entity = new PayConfiguration();

            if (!isCallback)
            {
                entity = PayConfigurationService.Find(o => o.CompanyId == cid && o.State == 1 && apicode == o.PayType);
            }
            else
            {
                entity = PayConfigurationService.Find(o => o.PaymentMerchantNumber == _cid && o.State == 1 && apicode == o.PayType);
            }
            if (entity != null)
            {
                var storeEntity = new StorePaymentAuthorization();
                if (isCallback)
                {
                    storeEntity = StorePaymentAuthorizationService.Find(o => o.CompanyId == entity.CompanyId && o.MapPaymentStoreId == storeid && o.PayType == apicode && o.State == 1);
                }
                else
                {
                    storeEntity = StorePaymentAuthorizationService.Find(o => o.CompanyId == entity.CompanyId && o.StoreId == storeid && o.PayType == apicode && o.State == 1);
                }
                if (storeEntity != null)
                {
                    //return OpResult.Success(entity.SecurityKey);
                    OpResult result = new OpResult()
                    {
                        Successed = true,
                        Message   = entity.SecurityKey,
                        Data      = storeEntity.MapPaymentStoreId
                    };
                    if (!isCallback)
                    {
                        mapCid = entity.PaymentMerchantNumber;
                    }
                    else
                    {
                        mapCid = entity.CompanyId.ToString();
                    }
                    return(result);
                }
                else
                {
                    return(OpResult.Fail("门店未开通授权支付!"));
                }
            }
            else
            {
                return(OpResult.Fail("商户未开通授权支付!"));
            }
        }
Beispiel #2
0
        public object TradeNotify([FromBody] JObject obj)
        {
            //更新会员积分信息
            var charset   = obj.Property("charset", true);
            var cid       = Convert.ToInt32(obj.Property("mch_id", true)); //
            var storeId   = obj.Property("store_id", true);                //门店
            var orderSN   = obj.Property("out_trade_no", true);            //单号
            var amount    = obj.Property("receipt_amount", true);          //支付金额
            var payState  = obj.Property("pay_status", true);              //notpay=支付中;paysuccess=支付成功;payfail=支付失败;paycancel=已撤销;paytimeout=支付超时
            var tradeDate = obj.Property("trade_date", true);              //支付时间
            var channel   = obj.Property("pay_channel", true);             //支付渠道
            var deviceId  = obj.Property("device_id", true);               //设备编号
            var signType  = obj.Property("sign_type", true);
            var sign      = obj.Property("sign", true);
            var version   = obj.Property("version", true);
            var method    = obj.Property("method", true);

            //验证签名
            var reqParams = new SortedDictionary <string, object>();

            reqParams.Add("charset", charset);
            reqParams.Add("method", PayConst.QCTTRADE_NOTIFY_PAY);
            reqParams.Add("mch_id", cid);
            reqParams.Add("store_id", storeId);
            reqParams.Add("device_id", deviceId);
            reqParams.Add("sign_type", signType);
            reqParams.Add("version", version);
            reqParams.Add("out_trade_no", orderSN);
            reqParams.Add("receipt_amount", amount);
            reqParams.Add("pay_status", payState);
            reqParams.Add("pay_channel", channel);
            reqParams.Add("trade_date", tradeDate);

            string mapcid = string.Empty;

            //查询门店支付授权
            var authorization = GetCompanyPayInfo(cid, storeId, PayConst.QCTAPICODE_P, out mapcid, true);
            int _cid          = Convert.ToInt32(mapcid);

            if (!authorization.Successed)
            {
                throw new MessageException("门店信息错误");
            }
            var alias = new string[1];
            //签名
            string localsign = PayHelper.Sign(reqParams, authorization.Message);

            if (localsign == sign)
            {
                if (payState == "PAYSUCCESS")
                {
                    var localStore = StorePaymentAuthorizationService.Find(o => o.CompanyId == _cid && o.MapPaymentStoreId == storeId && o.PayType == PayConst.QCTAPICODE_P && o.State == 1);
                    if (localStore == null)
                    {
                        throw new MessageException("未找到门店授权信息!");
                    }
                    //更新支付记录
                    var data = AppPaymentRecordsService.Find(o => o.CompanyId == _cid && o.StoreId == localStore.StoreId && o.OrderSN == orderSN);
                    if (data != null)
                    {
                        if (data.State == 1)
                        {
                            goto gotoReturn;
                        }
                        data.State      = 1;
                        alias[0]        = data.Alias;
                        data.PayChannel = channel;
                        data.ReturnData = obj.ToString();
                        AppPaymentRecordsService.Update(data);
                    }
                    //更新会员信息
                    var records = IntegralFlowsService.FindList(o => o.FlowSN == orderSN && o.CompanyId == cid);
                    if (records != null)
                    {
                        //更新会员主表信息
                        var differentIntergral = 0m;
                        foreach (var item in records)
                        {
                            item.State          = 1;
                            differentIntergral += item.Integral;
                        }
                        //更新积分交易流水状态
                        IntegralFlowsService.Update(new IntegralFlows());
                        if (differentIntergral != 0m)
                        {
                            UpdateMemberIntegral(records.FirstOrDefault().MemberId, differentIntergral);
                        }
                    }
                }
            }
            else
            {
                throw new MessageException("签名验证失败!");
            }
            //通知手机
            try
            {
                var pushData = new object();
                if (alias.Length > 0 && payState == "PAYSUCCESS")
                {
                    pushData = new
                    {
                        platform = "all",
                        audience = new { alias = alias },
                        message  = new
                        {
                            msg_content = JsonConvert.SerializeObject(new
                            {
                                method = "paynotify",
                                data   = new
                                {
                                    ordersn  = orderSN,
                                    date     = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                    state    = 1,
                                    amount   = amount,
                                    descript = "成功支付!"
                                }
                            }),
                            content_type = "text"
                        }
                    };
                }
                else
                {
                    pushData = new
                    {
                        platform = "all",
                        audience = new { alias = alias },
                        message  = new
                        {
                            msg_content = JsonConvert.SerializeObject(new
                            {
                                method = "paynotify",
                                data   = new
                                {
                                    ordersn  = orderSN,
                                    date     = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                    state    = 0,
                                    amount   = amount,
                                    descript = "订单未成功支付!"
                                }
                            }),
                            content_type = "text"
                        }
                    };
                }
                JPushRestClient.Post <dynamic, JObject>(pushData);
            }
            catch (Exception)
            {
            }
gotoReturn:
            return(new { return_code = "00000", return_msg = "接收成功" });
        }