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);
            }
        }
예제 #2
0
        //[HttpPost]
        public ActionResult AppStore(Dictionary <string, string> queryvalues)
        {
//#if Debug
//            queryvalues = new Dictionary<string, string>();
//            queryvalues.Add("transtime", "1472653281");
//            queryvalues.Add("productid", "Chip_3");
//            queryvalues.Add("identityid", "403278");
//            queryvalues.Add("othertype", "2");
//            queryvalues.Add("other", "8B58253C-9B85-4D13-93EF-0F9D21162895");
//            queryvalues.Add("customsign", "7fa5c658db8804a14879c972f271d58d");

//            queryvalues.Add("transactionid", "440000246529282");
//            queryvalues.Add("isfirstrecharge", "0");
//            queryvalues.Add("transactionreceipt", "ewoJInNpZ25hdHVyZSIgPSAiQXhvZGJkQlFNWnBVUkhKbXQvdWw4MExza2RuWDZlaXVzaGl4ZzI4WFNOM0ROZTdBbFp3K2NPVDhENEo5Q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U0F3TnpveU1Ub3hPU0JCYldWeWFXTmhMMHh2YzE5QmJtZGxiR1Z6SWpzS2ZRPT0iOwoJInBvZCIgPSAiNDQiOwoJInNpZ25pbmctc3RhdHVzIiA9ICIwIjsKfQ==");
//#endif



            string _transtime  = queryvalues.ContainsKey("transtime") ? queryvalues["transtime"] : string.Empty;
            string _productid  = queryvalues.ContainsKey("productid") ? queryvalues["productid"] : string.Empty;
            int    _identityid = queryvalues.ContainsKey("identityid") ? Convert.ToInt32(queryvalues["identityid"]) : 0;
            int    _othertype  = queryvalues.ContainsKey("othertype") ? Convert.ToInt32(queryvalues["othertype"]) : 0;
            string _other      = queryvalues.ContainsKey("other") ? queryvalues["other"] : string.Empty;
            string _customSign = queryvalues.ContainsKey("customsign") ? queryvalues["customsign"] : string.Empty;

            string Key = _key;

            string _transactionid      = queryvalues.ContainsKey("transactionid") ? queryvalues["transactionid"] : string.Empty;
            int    _isfirstrecharge    = queryvalues.ContainsKey("isfirstrecharge") ? Convert.ToInt32(queryvalues["isfirstrecharge"]) : 0;
            string _transactionreceipt = queryvalues.ContainsKey("transactionreceipt") ? queryvalues["transactionreceipt"] : string.Empty;
            string md5 = Utils.MD5(string.Concat(_transtime, _identityid, _othertype, _other, _productid, Key));

            if (!_customSign.Equals(md5))
            {
                log.Error("AppStore 参数不正确");
                return(Json(new { result = 10001, msg = "AppStore 参数不正确" }));
            }


            //Convert.FromBase64String(System.Text.Encoding.ASCII.GetBytes(_transactionreceipt))
            var res = System.Text.Encoding.ASCII.GetString(Convert.FromBase64String(_transactionreceipt));

            //(JObject)JsonConvert.DeserializeObject


            ReceiptManager receiptManager = new ReceiptManager();
            var            env            = Environments.Production;



            if (res.IndexOf("Sandbox") > 0)
            {
                env = Environments.Sandbox;
            }



            var response = receiptManager.ValidateReceipt(env, res);

            log.Info("response.Status=" + response.Status);
            log.Info("Environments.Sandbox" + res.IndexOf("Sandbox"));


            if (response.Status > 0)
            {
                log.Error("AppStore ReceiptVerifier Error Status :" + response.Status);
                return(Json(new { result = response.Status }));
            }


            if (!(response.Receipt.BundleIdentifier == "com.game515.wywdezhou" || response.Receipt.BundleIdentifier == "com.game515.515dezhou" || response.Receipt.BundleIdentifier == "com.gamehk.wanrendezhou" || response.Receipt.BundleIdentifier == "com.gamehk.wanrenqlunpan"))
            {
                log.Error("AppStore ReceiptVerifier Error bid :" + response.Receipt.BundleIdentifier);
                return(Json(new { result = 10006, msg = "AppStore ReceiptVerifier Error bid :" + response.Receipt.BundleIdentifier }));
            }


            try
            {
                //RechargeCheck rc = RechargeCheckBLL.GetModelBySerialNo(new RechargeCheck { SerialNo = out_trade_no });

                //if (rc == null)
                //{
                //    log.Error(" AppStore 订单[" + out_trade_no + "]不存在");
                //    return Content("fail");
                //}
                Recharge rc = RechargeBLL.GetModelByBillNo(new Recharge {
                    BillNo = _transactionid
                });
                if (rc != null)
                {
                    log.Error(" AppStore 订单[" + _transactionid + "]已存在");
                    return(Json(new { result = 1, msg = "AppStore 订单[" + _transactionid + "]已存在" }));
                }


                Role user = RoleBLL.GetModelByID(new Role {
                    ID = _identityid
                });
                if (user == null)
                {
                    log.Error(" AppStore 用户[" + _identityid + "]不存在");
                    return(Json(new { result = 10002, msg = "AppStore 用户[" + _identityid + "]不存在" }));
                }
                IAPProduct iap = IAPProductBLL.GetModelByID(_productid);
                if (iap == null)
                {
                    log.Error(" AppStore 支付配表出错");
                    return(Json(new { result = 10003, msg = "AppStore 支付配表出错" }));
                }


                isFirst  iF = iap.product_id.Split('_')[0].Equals("firstCharge") ? isFirst.是 : isFirst.否;
                chipType ct = iF == isFirst.是 ? chipType.首冲礼包 : (chipType)iap.goodsType;



                bool firstGif = iF == isFirst.是;



                Recharge recharge = RechargeBLL.GetFirstModelListByUserID(new Recharge {
                    UserID = _identityid
                });
                if (recharge != null)//首冲过
                {
                    if (firstGif == true)
                    {//又是首冲,则改变其为不首冲
                        firstGif      = false;
                        ct            = (chipType)1;
                        iF            = isFirst.否;
                        iap.goodsType = 1;
                        log.Error(" 多次首冲,修改firstGif值");
                    }
                }

                RechargeCheckBLL.AddOrderIP(new UserIpInfo {
                    UserID = _identityid, OrderID = _transactionid, CreateTime = DateTime.Now, ChargeType = (int)raType.AppStore, OrderIP = GetClientIp()
                });
                RechargeIP ipmodel = GetCallBackClientIp();
                RechargeCheckBLL.AddCallBackOrderIP(new UserIpInfo {
                    CallBackUserID = _identityid, OrderID = _transactionid, Method = ipmodel.Method, CallBackIP = ipmodel.IP, CallBackTime = DateTime.Now, CallBackChargeType = (int)raType.AppStore
                });



                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;
                }
                string list = iap.attach_props;
                list = list.Trim(',') + (gold > 0 ? ",10000:" + gold + "," : "");
                list = list.Trim(',') + (dia > 0 ? ",20000:" + dia + "," : "");
                list = list.Trim(',') + ",";
                uint rmb = (uint)iap.price;
                log.Info(" 分 :" + rmb * 100);
                // rmb = rmb * 100;//将元单位转换为分的单位转给游戏服务器



                RechargeBLL.Add(new Recharge {
                    BillNo = _transactionid, OpenID = response.Receipt.UniqueIdentifier, UserID = _identityid, Money = (rmb * 100), CreateTime = DateTime.Now, Chip = gold, Diamond = dia, ChipType = ct, IsFirst = iF, NickName = iap.productname, PayItem = iap.product_id, PF = raType.AppStore, UserAccount = user.NickName, ActualMoney = (rmb * 100), ProductNO = list.Trim(',')
                });


                log.Info(" 开始给服务器发送消息_identityid=" + _identityid + ",list=" + list + ",rmb*100=" + rmb * 100 + ",firstGif=" + firstGif + ",_transactionid=" + _transactionid);


                normal ServiceNormalS = normal.CreateBuilder()
                                        .SetUserID((uint)_identityid)
                                        .SetList(list)
                                        .SetRmb(rmb * 100)//将元单位转换为分的单位转给游戏服务器
                                        .SetRmbActual(rmb * 100)
                                        .SetFirstGif(firstGif)
                                        .SetBillNo(_transactionid)
                                        .Build();

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


                    log.Info("CenterCmd.CS_NORMAL:");

                    normalRep ServiceNormalC = normalRep.ParseFrom(tbind.body.ToBytes());
                    log.Info(" AppStore ServiceResult : " + ServiceNormalC.Suc);
                    if (ServiceNormalC.Suc)
                    {
                        log.Info(" AppStore ServiceResult [" + _transactionid + "] : " + ServiceNormalC.Suc);

                        RechargeBLL.UpdateReachTime(_transactionid);
                        //RechargeCheckBLL.Delete(new RechargeCheck { SerialNo = rc.SerialNo });
                    }

                    //Response.Redirect("mobilecall://fail?suc=" + ServiceNormalC.Suc);
                    break;

                case CenterCmd.CS_CONNECT_ERROR:


                    log.Info(" CenterCmd.CS_CONNECT_ERROR:");


                    break;
                }


                log.Info(" AppStore Process Success[" + _transactionid + "]: " + Utils.GetUrl() + "?" + Core.CreateLinkStringUrlencode(queryvalues, Encoding.UTF8));

                return(Json(new
                {
                    result = 0,
                    productid = _productid,
                    transactionid = _transactionid,
                    isfirstrecharge = _isfirstrecharge
                }));


                //log.Error(" AppStore fail : q " + Utils.GetUrl() + Utils.CreateLinkStringUrlencode(queryvalues, Encoding.UTF8));
                //return Json(new { result = 10004, msg = "AppStore 服务器发货失败" });
            }
            catch (Exception err)
            {
                log.Error(" AppStore fail : q " + Utils.GetUrl() + Utils.CreateLinkStringUrlencode(queryvalues, Encoding.UTF8), err);
                return(Json(new { result = 10005, msg = "AppStore 服务器发货失败 err:" + err.Message }));
            }
        }