예제 #1
0
        public dynamic HXCoupon(dynamic arg)
        {
            try
            {
                string code    = base.GetValue <string>("code");
                string card_id = base.GetValue <string>("card_id");
                //string token = Token(AppConfig.FWHOriginalID);
                string resmsg = NetHelper.HttpRequest(AppConfig.BeautyChinaWebApp, "", "GET", 2000,
                                                      Encoding.UTF8, "application/json");

                TokeRes toke  = JsonHelper.DeserializeObject <TokeRes>(resmsg);
                string  token = toke.Access_Token;
                string  url   = "https://api.weixin.qq.com/card/code/consume?access_token=" + token;
                string  json  = @"{
  ""code"": ""{0}"",
  ""card_id"": """ + card_id + @"""}";
                json = json.Replace("{0}", code);
                var resMessage = NetHelper.HttpRequest(url, json, "POST", 2000, Encoding.UTF8, "application/json");
                //{ "errcode":0,"errmsg":"ok","card":{                "card_id":"pFS7Fjg8kV1IdDz01r4SQwMkuCKc"},"openid":"oFS7Fjl0WsZ9AMZqrI80nbIq8xrA"}
                if (resMessage.Split('"')[5] == "ok")
                {
                    _logwarn.Warn("核销成功!code=" + code + " ,card_id=" + card_id);
                    return(ResponseJson(true, "ok", "核销成功"));
                }
                return(ResponseJson(false, "error", "核销失败"));
            }
            catch (Exception ex)
            {
                return(ResponseJson(false, "error", "核销异常" + ex.Message));
            }
        }
예제 #2
0
        private dynamic CreateStore(dynamic arg)
        {
            string resmsg = NetHelper.HttpRequest(AppConfig.BeautyChinaWebApp, "", "GET", 2000,
                                                  Encoding.UTF8, "application/json");

            TokeRes toke       = JsonHelper.DeserializeObject <TokeRes>(resmsg);
            string  token      = toke.Access_Token;
            string  url        = "	http://api.weixin.qq.com/cgi-bin/poi/addpoi?access_token="+ token;
            string  json       = @"{""business"":{
                            ""base_info"":{
                            ""sid"":""56788392"",
                            ""business_name"":""佰草集"",
                            ""branch_name"":""全国各大专柜"",
                            ""province"":""上海市"",
                            ""city"":""上海市"",
                            ""district"":""虹口区"",
                            ""address"":""上海保定路527号"",
                            ""telephone"":""021-35907000"",
                            ""categories"":[""美容spa""],
                            ""offset_type"":3,
                            ""longitude"":121.50074,
                            ""latitude"":31.25493,
                            ""open_time"":""10:00-23:00""
                            }
                            }
                            }";
            var     resMessage = NetHelper.HttpRequest(url, json, "POST", 2000, Encoding.UTF8, "application/json");

            return(ResponseJson(true, resMessage));
        }
예제 #3
0
        public string HXCoupon(string code, string card_id)
        {
            try
            {
                string resmsg = NetHelper.HttpRequest(AppConfig.TokenUrl, "", "GET", 2000,
                                                      Encoding.UTF8, "application/json");

                TokeRes toke  = JsonHelper.DeserializeObject <TokeRes>(resmsg);
                string  token = toke.Access_Token;
                string  url   = "https://api.weixin.qq.com/card/code/consume?access_token=" + token;
                string  json  = @"{
  ""code"": ""{0}"",
  ""card_id"": """ + card_id + @"""}";
                json = json.Replace("{0}", code);
                var resMessage = NetHelper.HttpRequest(url, json, "POST", 2000, Encoding.UTF8, "application/json");
                if (resMessage.Split('"')[5] == "ok")
                {
                    response.Status  = 1;
                    response.Message = "核销成功";
                    return(JsonHelper.ToJSON(response));
                }

                response.Status  = 0;
                response.Message = "核销失败";
                return(JsonHelper.ToJSON(response));
            }
            catch (Exception ex)
            {
                WriteTxt("核销卡券异常:card_id=" + card_id + " 异常信息:" + ex.Message);
                response.Status  = 0;
                response.Message = "核销异常" + ex.Message;
                //WriteTxt();
                return(JsonHelper.ToJSON(response));
            }
        }
예제 #4
0
        /// <summary>
        /// 自己封装耗时的方法
        /// </summary>
        /// <returns></returns>
        public static Task SendTmpsByMember(List <WX_TMP_HIS> his)
        {
            return(Task.Run(() =>
            {
                foreach (WX_TMP_HIS item in his)
                {
                    string resmsg = NetHelper.HttpRequest(AppConfig.BeautyChinaWebApp, "", "GET", 2000,
                                                          Encoding.UTF8, "application/json");
                    string tmpStr = item.DETAIL;
                    TokeRes toke = JsonHelper.DeserializeObject <TokeRes>(resmsg);
                    string resot = string.Empty;
                    resot = NetHelper.HttpRequest("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="
                                                  + toke.Access_Token, tmpStr, "POST", 2000, Encoding.UTF8, "application/json");


                    //如果发送成功
                    if (resot.Contains("ok"))
                    {
                        _logdebug.Info("执行模板消息发送定时任务,当前时间:" + DateTime.Now + ";发送结果:成功,发送内容:" + tmpStr);
                        mymember.UpdateWxTmpHisIsSendByID(item.ID, 1, resot);
                    }
                    else
                    {
                        _logdebug.Info("执行模板消息发送定时任务,当前时间:" + DateTime.Now + ";发送结果:失败,发送内容:" + tmpStr);
                        mymember.UpdateWxTmpHisIsSendByID(item.ID, 1, resot);
                    }
                }
            }));
        }
예제 #5
0
        public string LQCoupon(string OpendID)
        {
            var    cardId     = AppConfig.CardId;
            string signature  = "";
            string timestamp  = "";
            string api_ticket = "";
            string sjm        = Guid.NewGuid().ToString("d"); //随机码
            string nonce_str  = "noncestr=" + sjm;            //签名必须要用到随机数

            //string code = new Random().Next(111111111, 999999999).ToString();
            //string openid = OpendID;// "oDRuD1DSi1yyDx9x4_Ttpf_0haB0";

            timestamp = Utility.ConvertDateTimeInt(DateTime.Now).ToString();
            //string token = Token(AppConfig.FWHOriginalID);
            string resmsg = NetHelper.HttpRequest(AppConfig.TokenUrl, "", "GET", 2000,
                                                  Encoding.UTF8, "application/json");

            TokeRes toke  = JsonHelper.DeserializeObject <TokeRes>(resmsg);
            string  token = toke.Access_Token;


            string resticket = NetHelper.HttpRequest(AppConfig.CardApiTokenUrl, "", "GET", 2000,
                                                     Encoding.UTF8, "application/json");

            JsApiTicket JsApiTicket = JsonHelper.DeserializeObject <JsApiTicket>(resticket);

            api_ticket = JsApiTicket.JsApi; // WXCardCommon.GetCardApi(token);
                                            //api_ticket = WXCardCommon.GetCardApi(token);
            //string[] ArrTmp = { cardId, timestamp, api_ticket, code, openid };
            string[] ArrTmp = { cardId, timestamp, api_ticket, nonce_str };
            Array.Sort(ArrTmp);
            string tmpStr = string.Join("", ArrTmp);

            tmpStr    = FormsAuthentication.HashPasswordForStoringInConfigFile(tmpStr, "SHA1");
            signature = tmpStr;

            CardExt cardExt = new CardExt();

            cardExt.timestamp = timestamp;
            cardExt.signature = signature;
            cardExt.nonce_str = nonce_str;
            //cardExt.code = code;
            //cardExt.openid = openid;
            var retcardExt = JsonConvert.SerializeObject(cardExt);


            CardInfoExt CardInfo = new CardInfoExt();

            CardInfo.cardId  = cardId;
            CardInfo.cardExt = retcardExt;

            response.Status = 1;
            response.Data   = CardInfo;



            return(JsonHelper.ToJSON(response));
        }
예제 #6
0
        //导入卡券
        protected void btnImportCoupon_Click(object sender, EventArgs e)
        {
            XHYCouponService _xyhservice = new XHYCouponService();
            string           message     = "";
            string           url         = "";
            string           json        = "";
            string           cardid      = this.txtCardId.Text;

            string resmsg = NetHelper.HttpRequest(AppConfig.TokenUrl, "", "GET", 2000,
                                                  Encoding.UTF8, "application/json");

            TokeRes toke  = JsonHelper.DeserializeObject <TokeRes>(resmsg);
            string  token = toke.Access_Token;
            List <WXCouponNoInfo> list = _xyhservice.QueryWXCouponNoInfo(cardid);

            int    succ_cnt = 0;
            string codes    = "";

            foreach (WXCouponNoInfo model in list)
            {
                url  = "http://api.weixin.qq.com/card/code/deposit?access_token=" + token;
                json = @"{
                                   ""card_id"": """ + cardid + @""",
                                   ""code"": [
                                       """ + model.CouponNo + @"""
                                   ]
                                }";
                var resMessage = NetHelper.HttpRequest(url, json, "POST", 2000, Encoding.UTF8, "application/json");
                if (resMessage.Contains("succ_code")) //成功
                {
                    succ_cnt++;
                    _xyhservice.UpdateWXCouponNoInfoIsImport(model.id);
                }
                else
                {
                    message = resMessage + "<br>ID:" + model.id;
                }
                codes += "\"" + model.CouponNo + "\",";
            }
            codes = codes.Substring(0, codes.Length - 1);

            if (succ_cnt > 0)
            {
                //修改库存
                url  = "https://api.weixin.qq.com/card/modifystock?access_token=" + token;
                json = @"{""card_id"": """ + cardid + @""",""increase_stock_value"":" + succ_cnt + @",""reduce_stock_value"": 0}";
                var resMessage = NetHelper.HttpRequest(url, json, "POST", 2000, Encoding.UTF8, "application/json");
            }

            //核查code接口
            url     = "http://api.weixin.qq.com/card/code/checkcode?access_token=" + token;
            json    = @"{""card_id"": """ + cardid + @""",""code"":[" + codes + @"]}";
            message = NetHelper.HttpRequest(url, json, "POST", 2000, Encoding.UTF8, "application/json");

            this.txtImportCouponLog.Text = message;
        }
예제 #7
0
        public dynamic GetCardDetail(dynamic arg)
        {
            try
            {
                string code    = base.GetValue <string>("code");
                string card_id = base.GetValue <string>("card_id");
                string resmsg  = NetHelper.HttpRequest(AppConfig.BeautyChinaWebApp, "", "GET", 2000,
                                                       Encoding.UTF8, "application/json");

                TokeRes toke  = JsonHelper.DeserializeObject <TokeRes>(resmsg);
                string  token = toke.Access_Token;
                //string token = Token(AppConfig.FWHOriginalID);
                cardInfo cardInfo = new cardInfo();
                cardInfo.card_id = card_id;
                string url        = "https://api.weixin.qq.com/card/code/decrypt?access_token=" + token;
                string json       = @"{""encrypt_code"":""" + code + @"""}";
                string resMessage = NetHelper.HttpRequest(url, json, "POST", 2000, Encoding.UTF8, "application/json");

                //{"errcode":0,  "errmsg":"ok",  "code":"751234212312"}
                if (resMessage.Contains("\"ok\""))
                {
                    code          = resMessage.Split('"')[9];
                    cardInfo.code = code;
                    //查询卡券信息
                    url        = "https://api.weixin.qq.com/card/get?access_token=" + token;
                    json       = @"{
                            ""card_id"": """ + card_id + @"""
                           }";
                    resMessage = NetHelper.HttpRequest(url, json, "POST", 2000, Encoding.UTF8, "application/json");
                    if (resMessage.Contains("\"ok\""))
                    {
                        try
                        {
                            var brand_name = resMessage.Substring(resMessage.IndexOf("brand_name") + 10).Split('"')[2];
                            var title      = resMessage.Substring(resMessage.IndexOf("title") + 5).Split('"')[2];
                            var color      = resMessage.Substring(resMessage.IndexOf("color") + 5).Split('"')[2];
                            cardInfo.brand_name = brand_name;
                            cardInfo.title      = title;
                            cardInfo.color      = color;
                        }
                        catch
                        {
                            cardInfo.brand_name = "";
                            cardInfo.title      = "";
                            cardInfo.color      = "";
                        }
                    }
                }
                string cardInfoMsg = JsonConvert.SerializeObject(cardInfo);
                return(ResponseJson(true, "ok", cardInfoMsg));
            }
            catch (Exception ex)
            {
                return(ResponseJson(false, "error", "核销异常" + ex.Message));
            }
        }
예제 #8
0
        public string GetCardDetail(string code, string card_id)
        {
            try
            {
                string resmsg = NetHelper.HttpRequest(AppConfig.TokenUrl, "", "GET", 2000,
                                                      Encoding.UTF8, "application/json");

                TokeRes  toke     = JsonHelper.DeserializeObject <TokeRes>(resmsg);
                string   token    = toke.Access_Token;
                cardInfo cardInfo = new cardInfo();
                cardInfo.card_id = card_id;
                string url        = "https://api.weixin.qq.com/card/code/decrypt?access_token=" + token;
                string json       = @"{""encrypt_code"":""" + code + @"""}";
                string resMessage = NetHelper.HttpRequest(url, json, "POST", 2000, Encoding.UTF8, "application/json");

                if (resMessage.Contains("\"ok\""))
                {
                    code          = resMessage.Split('"')[9];
                    cardInfo.code = code;
                    //查询卡券信息
                    url        = "https://api.weixin.qq.com/card/get?access_token=" + token;
                    json       = @"{
                            ""card_id"": """ + card_id + @"""
                           }";
                    resMessage = NetHelper.HttpRequest(url, json, "POST", 2000, Encoding.UTF8, "application/json");
                    if (resMessage.Contains("\"ok\""))
                    {
                        try
                        {
                            var brand_name = resMessage.Substring(resMessage.IndexOf("brand_name") + 10).Split('"')[2];
                            var title      = resMessage.Substring(resMessage.IndexOf("title") + 5).Split('"')[2];
                            var color      = resMessage.Substring(resMessage.IndexOf("color") + 5).Split('"')[2];
                            cardInfo.brand_name = brand_name;
                            cardInfo.title      = title;
                            cardInfo.color      = color;
                        }
                        catch
                        {
                            cardInfo.brand_name = "";
                            cardInfo.title      = "";
                            cardInfo.color      = "";
                        }
                    }
                }
                string cardInfoMsg = JsonConvert.SerializeObject(cardInfo);
                response.Status = 1;
                response.Data   = cardInfoMsg;
            }
            catch (Exception ex)
            {
                response.Status  = 0;
                response.Message = "核销异常" + ex.Message;
                response.Data    = null;
            }
            return(JsonHelper.ToJSON(response));
        }
예제 #9
0
        public CommonModule() : base("/User")
        {
            Get["/GetCity"] = x =>
            {
                List <CityResDTO> list = DefutService.GetAdministrativeDivision();
                return(ResponseJson(true, "OK", list));
            };

            Post["/SendTmps"] = x =>
            {
                BCJ_TMP_DETAIL request = base.BindObject <BCJ_TMP_DETAIL>();
                try
                {
                    if (string.IsNullOrEmpty(request.Template_Code))
                    {
                        return(ResponseJson(false, "模板ID不能是空"));
                    }

                    string resmsg = NetHelper.HttpRequest(AppConfig.BeautyChinaWebApp, "", "GET", 2000,
                                                          Encoding.UTF8, "application/json");

                    TokeRes toke = JsonHelper.DeserializeObject <TokeRes>(resmsg);

                    int str = _hmjMember.SendTmp(request, toke.Access_Token);

                    if (str == -1)
                    {
                        return(ResponseJson(false, "没有该模板,请查看模板ID"));
                    }

                    return(ResponseJson(true, "OK"));
                }
                catch (Exception ex)
                {
                    WriteLog("发送模板消息", ex);
                    return(ResponseJsonError(false, error_message, ex));
                }
            };


            #region 微信卡券信息

            Get["/CreateStore"]         = CreateStore;
            Get["/CreateCoupon"]        = CreateCoupon;        //创建卡券
            Get["/UpdateCoupon"]        = UpdateCoupon;        //修好卡券
            Get["/ImportCoupon"]        = ImportCoupon;        //导入卡券
            Get["/HXCoupon"]            = HXCoupon;            //核销卡券
            Get["/SettingCouponHXType"] = SettingCouponHXType; //设置券核销方式
            Get["/GetCardDetail"]       = GetCardDetail;
            #endregion

            Post["/AddLog"] = AddLog;
        }
예제 #10
0
        public bool HXCoupon(string code, string card_id)
        {
            XHYCouponService _xyhservice = new XHYCouponService();

            try
            {
                string resmsg = NetHelper.HttpRequest(AppConfig.TokenUrl, "", "GET", 2000,
                                                      Encoding.UTF8, "application/json");

                TokeRes toke  = JsonHelper.DeserializeObject <TokeRes>(resmsg);
                string  token = toke.Access_Token;
                string  url   = "https://api.weixin.qq.com/card/code/consume?access_token=" + token;
                string  json  = @"{
  ""code"": ""{0}"",
  ""card_id"": """ + card_id + @"""}";
                json = json.Replace("{0}", code);
                var resMessage = NetHelper.HttpRequest(url, json, "POST", 2000, Encoding.UTF8, "application/json");
                //{ "errcode":0,"errmsg":"ok","card":{                "card_id":"pFS7Fjg8kV1IdDz01r4SQwMkuCKc"},"openid":"oFS7Fjl0WsZ9AMZqrI80nbIq8xrA"}
                if (resMessage.Split('"')[5] == "ok")
                {
                    //_logwarn.Warn("核销成功!code=" + code + " ,card_id=" + card_id);

                    _xyhservice.AddLodInfo(new Tb_log()
                    {
                        title = "核销卡券", msgType = "message", msgContent = "核销成功!code=" + code + " ,card_id=" + card_id, createDate = DateTime.Now
                    });
                    return(true);
                }
                _xyhservice.AddLodInfo(new Tb_log()
                {
                    title = "核销卡券", msgType = "error", msgContent = "核销失败", createDate = DateTime.Now
                });
                return(false);
            }
            catch (Exception ex)
            {
                _xyhservice.AddLodInfo(new Tb_log()
                {
                    title = "核销异常", msgType = "exception", msgContent = "核销异常:" + ex.Message, createDate = DateTime.Now
                });
                return(false);
            }
        }
예제 #11
0
        private dynamic SettingCouponHXType(dynamic arg)
        {
            string CardId = base.GetValue <string>("CardId");
            //string token = Token(AppConfig.FWHOriginalID);
            string resmsg = NetHelper.HttpRequest(AppConfig.BeautyChinaWebApp, "", "GET", 2000,
                                                  Encoding.UTF8, "application/json");

            TokeRes toke       = JsonHelper.DeserializeObject <TokeRes>(resmsg);
            string  token      = toke.Access_Token;
            string  url        = "https://api.weixin.qq.com/card/selfconsumecell/set?access_token=" + token;
            string  json       = @"{""card_id"":""" + CardId + @""",  ""is_open"": true}";
            string  resMessage = NetHelper.HttpRequest(url, json, "POST", 2000, Encoding.UTF8, "application/json");

            if (resMessage.Split('"')[5] == "ok")
            {
                return(ResponseJson(true, "卡券自助核销设置成功"));
            }
            else
            {
                return(ResponseJson(true, "卡券自助核销设置失败"));
            }
        }
예제 #12
0
        private dynamic UpdateCoupon(dynamic arg)
        {
            string resmsg = NetHelper.HttpRequest(AppConfig.BeautyChinaWebApp, "", "GET", 2000,
                                                  Encoding.UTF8, "application/json");
            string  CardId = base.GetValue <string>("CardId");
            TokeRes toke   = JsonHelper.DeserializeObject <TokeRes>(resmsg);
            string  token  = toke.Access_Token;
            string  url    = "https://api.weixin.qq.com/card/update?access_token=" + token;


            string         json       = @"{
                ""card_id"":""" + CardId + @""",
               ""general_coupon"": {
                            ""base_info"": {
                            ""logo_url"": ""https://mmbiz.qlogo.cn/mmbiz_jpg/c8icWUnxBQmEib9ZUicSFGkBiaRg4cbYxq1p3JygXK3eC0Rfy5HocvYdbOJGQaRJNfCDfFJBib7AsRQeZFqFtNADwBw/0"",
                            ""color"": ""Color020"",
                           
                            ""center_title"": ""立即使用"",
                            ""center_sub_title"": """",
                            ""center_url"": """ + AppConfig.HmjWebApp + @"assets/hmjweixin/html/hxcoupon.html"",
                            ""get_limit"":10
                            }
               }
            }";
            var            resMessage = NetHelper.HttpRequest(url, json, "POST", 2000, Encoding.UTF8, "application/json");
            CouponResponse response   = JsonConvert.DeserializeObject <CouponResponse>(resMessage);

            if (response.errmsg == "ok")
            {
                return(ResponseJson(true, "卡券修改成功,cardId=" + CardId));
            }
            else
            {
                return(ResponseJson(false, "卡券修改失败"));
            }
        }
예제 #13
0
        public dynamic ImportCoupon(dynamic arg)
        {
            string message = "";
            string url     = "";
            string json    = "";
            string cardid  = base.GetValue <string>("cardid");
            //string resmsg = NetHelper.HttpRequest(AppConfig.BeautyChinaWebApp, "", "GET", 2000,
            //    Encoding.UTF8, "application/json");
            //TokeRes toke = JsonHelper.DeserializeObject<TokeRes>(resmsg);
            //string token = Token(AppConfig.FWHOriginalID);
            string resmsg = NetHelper.HttpRequest(AppConfig.BeautyChinaWebApp, "", "GET", 2000,
                                                  Encoding.UTF8, "application/json");

            TokeRes toke  = JsonHelper.DeserializeObject <TokeRes>(resmsg);
            string  token = toke.Access_Token;
            List <WXCouponNoInfo> list = _hmjMember.QueryWXCouponNoInfo();

            int    succ_cnt = 0;
            string codes    = "";

            foreach (WXCouponNoInfo model in list)
            {
                url  = "http://api.weixin.qq.com/card/code/deposit?access_token=" + token;
                json = @"{
                                   ""card_id"": """ + cardid + @""",
                                   ""code"": [
                                       """ + model.CouponNo + @"""
                                   ]
                                }";
                var resMessage = NetHelper.HttpRequest(url, json, "POST", 2000, Encoding.UTF8, "application/json");
                if (resMessage.Contains("succ_code")) //成功
                {
                    succ_cnt++;
                    _hmjMember.UpdateWXCouponNoInfoIsImport(model.id);
                }
                else
                {
                    message = resMessage + "<br>ID:" + model.id;
                }
                codes += "\"" + model.CouponNo + "\",";
            }
            codes = codes.Substring(0, codes.Length - 1);

            if (succ_cnt > 0)
            {
                //修改库存
                url  = "https://api.weixin.qq.com/card/modifystock?access_token=" + token;
                json = @"{""card_id"": """ + cardid + @""",""increase_stock_value"":" + succ_cnt + @",""reduce_stock_value"": 0}";
                var resMessage = NetHelper.HttpRequest(url, json, "POST", 2000, Encoding.UTF8, "application/json");
                //if (resMessage.Contains("ok"))
                //{
                //    if (message != "")
                //    {
                //        message = "{\"meg\":\"" + message + "\",\"succ_cnt\":" + succ_cnt + "}";
                //    }
                //    else
                //    {
                //        message = "{\"meg\":\"ok\",\"succ_cnt\":" + succ_cnt + "}";
                //    }
                //}
            }

            //核查code接口
            url     = "http://api.weixin.qq.com/card/code/checkcode?access_token=" + token;
            json    = @"{""card_id"": """ + cardid + @""",""code"":[" + codes + @"]}";
            message = NetHelper.HttpRequest(url, json, "POST", 2000, Encoding.UTF8, "application/json");


            return(message);
        }
예제 #14
0
        public void ProcessRequest(HttpContext context)
        {
            if (GetQeuryString("para", context) == "jsapi") //获取js接口凭证
            {
                try
                {
                    //string token =  w.Token();//w.mjuserid
                    string resmsg = NetHelper.HttpRequest(AppConfig.TokenUrl, "", "GET", 2000,
                                                          Encoding.UTF8, "application/json");
                    TokeRes toke  = JsonHelper.DeserializeObject <TokeRes>(resmsg);
                    string  token = toke.Access_Token;
                    string  sj    = ConvertDateTimeInt(DateTime.Now).ToString(); //时间戳
                    string  sjm   = Guid.NewGuid().ToString("d");                //随机码

                    string jsapimsg = NetHelper.HttpRequest(AppConfig.JsApiTokenUrl, "", "GET", 2000,
                                                            Encoding.UTF8, "application/json");
                    JsApiTicket jat = JsonHelper.DeserializeObject <JsApiTicket>(jsapimsg);


                    string ticket = jat.JsApi;                                                        // GetJSAPI_Ticket(token, m); //凭证
                    //WriteTxt("js注册:apiurl=" + context.Request.Params["apiurl"]);
                    string dz           = context.Server.UrlDecode(context.Request.Params["apiurl"]); //context.Request.Params["apiurl"];//
                    string noncestr     = "noncestr=" + sjm;
                    string jsapi_ticket = "jsapi_ticket=" + ticket;
                    string timestamp    = "timestamp=" + sj;
                    string url          = "url=" + dz;
                    //WriteTxt("js注册:url="+ dz);
                    string[] ArrTmp = { noncestr, jsapi_ticket, timestamp, url };
                    Array.Sort(ArrTmp);         //字典排序
                    string tmpStr = string.Join("&", ArrTmp);
                    //WriteTxt("js注册:tmpStr=" + tmpStr);
                    tmpStr = FormsAuthentication.HashPasswordForStoringInConfigFile(tmpStr, "SHA1");
                    tmpStr = tmpStr.ToLower();
                    if (ticket == "")
                    {
                        //WriteTxt("js注册:失败" );
                        context.Response.Write("{\"status\":\"" + -1 + "\"}");
                    }
                    else
                    {
                        var re = new
                        {
                            state     = 0,
                            appId     = AppConfig.WXAppId,
                            timestamp = sj,
                            nonceStr  = sjm,
                            signature = tmpStr,
                            url       = dz,
                            link      = (dz.IndexOf("&") == -1 ? dz : dz.Substring(0, dz.IndexOf("&"))),
                            title     = "",
                            imgUrl    = ConfigurationSettings.AppSettings["WebUrl"] + "/wechat/XYH_Coupon_H5/images/logo.jpg",
                            desc      = ""
                        };
                        string ret = JsonConvert.SerializeObject(re);
                        //WriteTxt("js注册:" + ret);
                        context.Response.Write(ret);
                    }
                }
                catch (Exception ex)
                {
                    context.Response.Write(ex.Message + "," + ex.StackTrace);
                }
            }
            else if (GetQeuryString("para", context) == "upimg") //上传图片
            {
            }
            else if (GetQeuryString("para", context) == "delete") //上传图片
            {
            }
            else if (GetQeuryString("para", context) == "pv")
            {
                try
                {
                    PVData pv = new PVData();
                    pv.DOMAIN   = context.Request.Params[1];
                    pv.URL      = context.Request.Params[2];
                    pv.TITLE    = context.Request.Params[3];
                    pv.REFERRER = context.Request.Params[4];
                    pv.SH       = context.Request.Params[5];
                    pv.SW       = context.Request.Params[6];
                    pv.CD       = context.Request.Params[7];
                    pv.ACCOUNT  = context.Request.Params[9];
                    pv.LTIME    = context.Request.Params[10];
                    mss.InsertPVData(pv);
                }
                catch { }
            }
        }
예제 #15
0
        private dynamic CreateCoupon(dynamic arg)
        {
            //TimeSpan ts = Convert.ToDateTime("2018-05-15 00:00:00") - Convert.ToDateTime("1970-01-01 00:00:00");
            //int spend_time = Convert.ToInt32(ts.TotalSeconds);
            //long begin_timestamp = spend_time;

            //ts = Convert.ToDateTime("2018-05-23 23:59:59") - Convert.ToDateTime("1970-01-01 00:00:00");
            //spend_time = Convert.ToInt32(ts.TotalSeconds);
            //long end_timestamp = spend_time;//计算出来的时间会往后推8小时

            long begin_timestamp = 1527177600; //2018-05-25 00:00:00
            //long begin_timestamp = 1526313600;//2018-05-15 00:00:00
            long end_timestamp = 1528646399;   //2018-06-10 23:59:59
            //long end_timestamp = 1527091199;//2018-05-23 23:59:59
            string resmsg = NetHelper.HttpRequest(AppConfig.BeautyChinaWebApp, "", "GET", 2000,
                                                  Encoding.UTF8, "application/json");

            TokeRes toke  = JsonHelper.DeserializeObject <TokeRes>(resmsg);
            string  token = toke.Access_Token;
            string  url   = "https://api.weixin.qq.com/card/create?access_token=" + token;
            string  json  = @"{ 
            ""card"": {
              ""card_type"": ""GENERAL_COUPON"",
              ""general_coupon"": {
                  ""base_info"": {
                      ""logo_url"": 
            ""https://mmbiz.qlogo.cn/mmbiz_jpg/c8icWUnxBQmEib9ZUicSFGkBiaRg4cbYxq1p3JygXK3eC0Rfy5HocvYdbOJGQaRJNfCDfFJBib7AsRQeZFqFtNADwBw/0"",
                      ""brand_name"":""佰草集"",
                      ""code_type"":""CODE_TYPE_TEXT"",
                      ""title"": ""5折优惠券"",
                      ""sub_title"": ""新恒美紧肤洁面乳爆款招新"",
                      ""color"": ""Color020"",
                      ""notice"": ""请出示您的唯一优惠券码"",
                      ""description"": ""1)优惠券仅限本人使用,不可转赠,每人限领一张
            2)活动仅限指定产品
            3)该活动仅限在佰草集专柜首次购买的顾客"",
                                                ""date_info"": {
                                          ""type"": ""DATE_TYPE_FIX_TIME_RANGE"",
                                          ""begin_timestamp"": " + begin_timestamp + " ,"
                            + @"""end_timestamp"":  " + end_timestamp + ""
                            + @" },
                        ""sku"": {
                          ""quantity"": 0
                      },
                      ""get_limit"": 1,
                      ""use_custom_code"": true,
                      ""get_custom_code_mode"":""GET_CUSTOM_CODE_MODE_DEPOSIT"",
                      ""bind_openid"": false,
                      ""can_share"": false,
                      ""can_give_friend"": false,
                      ""center_title"": ""立即使用"",
                          ""center_sub_title"": """",
                          ""center_url"": """ + AppConfig.HmjWebApp + @"assets/hmjweixin/html/hxcoupon.html""
                  },
               ""advanced_info"": {

                           ""time_limit"": [
                               {
                            ""type"": ""MONDAY"",
                                   ""begin_hour"":0,
                                   ""begin_minute"":0,
                                   ""end_hour"":23,
                                   ""end_minute"":59
                               },
                                 {
                            ""type"": ""TUESDAY"",
                               ""begin_hour"":0,
                                   ""begin_minute"":0,
                                   ""end_hour"":23,
                                   ""end_minute"":59
                               },
                                 {
                            ""type"": ""WEDNESDAY"",
                                  ""begin_hour"":0,
                                   ""begin_minute"":0,
                                   ""end_hour"":23,
                                   ""end_minute"":59
                               },
                                 {
                            ""type"": ""THURSDAY"",
                                   ""begin_hour"":0,
                                   ""begin_minute"":0,
                                   ""end_hour"":23,
                                   ""end_minute"":59
                               },
                                 {
                            ""type"": ""FRIDAY"",
                                ""begin_hour"":0,
                                   ""begin_minute"":0,
                                   ""end_hour"":23,
                                   ""end_minute"":59
                               },
                                 {
                            ""type"": ""SATURDAY"",
                                   ""begin_hour"":0,
                                   ""begin_minute"":0,
                                   ""end_hour"":23,
                                   ""end_minute"":59
                               },
                                 {
                            ""type"": ""SUNDAY"",
                                    ""begin_hour"":0,
                                   ""begin_minute"":0,
                                   ""end_hour"":23,
                                   ""end_minute"":59
                               }
                           ]

                       },
                  ""default_detail"": ""原价160元,现价80元""}
            }
            }";
            ///assets/hmjweixin/html/hxcoupon.html
            // ""center_url"": """+AppConfig.HmjWebApp + @"HmjMember/HXCoupon.do""
            var            resMessage = NetHelper.HttpRequest(url, json, "POST", 2000, Encoding.UTF8, "application/json");
            CouponResponse response   = JsonConvert.DeserializeObject <CouponResponse>(resMessage);

            //pDRuD1EutQ_b25Qd8c27hJ-rl7Do
            //{"status": 1,    "message": "{\"errcode\":0,\"errmsg\":\"ok\",\"card_id\":\"pDRuD1EutQ_b25Qd8c27hJ-rl7Do\"}",    "data": null}

            if (response.errmsg == "ok")
            {
                string cardId = response.card_id;
                //url = "https://api.weixin.qq.com/card/selfconsumecell/set?access_token=" + token;
                //json = @"{""card_id"":""" + cardId + @""",  ""is_open"": true}";//,""need_verify_cod"":false,""need_remark_amount"":false
                //resMessage = NetHelper.HttpRequest(url, json, "POST", 2000, Encoding.UTF8, "application/json");

                //if (resMessage.Split('"')[5] == "ok")
                //    return ResponseJson(true, "卡券创建成功,自助核销设置成功cardId="+ cardId);
                //else
                //    return ResponseJson(true, "卡券创建成功,自助核销设置失败cardId="+ cardId);
                return(ResponseJson(true, "卡券创建成功,cardId=" + cardId));
            }
            else
            {
                return(ResponseJson(false, "卡券创建失败"));
            }
        }
예제 #16
0
        protected void btnCreateCoupon1_Click(object sender, EventArgs e)
        {
            long begin_timestamp = 1529856000; //2018-06-25 00:00:00
            //1529856000  2018-06-25 00:00:00
            long end_timestamp = 1533052799;   //2018-07-31 23:59:59
            //1533052799   2018-07-31 23:59:59
            string resmsg = NetHelper.HttpRequest(AppConfig.TokenUrl, "", "GET", 2000,
                                                  Encoding.UTF8, "application/json");

            TokeRes toke  = JsonHelper.DeserializeObject <TokeRes>(resmsg);
            string  token = toke.Access_Token;
            string  url   = "https://api.weixin.qq.com/card/create?access_token=" + token;
            string  json  = @"{ 
            ""card"": {
              ""card_type"": ""GENERAL_COUPON"",
              ""general_coupon"": {
                  ""base_info"": {
                      ""logo_url"": 
            ""https://mmbiz.qlogo.cn/mmbiz_jpg/ugkm3wzgIFILaicicIzX7hfxblXziaEUliaGk37Q0VukC4tiaWB3lfcxYopOn72bHibaKEenbsPHzqpvxppHk3NanItw/0?wx_fmt=jpeg"",
                      ""brand_name"":""佰草集心约会"",
                      ""code_type"":""CODE_TYPE_TEXT"",
                      ""title"": ""指定产品60元抵用券"",
                      ""sub_title"": """",
                      ""color"": ""Color020"",
                      ""notice"": ""请出示您的唯一优惠券码"",
                      ""description"": ""1)此券仅限本人使用,不可转增
                                         2)凭券前往佰草集专柜注册成为会员后方可立即使用
                                         3)活动仅限入店购买指定产品「润·泽兰蕴美精华水」时抵扣"",
                      ""date_info"": {
                                          ""type"": ""DATE_TYPE_FIX_TIME_RANGE"",
                                          ""begin_timestamp"": " + begin_timestamp + " ,"
                            + @"""end_timestamp"":  " + end_timestamp + @" },
                       ""sku"": {
                            ""quantity"": 0
                      },
                      ""get_limit"": 1,
                      ""use_custom_code"": true,
                      ""get_custom_code_mode"":""GET_CUSTOM_CODE_MODE_DEPOSIT"",
                      ""bind_openid"": false,
                      ""can_share"": false,
                      ""can_give_friend"": false,
                      ""center_title"": ""立即使用"",
                          ""center_sub_title"": """",
                          ""center_url"": """ + AppConfig.ActivityWebApp + @"wechat/XYH_2TG_Coupon_H5/html/hxcoupon.html""
                  },
               ""advanced_info"": {

                           ""time_limit"": [
                               {
                            ""type"": ""MONDAY"",
                                   ""begin_hour"":0,
                                   ""begin_minute"":0,
                                   ""end_hour"":23,
                                   ""end_minute"":59
                               },
                                 {
                            ""type"": ""TUESDAY"",
                               ""begin_hour"":0,
                                   ""begin_minute"":0,
                                   ""end_hour"":23,
                                   ""end_minute"":59
                               },
                                 {
                            ""type"": ""WEDNESDAY"",
                                  ""begin_hour"":0,
                                   ""begin_minute"":0,
                                   ""end_hour"":23,
                                   ""end_minute"":59
                               },
                                 {
                            ""type"": ""THURSDAY"",
                                   ""begin_hour"":0,
                                   ""begin_minute"":0,
                                   ""end_hour"":23,
                                   ""end_minute"":59
                               },
                                 {
                            ""type"": ""FRIDAY"",
                                ""begin_hour"":0,
                                   ""begin_minute"":0,
                                   ""end_hour"":23,
                                   ""end_minute"":59
                               },
                                 {
                            ""type"": ""SATURDAY"",
                                   ""begin_hour"":0,
                                   ""begin_minute"":0,
                                   ""end_hour"":23,
                                   ""end_minute"":59
                               },
                                 {
                            ""type"": ""SUNDAY"",
                                    ""begin_hour"":0,
                                   ""begin_minute"":0,
                                   ""end_hour"":23,
                                   ""end_minute"":59
                               }
                           ]

                       },
                  ""default_detail"": ""指定产品60元抵用券""}
            }
            }";

            var            resMessage = NetHelper.HttpRequest(url, json, "POST", 2000, Encoding.UTF8, "application/json");
            CouponResponse response   = JsonConvert.DeserializeObject <CouponResponse>(resMessage);

            //pDRuD1EutQ_b25Qd8c27hJ-rl7Do
            //{"status": 1,    "message": "{\"errcode\":0,\"errmsg\":\"ok\",\"card_id\":\"pDRuD1EutQ_b25Qd8c27hJ-rl7Do\"}",    "data": null}
            if (response.errmsg == "ok")
            {
                string cardId = response.card_id;

                this.txtCreateCouponLog1.Text = "卡券创建成功,cardId = " + cardId;
            }
            else
            {
                this.txtCreateCouponLog1.Text = "卡券创建失败" + response;
            }
        }
예제 #17
0
        public AccessResponse SendTmps(BCJ_TMP_DETAIL_EX request)
        {
            ILog   _loginfo = LogManager.GetLogger("loginfo");
            string ip       = String.Empty;

            //服务端获取IP地址
            ip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            if (null == ip || ip == String.Empty)
            {
                ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
            }
            if (null == ip || ip == String.Empty)
            {
                ip = HttpContext.Current.Request.UserHostAddress;
            }
            //ILog _logerror = LogManager.GetLogger("logerror");
            //_loginfo.Info("IP:"+ip);
            //string ip = this.Context.Request.UserHostAddress;
            //HttpRequest.UserHostAddress.ToString()
            //BCJ_TMP_DETAIL tmp_detail = JsonConvert.DeserializeObject<BCJ_TMP_DETAIL>(request);
            AccessResponse response = new AccessResponse();
            string         json     = "";
            string         key      = FormsAuthentication.HashPasswordForStoringInConfigFile(ip, "SHA1");

            if (System.Configuration.ConfigurationManager.AppSettings.Get("AuthSecret") == null)
            {
                _loginfo.Info("发送模板消息接口 IP:" + ip + " 验证不通过:服务没有配置白名单");
                response.Wv_Return    = "N";
                response.Message      = "服务没有配置白名单";
                response.Member_Group = "0";
                return(response);
            }
            if (!System.Configuration.ConfigurationManager.AppSettings.Get("AuthSecret").Split(',').Contains <string>(key))
            {
                _loginfo.Info("发送模板消息接口 IP:" + ip + " 验证不通过:当前ip" + ip + "不在没权限访问");
                response.Wv_Return    = "N";
                response.Message      = "当前ip" + ip + "不在没权限访问";
                response.Member_Group = "0";
                return(response);
            }
            int successCnt = 0;

            try
            {
                if (string.IsNullOrWhiteSpace(request.IsRealTime))
                {
                    _loginfo.Info("发送模板消息接口 IP:" + ip + " 验证不通过:请提供是否实时参数信息");
                    response.Wv_Return    = "N";
                    response.Message      = "请提供是否实时参数信息";
                    response.Member_Group = "0";
                    return(response);
                }

                if (string.IsNullOrWhiteSpace(request.Invoke_Time))
                {
                    _loginfo.Info("发送模板消息接口 IP:" + ip + " 验证不通过:调用时间参数异常");
                    response.Wv_Return    = "N";
                    response.Message      = "调用时间参数异常";
                    response.Member_Group = "0";
                    return(response);
                }

                try
                {
                    DateTime Invoke_Time = DateTime.Parse(request.Invoke_Time);
                }
                catch
                {
                    _loginfo.Info("发送模板消息接口 IP:" + ip + " 验证不通过:调用时间格式不正确");
                    response.Wv_Return    = "N";
                    response.Message      = "调用时间格式不正确";
                    response.Member_Group = "0";
                    return(response);
                }

                if (request.Templates.Count <= 0)
                {
                    _loginfo.Info("发送模板消息接口 IP:" + ip + " 验证不通过:请至少提供一个消息模版信息");
                    response.Wv_Return    = "N";
                    response.Message      = "请至少提供一个消息模版信息";
                    response.Member_Group = "0";
                    return(response);
                }

                if (request.Template_Params.Count <= 0)
                {
                    _loginfo.Info("发送模板消息接口 IP:" + ip + " 验证不通过:请至少提供一个会员目标组信息");
                    response.Wv_Return    = "N";
                    response.Message      = "请至少提供一个会员目标组信息";
                    response.Member_Group = "0";
                    return(response);
                }

                string resmsg = NetHelper.HttpRequest(AppConfig.BeautyChinaWebApp, "", "GET", 2000,
                                                      Encoding.UTF8, "application/json");

                TokeRes          toke         = JsonHelper.DeserializeObject <TokeRes>(resmsg);
                HmjMemberService _hmjMember   = new HmjMemberService();
                string           errorMessage = "";
                string           requestStr   = JsonHelper.SerializeObject(request);
                //添加日志: ip+请求参数
                _loginfo.Info("发送模板消息接口 IP:" + ip + " 请求参数:" + requestStr);
                int str = _hmjMember.SendTmpEx(request, toke.Access_Token, ref successCnt, ref errorMessage);

                if (str == -1)
                {
                    _loginfo.Info("发送模板消息接口 IP:" + ip + " 返回结果失败:" + "[成功数]" + successCnt + " [错误信息]" + errorMessage);
                    response.Wv_Return    = "N";
                    response.Message      = errorMessage;
                    response.Member_Group = successCnt.ToString();
                    return(response);
                }

                _loginfo.Info("发送模板消息接口 IP:" + ip + " 返回结果成功:[成功数]" + successCnt);
                response.Wv_Return    = "Y";
                response.Message      = "OK";
                response.Member_Group = successCnt.ToString();
                return(response);
            }
            catch (Exception ex)
            {
                _loginfo.Info("发送模板消息接口 IP:" + ip + " 返回结果异常:[成功数]" + successCnt);
                WriteLog("发送模板消息", ex);
                //return ResponseJsonError(false, error_message, ex);
                response.Wv_Return    = "N";
                response.Message      = ex.Message;
                response.Member_Group = successCnt.ToString();
                return(response);
            }
        }
예제 #18
0
        protected void btnCreateCoupon2_Click(object sender, EventArgs e)
        {
            long   begin_timestamp = 1533052800; //2018-08-01 00:00:00
            long   end_timestamp   = 1568889428; //2018-09-30 23:59:59
            string resmsg          = NetHelper.HttpRequest(AppConfig.TokenUrl, "", "GET", 2000,
                                                           Encoding.UTF8, "application/json");

            TokeRes toke  = JsonHelper.DeserializeObject <TokeRes>(resmsg);
            string  token = toke.Access_Token;
            string  url   = "https://api.weixin.qq.com/card/create?access_token=" + token;
            string  json  = @"{ 
            ""card"": {
              ""card_type"": ""GENERAL_COUPON"",
              ""general_coupon"": {
                  ""base_info"": {
                      ""logo_url"": 
            ""https://mmbiz.qlogo.cn/mmbiz_jpg/ugkm3wzgIFILaicicIzX7hfxblXziaEUliaGk37Q0VukC4tiaWB3lfcxYopOn72bHibaKEenbsPHzqpvxppHk3NanItw/0?wx_fmt=jpeg"",
                      ""brand_name"":""佰草集心约会"",
                      ""code_type"":""CODE_TYPE_TEXT"",
                      ""title"": ""满200减60抵用券"",
                      ""sub_title"": """",
                      ""color"": ""Color020"",
                      ""notice"": ""请出示您的唯一优惠券码"",
                      ""description"": ""1)此券仅限本人使用,不可转增,每人限领1张
                                         2)凭券返店消费满200元时抵扣
                                         3)该活动仅限在佰草集专柜购买的顾客"",
                      ""date_info"": {
                                          ""type"": ""DATE_TYPE_FIX_TIME_RANGE"",
                                          ""begin_timestamp"": " + begin_timestamp + " ,"
                            + @"""end_timestamp"":  " + end_timestamp + @" },
                       ""sku"": {
                            ""quantity"": 100
                      },
                      ""get_limit"": 10,
                      ""use_custom_code"": true,
                      ""bind_openid"": true,
                      ""can_share"": false,
                      ""can_give_friend"": false,
                      ""center_title"": ""立即使用"",
                          ""center_sub_title"": """",
                          ""center_url"": """ + AppConfig.ActivityWebApp + @"wechat/XYH_2TG_Coupon_H5/html/hxcoupon.html""
                  },
                  ""default_detail"": ""满200减60抵用券""}
            }
            }";

            var            resMessage = NetHelper.HttpRequest(url, json, "POST", 2000, Encoding.UTF8, "application/json");
            CouponResponse response   = JsonConvert.DeserializeObject <CouponResponse>(resMessage);

            //pDRuD1EutQ_b25Qd8c27hJ-rl7Do
            //{"status": 1,    "message": "{\"errcode\":0,\"errmsg\":\"ok\",\"card_id\":\"pDRuD1EutQ_b25Qd8c27hJ-rl7Do\"}",    "data": null}
            if (response.errmsg == "ok")
            {
                string cardId = response.card_id;

                this.txtCreateCouponLog2.Text = "卡券创建成功,cardId = " + cardId;
            }
            else
            {
                this.txtCreateCouponLog2.Text = "卡券创建失败" + response;
            }
        }