示例#1
0
        /// <summary>
        /// 易宝异步返回
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public YBResponsePara YBCallBack(HttpContext context)
        {
            YBResponsePara result = new YBResponsePara()
            {
                isPaySuccess = false,
                orderNumber  = "",
                paymentMoney = 0,
                resultMsg    = ""
            };

            try
            {
                if (context.Request["data"].IsNull() ||
                    context.Request["encryptkey"].IsNull())
                {
                    result.resultMsg = "回调参数不正确";
                    return(result);
                }
                //回调中的参数data
                string data = context.Request["data"].ToString();
                //回调中的参数encryptkey
                string encryptkey = context.Request["encryptkey"].ToString();
                //解密易宝支付回调结果
                string callback_result = YJPayUtil.checkYbCallbackResult(data, encryptkey);
                if (callback_result != "验签未通过")
                {
                    //string descstring = AES.Decrypt(data, APIURLConfig.merchantAesKey);
                    Dictionary <string, object> responsePara = callback_result.JsonToDocument <Dictionary <string, object> >();

                    if (!responsePara.IsNull())
                    {
                        result.isPaySuccess = true;
                        result.paymentMoney = AlipayConfig.MoneyFormatDco(responsePara["amount"].ToString());
                        result.orderNumber  = responsePara["orderid"].ToString();
                        result.resultMsg    = "返回成功";
                    }
                }
            }
            catch (Exception err)
            {
                result.resultMsg = err.Message;
            }

            return(result);
        }
        public ActionResult YeePay(Dictionary <string, string> queryvalues)
        {
            string _data       = queryvalues.ContainsKey("data") ? queryvalues["data"] : string.Empty;
            string _encryptkey = queryvalues.ContainsKey("encryptkey") ? queryvalues["encryptkey"] : string.Empty;

            if (_data == string.Empty || _encryptkey == string.Empty)
            {
                Response.Redirect("mobilecall://fail");
                return(Content("参数不正确!"));
            }

            try
            {
                //商户注意:接收到易宝的回调信息后一定要回写success用以保证握手成功!
                //Response.Write("success");

                YeepayCallback model = new YeepayCallback();
                model.Data           = _data;
                model.EncryptKey     = _encryptkey;
                model.CallBackResult = YJPayUtil.checkYbCallbackResult(_data, _encryptkey);//解密易宝支付回调结果



                JsonToInstance       util = new JsonToInstance();
                YeepayCallbackReslut m    = util.ToInstance <YeepayCallbackReslut>(model.CallBackResult);
                RechargeCheck        rc   = RechargeCheckBLL.GetModelBySerialNo(new RechargeCheck {
                    SerialNo = m.orderid
                });
#if Debug
                Role user = RoleBLL.GetModelByID(new Role {
                    ID = rc.UserID
                });
#endif

#if P17
                Role user = RoleBLL.GetModelByID(new Role {
                    ID = rc.UserID
                });
#endif
#if Release
                Role user = RoleBLL.GetModelByID(new Role {
                    ID = rc.UserID
                });
#endif
                IAPProduct iap = IAPProductBLL.GetModelByID(rc.ProductID);
                isFirst    iF  = iap.product_id.Split('_')[0].Equals("firstCharge")?isFirst.是:isFirst.否;
                chipType   ct  = iF == isFirst.是 ? chipType.首冲礼包 : (chipType)iap.goodsType;



                bool firstGif = iF == isFirst.是;

                uint gold = iap.goodsType == 1 ? (uint)iap.goods : 0;
                uint dia  = iap.goodsType == 2 ? (uint)iap.goods : 0;

                if (firstGif)
                {
                    gold = (uint)(iap.goods + iap.attach_chip);
                    dia  = (uint)iap.attach_5b;
                }

                uint rmb = (uint)(rc.Money / 100);

                normal ServiceNormalS = normal.CreateBuilder()
                                        .SetUserID((uint)rc.UserID)
                                        .SetGold(gold)
                                        .SetDia(dia)
                                        .SetRmb(rmb)
                                        .SetFirstGif(firstGif)
                                        .Build();


                Bind tbind = Cmd.runClient(new Bind(BR_Cmd.BR_NORMAL, ServiceNormalS.ToByteArray()));
                switch ((CenterCmd)tbind.header.CommandID)
                {
                case CenterCmd.CS_NORMAL:
                    normalRep ServiceNormalC = normalRep.ParseFrom(tbind.body.ToBytes());


                    if (ServiceNormalC.Suc)
                    {
                        RechargeBLL.Add(new Recharge {
                            BillNo = m.yborderid, OpenID = rc.SerialNo, UserID = rc.UserID, Money = rc.Money, CreateTime = DateTime.Now, Chip = gold, ChipType = ct, IsFirst = iF, NickName = iap.productname, PayItem = iap.product_id, PF = raType.易宝, UserAccount = user.NickName
                        });

                        RechargeCheckBLL.Delete(new RechargeCheck {
                            SerialNo = m.orderid
                        });



                        //Response.Redirect("mobilecall://success");
                        return(RedirectToAction("success", "Home"));
                    }
                    //Response.Redirect("mobilecall://fail?suc=" + ServiceNormalC.Suc);
                    break;

                case CenterCmd.CS_CONNECT_ERROR:
                    break;
                }



                //Response.Redirect("mobilecall://fail");
                return(RedirectToAction("fail", "Home"));
            }
            catch (Exception err)
            {
                //Response.Redirect("mobilecall://fail?err=" + err);
                return(RedirectToAction("fail", "Home"));
                //return Content("支付失败!" + err);
            }
        }
示例#3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            TuanDai.Payment.Log.Info(this.GetType().ToString(), "开始易宝回调");
            string callback_result = "";

            try
            {
                if (Request["data"] == null || Request["encryptkey"] == null)
                {
                    TuanDai.Payment.Log.Info(this.GetType().ToString(), "参数不正确");
                    Response.Write("参数不正确!");
                    Response.End();
                }

                TuanDai.Payment.Log.Info(this.GetType().ToString(), "易宝回调加密参数:" + Request["data"] + ",密钥:" + Request["encryptkey"]);
                //商户注意:接收到易宝的回调信息后一定要回写success用以保证握手成功!

                string data       = Request["data"];       //回调中的参数data
                string encryptkey = Request["encryptkey"]; //回调中的参数encryptkey
                callback_result = YJPayUtil.checkYbCallbackResult(data, encryptkey);
                var resultData = JsonConvert.DeserializeObject <SortedDictionary <string, string> >(callback_result);
                TuanDai.Payment.Log.Info(this.GetType().ToString(), "The Pay result is Values  : " + callback_result);

                if (resultData == null || resultData.ContainsKey("error_msg"))
                {
                    Response.Write("参数不正确!");
                    Response.End();
                }

                var status         = resultData["status"].ToString();
                var rechargeMoney  = resultData["amount"].ToString();
                var out_trade_no   = resultData["orderid"].ToString();
                var transaction_id = resultData["yborderid"].ToString();

                string            strSQL   = "p_OnLineRechargeHandler";
                DynamicParameters dyParams = new DynamicParameters();
                dyParams.Add("@orderno", out_trade_no);
                dyParams.Add("@MediumMoney", decimal.Parse(rechargeMoney) / 100);
                dyParams.Add("@MediumOrderNo", transaction_id);
                dyParams.Add("@outStatus", 0, DbType.Int32, ParameterDirection.Output, 20);
                if (status == "1")
                {
                    dyParams.Add("@handlerStatus", 2);
                }
                else
                {
                    dyParams.Add("@handlerStatus", 1);
                }
                PublicConn.ExecuteTD(PublicConn.DBWriteType.FundWrite, strSQL, ref dyParams, CommandType.StoredProcedure);

                int result = dyParams.Get <int>("@outStatus");
                if (result == 1)
                {
                    AccountRechareInfo accountRechare = getAccountRechare(out_trade_no);
                    if (accountRechare != null)
                    {
                        //List<int> typeList = new List<int>() { 2, 3, 4, 6, 8,9,11, 12 };
                        //if (db.AccountRechare.Count(p => p.UserId == accountRechare.UserId && p.Status == 2 && typeList.Contains(p.type)) == 1)
                        //{
                        //    TuanDai.PortalSystem.BLL.VipGetWorthBLL.AddGetWorth(accountRechare.UserId, (int)ConstString.UserGrowthType.FirstReCharge, null, 0);
                        //}

                        TuanDai.PortalSystem.BLL.UserBLL bll = new TuanDai.PortalSystem.BLL.UserBLL();
                        UserBasicInfoInfo userBasicInfo      = bll.GetUserBasicInfoModelById(accountRechare.UserId);
                        if (userBasicInfo != null)
                        {
                            var isNewSmsRequest = ConfigHelper.getConfigString("IsNewSmsRequest", "0");
                            if (isNewSmsRequest == "0")
                            {
                                var parameters = new Dictionary <string, object>();
                                parameters.Add("User", userBasicInfo);
                                parameters.Add("CurrentDate", DateTime.Now);
                                parameters.Add("RechargeMoney", rechargeMoney);
                                parameters.Add("Host", GlobalUtils.WebURL);

                                var messageSender = new BusinessDll.MessageSend();
                                messageSender.SendMessage2(eventCode: MessageTemplates.RechargeSuccess, parameters: parameters,
                                                           mobile: userBasicInfo.TelNo, email: userBasicInfo.Email, userId: userBasicInfo.Id);
                            }
                            else
                            {
                                SmsRequest rechargeSuccessSmsRequest = new SmsRequest();
                                rechargeSuccessSmsRequest.EventCode      = MsgTemplatesType.RechargeSuccess;
                                rechargeSuccessSmsRequest.PlatformSource = PlatformSource.Pc;
                                rechargeSuccessSmsRequest.UserId         = userBasicInfo.Id;
                                rechargeSuccessSmsRequest.EmailAddress   = userBasicInfo.Email;
                                rechargeSuccessSmsRequest.Mobile         = userBasicInfo.TelNo;
                                rechargeSuccessSmsRequest.Parameters     = new Dictionary <string, object>();
                                rechargeSuccessSmsRequest.Parameters.Add("RechargeMoney", rechargeMoney);

                                string errorMessage = string.Empty;
                                SmsClient.SendMessage(rechargeSuccessSmsRequest, ref errorMessage);
                            }
                        }
                    }
                }

                //NetLog.WriteBatchwithdrawHandler("交易成功", string.Concat("签名:", sPara["sign"].ToString(), "签名方式:", sPara["sign_type"].ToString(), "我方处理状态:", result.ToString().Trim(), "连连处理状态:", sPara["result_pay"].ToString()));
                Response.Write(@"SUCCESS");
                Response.End();

                //SoftLog.LogStr("支付成功回调信息:" + callback_result, "yeepay/CallbackLog");
            }
            catch (Exception err)
            {
                TuanDai.Payment.Log.Info(this.GetType().ToString(), "支付失败:" + err.ToString() + "," + Request["data"] + Environment.NewLine + Request["encryptkey"] + "处理结果:" + callback_result);
                //SoftLog.LogStr("支付失败:" + err.ToString() + "," + Request["data"] + Environment.NewLine + Request["encryptkey"] + "处理结果:" + callback_result, "yeepay/CallbackLog");
                Response.Write("支付失败!");
                Response.End();
            }
            finally
            {
                //SoftLog.LogStr("支付回调信息" + Request["data"] + Environment.NewLine + Request["encryptkey"] + "处理结果:" + callback_result, "yeepay/CallbackLog");
            }
        }