コード例 #1
0
ファイル: Program.cs プロジェクト: shine7430/giftcard
        static void Main(string[] args)
        {
            // 请根据实际 appid 和 appkey 进行开发,以下只作为演示 sdk 使用
            // appid,appkey,templId申请方式可参考接入指南 https://www.qcloud.com/document/product/382/3785#5-.E7.9F.AD.E4.BF.A1.E5.86.85.E5.AE.B9.E9.85.8D.E7.BD.AE
            int    sdkappid     = 1400096240;
            string appkey       = "409fa0923289125b7b12025b0b281535";
            string phoneNumber1 = "15221336036";
            string phoneNumber2 = "15221336036";
            string phoneNumber3 = "15221336036";
            int    tmplId       = 128733;

            try
            {
                //SmsSingleSenderResult singleResult;
                //SmsSingleSender singleSender = new SmsSingleSender(sdkappid, appkey);

                //singleResult = singleSender.Send(0, "86", phoneNumber2, "测试短信,普通单发,深圳,小明,上学。", "", "");
                //Console.WriteLine(singleResult);


                List <string> templParams = new List <string>();
                templParams.Add("7876");
                //// 指定模板单发
                //// 假设短信模板内容为:测试短信,{1},{2},{3},上学。
                //singleResult = singleSender.SendWithParam("86", phoneNumber2, tmplId, templParams, "", "", "");
                //Console.WriteLine(singleResult);
                //return;
                SmsMultiSenderResult multiResult;
                SmsMultiSender       multiSender  = new SmsMultiSender(sdkappid, appkey);
                List <string>        phoneNumbers = new List <string>();
                //phoneNumbers.Add(phoneNumber1);
                //phoneNumbers.Add(phoneNumber2);
                //phoneNumbers.Add(phoneNumber3);
                DataTable dt = MySqlHelp.ExecuteDataTable("select * from t_customers");
                foreach (DataRow dr in dt.Rows)
                {
                    phoneNumbers.Add(dr["CellNumber"].ToString());
                }
                // 普通群发
                // 下面是 3 个假设的号码
                multiResult = multiSender.Send(0, "86", phoneNumbers, "测试短信,普通群发,深圳,小明,上学。", "", "");
                Console.WriteLine(multiResult);
                return;

                // 指定模板群发
                // 假设短信模板内容为:测试短信,{1},{2},{3},上学。
                templParams.Clear();
                templParams.Add("指定模板群发");
                templParams.Add("深圳");
                templParams.Add("小明");
                multiResult = multiSender.SendWithParam("86", phoneNumbers, tmplId, templParams, "", "", "");
                Console.WriteLine(multiResult);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.Read();
        }
コード例 #2
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Charset     = "utf-8";

            string Action     = context.Request["Action"].ToString();
            var    conditions = context.Request["conditions"];
            var    deliveryid = context.Request["deliveryid"];
            var    orderid    = context.Request["orderid"];
            string result     = string.Empty;
            var    querySQL   = string.Empty;
            List <Entity.DeliveryReport> _DeliveryReport = new List <Entity.DeliveryReport>();
            DataTable odDT = new DataTable();

            if (!string.IsNullOrEmpty(Action))
            {
                switch (Action.ToLower())
                {
                case "getdeliverys":
                    querySQL = @"select 
tor.outtradeno as 'orderid',
td.id as 'deliveryid',
td.status as 'deliverystatus',
tor.openid,
tu.nickname,
tor.fruittype,
tor.count,
tor.deliveryaddr,
tor.user,
tor.mp,
td.date,
GROUP_CONCAT(tdf.name) as 'fruits'
from t_order tor
inner join t_delivery td
on tor.orderid=td.orderid and tor.status='PaidSuccessed'
inner join t_deliveryfruits tdf
on tdf.deliveryid=td.id
inner join t_user tu
on tu.openid=tor.openid
group by 
tor.outtradeno,
tor.openid,
tu.nickname,
tor.fruittype,
tor.count,
tor.deliveryaddr,
tor.user,
tor.mp,
td.date
order by td.date
";
                    odDT     = MySqlHelp.ExecuteDataTable(querySQL);
                    for (int i = 0; i < odDT.Rows.Count; i++)
                    {
                        Entity.DeliveryReport orderentity = new Entity.DeliveryReport();
                        orderentity.orderid        = odDT.Rows[i]["orderid"].ToString();
                        orderentity.openid         = odDT.Rows[i]["openid"].ToString();
                        orderentity.nickname       = odDT.Rows[i]["nickname"].ToString();
                        orderentity.fruittype      = odDT.Rows[i]["fruittype"].ToString();
                        orderentity.count          = odDT.Rows[i]["count"].ToString();
                        orderentity.deliveryaddr   = odDT.Rows[i]["deliveryaddr"].ToString();
                        orderentity.user           = odDT.Rows[i]["user"].ToString();
                        orderentity.date           = odDT.Rows[i]["date"].ToString();
                        orderentity.mp             = odDT.Rows[i]["mp"].ToString();
                        orderentity.fruits         = odDT.Rows[i]["fruits"].ToString();
                        orderentity.deliveryid     = odDT.Rows[i]["deliveryid"].ToString();
                        orderentity.deliverystatus = odDT.Rows[i]["deliverystatus"].ToString();
                        _DeliveryReport.Add(orderentity);
                    }
                    result = "{\"result\":\"successed\",\"orders\":" + JsonUtility.ToJSONString(_DeliveryReport) + "}";

                    break;

                case "getgiftboxdelivery":

                    querySQL = @"select 
tor.outtradeno as 'orderid',
tor.openid,
tu.nickname,
tor.fruittype,
tor.startdate,
tor.count,
tor.deliveryaddr,
tor.user,
tor.mp,
tor.deliverystatus,
GROUP_CONCAT(CONCAT(tof.name,tof.fruitNum * tof.count ,tof.unit,' (',CAST(tof.count AS char),'份)' ) )as 'fruits',
tor.GiftCardCode,
tor.ExpressNumber
from t_order tor
inner join t_orderfruts tof
on tof.orderid=tor.orderid and  tor.status in('PaidSuccessed','Completed') and fruittype like '%礼盒%' 
inner join t_user tu
on tu.openid=tor.openid
group by
tor.outtradeno
order by startdate
";
                    odDT     = MySqlHelp.ExecuteDataTable(querySQL);
                    for (int i = 0; i < odDT.Rows.Count; i++)
                    {
                        Entity.DeliveryReport orderentity = new Entity.DeliveryReport();
                        orderentity.orderid   = odDT.Rows[i]["orderid"].ToString();
                        orderentity.openid    = odDT.Rows[i]["openid"].ToString();
                        orderentity.nickname  = odDT.Rows[i]["nickname"].ToString();
                        orderentity.fruittype = odDT.Rows[i]["fruittype"].ToString();
                        orderentity.date      = odDT.Rows[i]["startdate"].ToString();

                        orderentity.count          = odDT.Rows[i]["count"].ToString();
                        orderentity.deliveryaddr   = odDT.Rows[i]["deliveryaddr"].ToString();
                        orderentity.user           = odDT.Rows[i]["user"].ToString();
                        orderentity.mp             = odDT.Rows[i]["mp"].ToString();
                        orderentity.fruits         = odDT.Rows[i]["fruits"].ToString();
                        orderentity.deliverystatus = odDT.Rows[i]["deliverystatus"].ToString();
                        orderentity.ExpressNumber  = odDT.Rows[i]["ExpressNumber"].ToString();
                        orderentity.GiftCardCode   = odDT.Rows[i]["GiftCardCode"].ToString();
                        _DeliveryReport.Add(orderentity);
                    }
                    result = "{\"result\":\"successed\",\"orders\":" + JsonUtility.ToJSONString(_DeliveryReport) + "}";
                    break;

                case "getcommunitydelivery":
                    querySQL = @"select 
tor.outtradeno as 'orderid',
tor.openid,
tu.nickname,
tor.fruittype,
tor.startdate,
tor.count,
tor.deliveryaddr,
tor.user,
tor.mp,
tor.deliverystatus,
GROUP_CONCAT(CONCAT(tof.name,tof.fruitNum * tof.count ,tof.unit ) ) as 'fruits',
tor.GiftCardCode,
tor.ExpressNumber,
tor.actualprice,
tor.status,
tor.agencylevel,
tor.discount,
tor.rebate
from t_order tor
inner join t_orderfruts tof
on tof.orderid=tor.orderid and  tor.status in('PaidSuccessed','Completed','NotPaid') and fruittype like '%社区%'
inner join t_user tu
on tu.openid=tor.openid
group by
tor.outtradeno
order by startdate
";
                    odDT     = MySqlHelp.ExecuteDataTable(querySQL);
                    for (int i = 0; i < odDT.Rows.Count; i++)
                    {
                        Entity.DeliveryReport orderentity = new Entity.DeliveryReport();
                        orderentity.orderid   = odDT.Rows[i]["orderid"].ToString();
                        orderentity.openid    = odDT.Rows[i]["openid"].ToString();
                        orderentity.nickname  = odDT.Rows[i]["nickname"].ToString();
                        orderentity.fruittype = odDT.Rows[i]["fruittype"].ToString();
                        orderentity.date      = odDT.Rows[i]["startdate"].ToString();

                        orderentity.count          = odDT.Rows[i]["count"].ToString();
                        orderentity.deliveryaddr   = odDT.Rows[i]["deliveryaddr"].ToString();
                        orderentity.user           = odDT.Rows[i]["user"].ToString();
                        orderentity.mp             = odDT.Rows[i]["mp"].ToString();
                        orderentity.fruits         = odDT.Rows[i]["fruits"].ToString();
                        orderentity.deliverystatus = odDT.Rows[i]["deliverystatus"].ToString();
                        orderentity.ExpressNumber  = odDT.Rows[i]["ExpressNumber"].ToString();
                        orderentity.GiftCardCode   = odDT.Rows[i]["GiftCardCode"].ToString();
                        orderentity.actualprice    = odDT.Rows[i]["actualprice"].ToString();
                        orderentity.status         = odDT.Rows[i]["status"].ToString();
                        orderentity.agencylevel    = odDT.Rows[i]["agencylevel"].ToString();
                        orderentity.discount       = odDT.Rows[i]["discount"].ToString();
                        orderentity.rebate         = odDT.Rows[i]["rebate"].ToString();
                        _DeliveryReport.Add(orderentity);
                    }
                    result = "{\"result\":\"successed\",\"orders\":" + JsonUtility.ToJSONString(_DeliveryReport) + "}";
                    break;

                case "getfruitsestimate":
                    querySQL = @"
select * from
(
select 
td.date,
tdf.name as fruits,
sum(tor.count*150) as count,
'g' as unit
 from t_order tor
inner join t_delivery td
on tor.orderid=td.orderid and tor.status='PaidSuccessed' and tor.fruittype<>'精品礼盒DIY'
inner join t_deliveryfruits tdf
on td.id=tdf.deliveryid
group by
td.date,
tdf.name 
union
select 
tor.startdate as 'date',
tof.name as fruits,
sum(tof.fruitNum * tof.count* tor.count) as 'count',
tof.unit
from t_order tor
inner join t_orderfruts tof
on tof.orderid=tor.orderid and  tor.status='PaidSuccessed' and fruittype='精品礼盒DIY'
inner join t_user tu
on tu.openid=tor.openid
group by
tor.startdate,
tof.name,
tof.unit
)T
order by date";
                    odDT     = MySqlHelp.ExecuteDataTable(querySQL);
                    for (int i = 0; i < odDT.Rows.Count; i++)
                    {
                        Entity.DeliveryReport orderentity = new Entity.DeliveryReport();
                        orderentity.date   = odDT.Rows[i]["date"].ToString();
                        orderentity.fruits = odDT.Rows[i]["fruits"].ToString();
                        orderentity.count  = odDT.Rows[i]["count"].ToString();
                        orderentity.unit   = odDT.Rows[i]["unit"].ToString();
                        _DeliveryReport.Add(orderentity);
                    }
                    result = "{\"result\":\"successed\",\"orders\":" + JsonUtility.ToJSONString(_DeliveryReport) + "}";
                    break;

                case "getcommunityfruitsestimate":
                    querySQL = @"select * from
(
select 
tor.status,
tor.deliveryaddr,
tor.startdate as 'date',
tof.name as fruits,
sum(tof.fruitNum * tof.count* tor.count) as 'count',
tof.unit
from t_order tor
inner join t_orderfruts tof
on tof.orderid=tor.orderid and fruittype like '%社区%'
inner join t_user tu
on tu.openid=tor.openid
group by
tor.status,
tor.startdate,
tof.name,
tof.unit,
deliveryaddr
)T
order by date";
                    odDT     = MySqlHelp.ExecuteDataTable(querySQL);
                    for (int i = 0; i < odDT.Rows.Count; i++)
                    {
                        Entity.DeliveryReport orderentity = new Entity.DeliveryReport();
                        orderentity.date         = odDT.Rows[i]["date"].ToString();
                        orderentity.fruits       = odDT.Rows[i]["fruits"].ToString();
                        orderentity.count        = odDT.Rows[i]["count"].ToString();
                        orderentity.unit         = odDT.Rows[i]["unit"].ToString();
                        orderentity.deliveryaddr = odDT.Rows[i]["deliveryaddr"].ToString();
                        orderentity.status       = odDT.Rows[i]["status"].ToString();

                        _DeliveryReport.Add(orderentity);
                    }
                    result = "{\"result\":\"successed\",\"orders\":" + JsonUtility.ToJSONString(_DeliveryReport) + "}";
                    break;

                case "singledelivery":

                    DataTable checkdt = MySqlHelp.ExecuteDataTable(string.Format(@"update t_delivery set status='已配送' 
where id={0};
select 1 from t_order tor
inner join t_delivery td
on td.orderid=tor.orderid
where td.status='未配送' and tor.outtradeno='{1}'", deliveryid, orderid));
                    if (checkdt.Rows.Count <= 0)
                    {
                        MySqlHelp.ExecuteNonQuery("update t_order set status='Completed',statusid='3' where outtradeno=" + UtilityFn.formatstring(orderid));
                    }
                    result = "{\"result\":\"successed\"}";
                    break;

                case "bodelivery":
                    MySqlHelp.ExecuteNonQuery("update t_order set deliverystatus='已配送',status='Completed',statusid='3' where outtradeno=" + UtilityFn.formatstring(deliveryid));
                    result = "{\"result\":\"successed\"}";
                    break;

                case "changeexpressnumber":
                    var ExpressNumber = context.Request["ExpressNumber"];
                    MySqlHelp.ExecuteNonQuery("update t_order set ExpressNumber=" + UtilityFn.formatstring(ExpressNumber) + " where outtradeno=" + UtilityFn.formatstring(orderid));
                    result = "{\"result\":\"successed\"}";

                    break;

                default:
                    break;
                }
            }
            context.Response.Write(result);
        }
コード例 #3
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Charset     = "utf-8";

            string Action = context.Request["Action"].ToString();

            string result = "{\"result\":\"failed\"}";
            string openid = "";

            if (!string.IsNullOrEmpty(Action))
            {
                switch (Action)
                {
                case "order":
                    var    orderdata  = context.Request["orderdata"].ToString();
                    string _statusid  = "1";
                    string _statusStr = "NotPaid";
                    AllTrustUs.SquirrelPocket.Entity.Order _o = JsonUtility.Deserialize <AllTrustUs.SquirrelPocket.Entity.Order>(orderdata);
                    if (Convert.ToDecimal(_o.actualprice) == 0)
                    {
                        _statusid  = "2";
                        _statusStr = "PaidSuccessed";
                    }

                    string insjson = @"insert into t_order(openid,outtradeno,fruittype,unitprice,startdate,enddate,days,
                            count,deliveryaddr,user,mp,totalprice,status,createdate,statusid,deliverystatus,otheraddr,GiftCardCode,deduction,actualprice,agencylevel,discount) values({0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19},{20},{21});select @@IDENTITY;";
                    insjson = string.Format(insjson,
                                            UtilityFn.formatstring(_o.openid),
                                            UtilityFn.formatstring(UtilityFn.GenerateOutTradeNo()),
                                            UtilityFn.formatstring(_o.fruittype),
                                            UtilityFn.formatstring(_o.unitprice),
                                            UtilityFn.formatstring(_o.startdate),
                                            UtilityFn.formatstring(_o.enddate),
                                            UtilityFn.formatstring(_o.days),
                                            UtilityFn.formatstring(_o.count),
                                            UtilityFn.formatstring(_o.deliveryaddr),
                                            UtilityFn.formatstring(_o.user),
                                            UtilityFn.formatstring(_o.mp),
                                            UtilityFn.formatstring(_o.totalprice),
                                            UtilityFn.formatstring(_statusStr),
                                            UtilityFn.formatstring(DateTime.Now.ToString("yyyy/MM/dd HH:mm")),
                                            UtilityFn.formatstring(_statusid),
                                            UtilityFn.formatstring("未配送"),
                                            UtilityFn.formatstring(_o.otheraddr),
                                            UtilityFn.formatstring(_o.GiftCardCode),
                                            UtilityFn.formatstring(_o.deduction),
                                            UtilityFn.formatstring(_o.actualprice),
                                            UtilityFn.formatstring(_o.agencylevel),
                                            UtilityFn.formatstring(_o.discount)
                                            );
                    DataTable order = MySqlHelp.ExecuteDataTable(insjson);

                    if (order.Rows.Count > 0 && int.Parse(order.Rows[0][0].ToString()) > 0)
                    {
                        var orderid = order.Rows[0][0].ToString();
                        if (!string.IsNullOrEmpty(_o.GiftCardCode))
                        {
                            var updatecard = "update giftcard set isused='1',usedorderid='" + orderid + "',useddate='" + DateTime.Now.ToString("yyyy-MM-dd") + "' where giftcardcode='" + _o.GiftCardCode.Replace("-", "") + "'";
                            MySqlHelp.ExecuteNonQuery(updatecard);
                        }

                        foreach (AllTrustUs.SquirrelPocket.Entity.OrderFruit of in _o.fruits)
                        {
                            string insof = @"insert into t_orderfruts(orderid,fruitid,name,unit,unitprice,count,price,fruitNum,cost) 
                                    values({0},{1},{2},{3},{4},{5},{6},{7},{8});";
                            insof = string.Format(insof,
                                                  UtilityFn.formatstring(orderid),
                                                  UtilityFn.formatstring(of.FruitID),
                                                  UtilityFn.formatstring(of.Name),
                                                  UtilityFn.formatstring(string.IsNullOrEmpty(of.unit) ? "个" : of.unit),
                                                  UtilityFn.formatstring(of.unitprice),
                                                  UtilityFn.formatstring(string.IsNullOrEmpty(of.count) ? "1" : of.count),
                                                  UtilityFn.formatstring(of.price),
                                                  UtilityFn.formatstring(of.fruitNum),
                                                  UtilityFn.formatstring(of.cost)
                                                  );

                            MySqlHelp.ExecuteNonQuery(insof);
                        }

                        foreach (Entity.Delivery de in _o.deliverys)
                        {
                            string insdeli = @"insert into t_delivery(orderid,date,count,status) 
                                    values({0},{1},{2},{3});select @@IDENTITY;";
                            insdeli = string.Format(insdeli,
                                                    UtilityFn.formatstring(orderid),
                                                    UtilityFn.formatstring(de.Date),
                                                    UtilityFn.formatstring(de.Count),
                                                    UtilityFn.formatstring("未配送"));
                            DataTable deliDT = MySqlHelp.ExecuteDataTable(insdeli);
                            if (deliDT.Rows.Count > 0 && int.Parse(deliDT.Rows[0][0].ToString()) > 0)
                            {
                                var deliID = deliDT.Rows[0][0].ToString();
                                foreach (Entity.Deliveryfruits def in de.Deliveryfruits)
                                {
                                    string insdelif = @"insert into t_deliveryfruits(deliveryid,fruitid,name) 
                                    values({0},{1},{2});";
                                    insdelif = string.Format(insdelif,
                                                             UtilityFn.formatstring(deliID),
                                                             UtilityFn.formatstring(def.FruitID),
                                                             UtilityFn.formatstring(def.Name));
                                    MySqlHelp.ExecuteNonQuery(insdelif);
                                }
                            }
                        }
                        EmailHelper eh = new EmailHelper();
                        eh.SendMail("Squirel New Order Create", UtilityFn.JsonToHTMLTable(_o.ToJSONString()));

                        result = "{\"result\":\"successed\",\"orderid\":\"" + orderid + "\"}";
                    }
                    break;

                case "getorder":
                    openid = context.Request["openid"].ToString();
                    var status = context.Request["status"].ToString();
                    List <Entity.Order> _Orders = new List <Entity.Order>();
                    string    getsql            = "select * from t_order where openid=" + UtilityFn.formatstring(openid) + " and status=" + UtilityFn.formatstring(status) + " and status<>'deleted' order by statusid asc, createdate desc";
                    DataTable odDT = MySqlHelp.ExecuteDataTable(getsql);
                    for (int i = 0; i < odDT.Rows.Count; i++)
                    {
                        Entity.Order orderentity = new Entity.Order();

                        orderentity.openid       = odDT.Rows[i]["openid"].ToString();
                        orderentity.fruittype    = odDT.Rows[i]["fruittype"].ToString();
                        orderentity.startdate    = odDT.Rows[i]["startdate"].ToString();
                        orderentity.enddate      = odDT.Rows[i]["enddate"].ToString();
                        orderentity.days         = odDT.Rows[i]["days"].ToString();
                        orderentity.count        = odDT.Rows[i]["count"].ToString();
                        orderentity.deliveryaddr = odDT.Rows[i]["deliveryaddr"].ToString();
                        orderentity.user         = odDT.Rows[i]["user"].ToString();
                        orderentity.mp           = odDT.Rows[i]["mp"].ToString();
                        orderentity.totalprice   = odDT.Rows[i]["totalprice"].ToString();
                        orderentity.outtradeno   = odDT.Rows[i]["outtradeno"].ToString();
                        orderentity.status       = odDT.Rows[i]["status"].ToString();
                        orderentity.orderid      = odDT.Rows[i]["orderid"].ToString();
                        orderentity.createdate   = odDT.Rows[i]["createdate"].ToString();
                        orderentity.unitprice    = odDT.Rows[i]["unitprice"].ToString();
                        orderentity.otheraddr    = odDT.Rows[i]["otheraddr"].ToString();
                        orderentity.deduction    = odDT.Rows[i]["deduction"].ToString();
                        orderentity.actualprice  = odDT.Rows[i]["actualprice"].ToString();

                        string    getfruitssql = "select * from t_orderfruts where orderid=" + UtilityFn.formatstring(orderentity.orderid);
                        DataTable frDT         = MySqlHelp.ExecuteDataTable(getfruitssql);
                        orderentity.fruits = new List <Entity.OrderFruit>();
                        for (int j = 0; j < frDT.Rows.Count; j++)
                        {
                            Entity.OrderFruit ordereFruitntity = new Entity.OrderFruit();
                            ordereFruitntity.FruitID = frDT.Rows[j]["fruitid"].ToString();
                            ordereFruitntity.Name    = frDT.Rows[j]["name"].ToString();
                            orderentity.fruits.Add(ordereFruitntity);
                        }

                        _Orders.Add(orderentity);
                    }
                    result = "{\"result\":\"successed\",\"orders\":" + JsonUtility.ToJSONString(_Orders) + "}";



                    break;

                case "cancelorder":
                    string cancelorderid = context.Request["orderid"].ToString();
                    MySqlHelp.ExecuteNonQuery("update t_order set status='Canceled',statusid='5' where orderid=" + UtilityFn.formatstring(cancelorderid));
                    result = "{\"result\":\"successed\"}";
                    break;

                case "deleteorder":
                    string deleteorderorderid = context.Request["orderid"].ToString();
                    MySqlHelp.ExecuteNonQuery("update t_order set status='Deleted',statusid='4' where orderid=" + UtilityFn.formatstring(deleteorderorderid));
                    result = "{\"result\":\"successed\"}";
                    break;

                case "saveuserinfo":
                    string userdata = context.Request["userdata"].ToString();
                    openid = context.Request["openid"].ToString();

                    Dictionary <string, object> Dic = JsonUtility.ToDictionary(userdata);
                    var nickname = Dic["nickname"].ToString();
                    var country  = Dic["country"].ToString();
                    var province = Dic["province"].ToString();
                    var city     = Dic["city"].ToString();
                    var sex      = "";
                    if (!string.IsNullOrEmpty(Dic["sex"].ToString()))
                    {
                        if (Dic["sex"].ToString().Contains("男"))
                        {
                            sex = "1";
                        }
                        else
                        {
                            sex = "2";
                        }
                    }
                    else
                    {
                        sex = "1";
                    }

                    var mp = Dic["mp"].ToString();

                    ((WeXUser)context.Session["CurrentWeXUser"]).MP       = mp;
                    ((WeXUser)context.Session["CurrentWeXUser"]).city     = city;
                    ((WeXUser)context.Session["CurrentWeXUser"]).country  = country;
                    ((WeXUser)context.Session["CurrentWeXUser"]).nickname = nickname;
                    ((WeXUser)context.Session["CurrentWeXUser"]).sex      = sex;
                    ((WeXUser)context.Session["CurrentWeXUser"]).province = province;
                    MySqlHelp.ExecuteNonQuery("update t_user set mp=" + UtilityFn.formatstring(mp)
                                              + ",nickname=" + UtilityFn.formatstring(nickname)
                                              + ",country=" + UtilityFn.formatstring(country)
                                              + ",province=" + UtilityFn.formatstring(province)
                                              + ",city=" + UtilityFn.formatstring(city)
                                              + ",sex=" + UtilityFn.formatstring(sex)
                                              + " where openid=" + UtilityFn.formatstring(openid));

                    //((WeXUser)context.Session["CurrentWeXUser"]).MP = mp;

                    result = "{\"result\":\"successed\"}";

                    break;

                case "getDeliveryDetail":
                    var Deliveryorderid         = context.Request["orderid"].ToString();
                    List <Entity.Delivery> deli = new List <Entity.Delivery>();
                    string    Deligetsql        = "select * from t_delivery where orderid=" + UtilityFn.formatstring(Deliveryorderid);
                    DataTable DeliDT            = MySqlHelp.ExecuteDataTable(Deligetsql);

                    for (int i = 0; i < DeliDT.Rows.Count; i++)
                    {
                        Entity.Delivery ent = new Entity.Delivery();
                        ent.ID             = DeliDT.Rows[i]["ID"].ToString();
                        ent.OrderID        = Deliveryorderid;
                        ent.Date           = DeliDT.Rows[i]["Date"].ToString();
                        ent.Count          = DeliDT.Rows[i]["Count"].ToString();
                        ent.deliverystatus = DeliDT.Rows[i]["status"].ToString();
                        deli.Add(ent);
                    }

                    result = "{\"result\":\"successed\",\"deliverys\":" + JsonUtility.ToJSONString(deli) + "}";
                    break;

                case "orderRefund":
                    string    orderRefundorderid = context.Request["orderid"].ToString();
                    DataTable orderDT            = MySqlHelp.ExecuteDataTable(string.Format("select * from t_order where orderid={0}", orderRefundorderid));
                    var       outtradeno         = orderDT.Rows[0]["outtradeno"].ToString();
                    var       transaction_id     = orderDT.Rows[0]["transaction_id"].ToString();
                    var       totalprice         = orderDT.Rows[0]["totalprice"].ToString();
                    var       actualprice        = orderDT.Rows[0]["actualprice"].ToString();
                    try
                    {
                        string Refundresult = Refund.Run(transaction_id, outtradeno, (int.Parse(actualprice) * 100).ToString(), (int.Parse(actualprice) * 100).ToString());

                        Dictionary <string, object> di = JsonUtility.ToDictionary(Refundresult);
                        EmailHelper eh = new EmailHelper();
                        if (di["result_code"].ToString().ToUpper() == "FAIL")
                        {
                            result = "{\"result\":\"failed\"}";
                            eh.SendMail("Squirel Refunded Order failed[" + orderRefundorderid + "]", UtilityFn.JsonToHTMLTable(Refundresult));
                        }
                        else
                        {
                            result = "{\"result\":\"successed\"}";
                            MySqlHelp.ExecuteNonQuery(string.Format("update t_order set status='Refunded',statusid='100' where  orderid={0}", orderRefundorderid));
                            eh.SendMail("Squirel Refunded Order Successed[" + orderRefundorderid + "]", UtilityFn.JsonToHTMLTable(Refundresult));
                        }
                        Log.Info(this.GetType().ToString(), Refundresult);

                        //Response.Write("<span style='color:#00CD00;font-size:20px'>" + result + "</span>");
                    }
                    catch (WxPayException ex)
                    {
                        result = "{\"result\":\"failed\"}";
                        //Response.Write("<span style='color:#FF0000;font-size:20px'>" + ex.ToString() + "</span>");
                    }
                    catch (Exception ex)
                    {
                        result = "{\"result\":\"failed\"}";
                        //Response.Write("<span style='color:#FF0000;font-size:20px'>" + ex.ToString() + "</span>");
                    }


                    break;

                case "getgiftcode":
                    string    giftcode   = context.Request["giftcode"].ToString().Replace("-", "");
                    DataTable giftcodeDT = MySqlHelp.ExecuteDataTable(string.Format("select * from giftcard where isused='0' and giftcardcode='{0}'", giftcode));
                    if (giftcodeDT.Rows.Count > 0)
                    {
                        Giftcard gc = new Giftcard();
                        gc.id           = Convert.ToInt32(giftcodeDT.Rows[0]["id"]);
                        gc.giftcardcode = giftcodeDT.Rows[0]["giftcardcode"].ToString();
                        gc.amount       = giftcodeDT.Rows[0]["amount"].ToString();
                        gc.generatedate = giftcodeDT.Rows[0]["generatedate"].ToString();
                        gc.isused       = giftcodeDT.Rows[0]["isused"].ToString();
                        gc.usedorderid  = giftcodeDT.Rows[0]["usedorderid"].ToString();
                        gc.useddate     = giftcodeDT.Rows[0]["useddate"].ToString();
                        gc.forcompany   = giftcodeDT.Rows[0]["forcompany"].ToString();
                        gc.expireddate  = giftcodeDT.Rows[0]["expireddate"].ToString();

                        result = "{\"result\":\"successed\",\"giftcard\":" + JsonUtility.ToJSONString(gc) + "}";
                    }
                    else
                    {
                        result = "{\"result\":\"failed\"}";
                    }
                    break;

                default:
                    break;
                }
            }
            context.Response.Write(result);
        }
コード例 #4
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string code = context.Request.QueryString["code"];

            context.Response.AddHeader("Access-Control-Allow-Origin", "*");

            //context.Response.Write("AuthorizationCheckByCodeHandler:" + code);
            string RedirectPage = "";
            string returnresult = "{\"result:\":\"{0}\",\"RedirectPage\":\"{1}\"}";

            try
            {
                //构造获取openid及access_token的url
                WxPayData data = new WxPayData();
                data.SetValue("appid", WxPayConfig.APPID);
                data.SetValue("secret", WxPayConfig.APPSECRET);
                data.SetValue("code", code);
                data.SetValue("grant_type", "authorization_code");
                string url = "https://api.weixin.qq.com/sns/oauth2/access_token?" + data.ToUrl();
                Log.Debug(this.GetType().ToString(), "GetOpenidAndAccessTokenFromCode url : " + url);
                //请求url以获取数据
                string result = HttpService.Get(url);

                Log.Debug(this.GetType().ToString(), "GetOpenidAndAccessTokenFromCode response : " + result);

                //保存access_token,用于收货地址获取
                JsonData jd = JsonMapper.ToObject(result);
                Log.Debug(this.GetType().ToString(), "GetOpenidAndAccessTokenFromCode Result : " + result);
                var access_token = (string)jd["access_token"];
                //Response.Write(result);

                //获取用户openid
                var       openid       = (string)jd["openid"];
                WxPayData dataUserInfo = new WxPayData();
                dataUserInfo.SetValue("access_token", access_token);
                dataUserInfo.SetValue("openid", openid);

                DataTable checkuserDT = MySqlHelp.ExecuteDataTable(@"select tu.*
,
CASE
WHEN  la.agencylevel is null THEN 'L0'
ELSE la.agencylevel
END as 'agencylevel',
CASE
WHEN  la.agencylevel is null THEN '1'
ELSE la.discount
END as 'discount'
from t_user tu
left join t_agencylevel la
on tu.id=la.userid and la.enabled='1'
where tu.openid=" + UtilityFn.formatstring(openid));

                //数据库里是否有用户信息
                if (checkuserDT.Rows.Count > 0)
                {
                    if (FormatWeXUser(checkuserDT, context))
                    {
                        var ActionPage = context.Request.QueryString["ActionPage"];
                        if (!string.IsNullOrEmpty(ActionPage))
                        {
                            //Response.Redirect(ActionPage, false);
                            RedirectPage = ActionPage;
                        }
                        else
                        {
                            //Response.Redirect("home.aspx", false);
                            RedirectPage = "home.aspx";
                        }
                    }
                    else
                    {
                        //Response.Redirect("/Order/MyInfoPage.aspx", false);
                        RedirectPage = "/Order/MyInfoPage.aspx";
                    }
                    //Log.Info("Get User End", "=========" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));

                    //Response.Redirect("home.aspx", false);
                }
                else
                {
                    //Response.Redirect("login.aspx", false);
                    RedirectPage = "login.aspx";
                }


                //Response.Write(result);

                //Log.Debug(this.GetType().ToString(), "Get openid : " + openid);
                //Log.Debug(this.GetType().ToString(), "Get access_token : " + access_token);

                context.Response.Write("{\"result:\":\"success\",\"RedirectPage\":\"" + RedirectPage + "\"}");
            }
            catch (Exception ex)
            {
                Log.Error(this.GetType().ToString(), ex.ToString());
                //throw new WxPayException(ex.ToString());
                context.Response.Write("{\"result:\":\"failed\",\"RedirectPage\":\"\"}");
            }
        }
コード例 #5
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Charset     = "utf-8";

            string Action = context.Request["Action"].ToString();

            string result = "{\"result\":\"failed\"}";

            if (!string.IsNullOrEmpty(Action))
            {
                Auth     auth     = new Token(CurToken); // Auth auth = new Sign("app_id", "app_secret");
                YZClient yzClient = new DefaultYZClient(auth);
                Dictionary <string, object> dict;
                switch (Action)
                {
                case "getgiftcard":
                    dict = new System.Collections.Generic.Dictionary <string, object>();
                    dict.Add("page_no", 1);
                    dict.Add("page_size", 100);
                    //dict.Add("status", "ON");
                    dict.Add("group_type", "PROMOCODE");
                    result = yzClient.Invoke("youzan.ump.coupon.search", "3.0.0", "POST", dict, null);
                    break;

                case "giftcardtake":
                    string    _openid   = context.Request["openid"].ToString();
                    string    _mobile   = context.Request["mobile"].ToString();
                    string    _name     = context.Request["name"].ToString();
                    string    _cardcode = context.Request["cardcode"].ToString();
                    int       _PROMOCODEid;
                    string    getsql = "select * from giftcard where giftcardcode = '" + _cardcode + "'";
                    DataTable odDT   = MySqlHelp.ExecuteDataTable(getsql);

                    if (odDT.Rows.Count > 0)
                    {
                        if (odDT.Rows[0]["enabled"].ToString() == "0")
                        {
                            result = "{\"response\": {\"issuccess\": 0,\"msg\": \"该礼品卡暂不可用,请联系公司负责人!\"}}";
                        }
                        else if (odDT.Rows[0]["isused"].ToString() == "1")
                        {
                            result = "{\"response\": {\"issuccess\": 0,\"msg\": \"该礼品卡已被领用,不能重复注册!\"}}";
                        }
                        else
                        {
                            try
                            {
                                _PROMOCODEid = Convert.ToInt32(odDT.Rows[0]["PromoId"]);

                                dict = new System.Collections.Generic.Dictionary <string, object>();
                                dict.Add("mobile", _mobile);
                                dict.Add("coupon_group_id", _PROMOCODEid);

                                result = yzClient.Invoke("youzan.ump.coupon.take", "3.0.0", "POST", dict, null);

                                InvokeResponse Response = JsonUtility.Deserialize <InvokeResponse>(result);
                                if (Response.error_response == null && Response.response != null && Response.response.coupon_type == "PROMOCODE")
                                {
                                    var updatecard = "update giftcard set isused='1',useddate='" + DateTime.Now.ToString("yyyy-MM-dd") + "',usedmobile='" + _mobile + "',usedopenid='" + _openid + "',usedname='" + _name + "' where giftcardcode='" + _cardcode.Replace("-", "") + "'";
                                    MySqlHelp.ExecuteNonQuery(updatecard);
                                    DataTable dt = MySqlHelp.ExecuteDataTable("select jumpurl from giftcard where giftcardcode='" + _cardcode.Replace("-", "") + "'");
                                    result = "{\"response\": {\"issuccess\": \"1\",\"msg\": \"验证成功!\",\"jumpurl\":\"" + dt.Rows[0]["jumpurl"].ToString() + "\"}}";
                                }
                                else
                                {
                                    result = "{\"response\": {\"issuccess\": \"0\",\"msg\": \"" + Response.error_response.msg + "\"}}";
                                }
                            }
                            catch (Exception ex)
                            {
                                result = "{\"response\": {\"issuccess\": 0,\"msg\": \"" + ex.Message + "!\"}}";
                            }
                        }
                    }
                    else
                    {
                        result = "{\"response\": {\"issuccess\": 0,\"msg\": \"礼品卷不存在,请验证礼品卷码是否填写正确!\"}}";
                    }
                    break;

                case "giftcardtakelist":
                    DataTable dttakelist = MySqlHelp.ExecuteDataTable("select * from giftcard");
                    result = "{\"response\": {\"issuccess\": \"1\",\"msg\": \"验证成功!\",\"giftcardlist\":" + formatgiftcard(dttakelist) + "}}";

                    break;

                case "cardactive":
                    string _ids1 = context.Request["ids"].ToString();
                    MySqlHelp.ExecuteNonQuery("update giftcard set enabled=1 where id in (" + _ids1 + ")and isused = 0");
                    result = "{\"response\": {\"issuccess\": \"1\",\"msg\": \"验证成功!\"}}";

                    break;

                case "cardinactive":
                    string _ids2 = context.Request["ids"].ToString();
                    MySqlHelp.ExecuteNonQuery("update giftcard set enabled=0 where id in (" + _ids2 + ") and isused = 0");
                    result = "{\"response\": {\"issuccess\": \"1\",\"msg\": \"验证成功!\"}}";

                    break;

                default:
                    break;
                }
            }
            context.Response.Write(result);
        }