Ejemplo n.º 1
0
 /// <summary>
 /// 单击同步门店按钮事件
 /// </summary>
 protected void btnSyncPoiInfos_Click(object sender, EventArgs e)
 {
     try
     {
         //获取access_token
         string token = Access_token.GetAccess_token(Access_token.Access_Type.weixin, true);
         //门店列表接口提交url
         string url = "https://api.weixin.qq.com/cgi-bin/poi/getpoilist?access_token=" + token;
         //提交json串,门店列表索引开始:begin,门店列表返回数量限制:limit
         string json = @"{""begin"":0,""limit"":10}";
         //调用post提交方法
         string strPOIList = new Hishop.Weixin.MP.Util.WebUtils().DoPost(url, json);
         //将传回的json字符串转换为json对象
         JObject obj3 = JsonConvert.DeserializeObject(strPOIList) as JObject;
         //将json对象转换为实体类对象
         List <PoiInfoList> poiInfoList = JsonHelper.JsonToList <PoiInfoList>(obj3["business_list"].ToString());
         if (poiInfoList.Count <= 0)
         {
             this.ShowMsg("尚未添加微信门店", false);
             return;
         }
         if (WxPoiHelper.SyncPoiListInfo(poiInfoList))
         {
             this.ShowMsgAndReUrl("同步成功!", true, Request.Url.AbsoluteUri);
         }
         else
         {
             this.ShowMsg("同步失败", false);
         }
     }
     catch (Exception ex)
     {
         this.ShowMsg(ex.Message, false);
     }
 }
Ejemplo n.º 2
0
        private const string FIXED_JSON_DATA2 = @"{""action_name"": ""QR_LIMIT_STR_SCENE"", ""action_info"": {""scene"": {""scene_str"":""{0}""}}}";               //接受字符串

        /// <summary>
        /// 创建二维码ticket
        /// </summary>
        public static string CreateTicket(string WeixinAppId, string WeixinAppSecret, string ticketID, bool isTemp = true)
        {
            string  token = TokenApi.GetToken(WeixinAppId, WeixinAppSecret);
            JObject obj2  = JsonConvert.DeserializeObject(token) as JObject;

            if (obj2 != null && obj2.ToString().Contains("access_token"))
            {
                token = obj2["access_token"].ToString();
            }
            string url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + token;
            //WxLogger(ticketID);
            string json = (isTemp) ? TEMP_JSON_DATA : FIXED_JSON_DATA2;

            json = json.Replace("{0}", ticketID);
            //WxLogger(json);
            string  strTICKET = new Hishop.Weixin.MP.Util.WebUtils().DoPost(url, json);
            JObject obj3      = JsonConvert.DeserializeObject(strTICKET) as JObject;

            return(obj3["ticket"].ToString());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 调用微信接口获取所有门店信息
        /// </summary>
        /// <param name="context"></param>
        private void getPoiList(System.Web.HttpContext context)
        {
            context.Response.ContentType = "application/json";
            try
            {
                Thread.Sleep(1000);
                DataTable          dtPoiInfo   = WxPoiHelper.GetPoiListInfo();
                List <PoiInfoList> poiInfoList = new List <PoiInfoList>();
                if (dtPoiInfo.Rows.Count == 0)//如果没有同步,则调用微信接口重新获取
                {
                    //获取access_token
                    string token = Access_token.GetAccess_token(Access_token.Access_Type.weixin, true);
                    //门店列表接口提交url
                    string url = "https://api.weixin.qq.com/cgi-bin/poi/getpoilist?access_token=" + token;
                    //提交json串,门店列表索引开始:begin,门店列表返回数量限制:limit
                    string json = @"{""begin"":0,""limit"":10}";
                    //调用post提交方法
                    string strPOIList = new Hishop.Weixin.MP.Util.WebUtils().DoPost(url, json);
                    //将传回的json字符串转换为json对象
                    JObject obj3 = JsonConvert.DeserializeObject(strPOIList) as JObject;
                    //将json对象转换为实体类对象
                    poiInfoList = JsonHelper.JsonToList <PoiInfoList>(obj3["business_list"].ToString());

                    //同步微信门店信息
                    if (WxPoiHelper.SyncPoiListInfo(poiInfoList))
                    {
                        dtPoiInfo = WxPoiHelper.GetPoiListInfo();
                    }
                }


                //获取所有门店的坐标
                string offset = string.Empty;
                foreach (DataRow row in dtPoiInfo.Rows)
                {
                    offset += row["longitude"] + "," + row["latitude"] + ";";//增加精度纬度
                }
                offset = offset.TrimEnd(';');
                //将门店坐标放入数组
                string[] offsetList = offset.Split(';');
                /****************根据配送范围将门店的坐标循环匹配用户当前的坐标,误差范围:1公里*******************/
                //允许的误差值(配送范围)
                double range = Convert.ToDouble(context.Request["range"]);
                //获取用户的坐标
                double userLongtitude = Convert.ToDouble(context.Request["userLontitude"]);
                double userLatitude   = Convert.ToDouble(context.Request["userLatitude"]);
                //循环判断获取距离,得到配送范围内的门店poi_id
                List <string> poi_id            = new List <string>();
                List <double> poi_user_distance = new List <double>();
                for (int i = 0; i < offsetList.Length; i++)
                {
                    string[] oa       = offsetList[i].Split(',');//获取门店经度,纬度
                    double   distance = GetDistance(userLatitude, userLongtitude, Convert.ToDouble(oa[1]), Convert.ToDouble(oa[0]));
                    if (distance <= range)
                    {
                        poi_id.Add(dtPoiInfo.Rows[i]["poi_id"].ToString());
                        poi_user_distance.Add(distance);
                    }
                }
                bool   isUserInRange = false;
                string matchIds      = "";
                string matchDistance = "";
                if (poi_id.Count > 0)//如果有配送范围内的用户,则返回第一个匹配到的门店后台id
                {
                    for (int i = 0; i < poi_id.Count; i++)
                    {
                        DataTable dtSender = WxPoiHelper.GetSenderByPoiId(poi_id[i]);
                        foreach (DataRow row in dtSender.Rows)
                        {
                            if (row["clientUserId"].ToString() != "")
                            {
                                matchIds      += row["clientUserId"] + ",";
                                matchDistance += poi_user_distance[i] + ",";
                            }
                        }
                    }
                    isUserInRange = true;
                    //如果匹配到的微信门店还没有绑定至后台账号,给出提示
                    if (matchIds.Length == 0)
                    {
                        context.Response.Write("{\"success\":false,\"errMsg\":\"匹配到了未绑定的门店,或者门店还未通过审核!\"}");
                        return;
                    }
                    //根据门店id匹配到对应的子账号id:sender
                    matchDistance = matchDistance.TrimEnd(',');
                    matchIds      = matchIds.TrimEnd(',');
                    //string[] sender = matchId.Split(',');
                    //string[] clientUserId = matchId.Split(',');

                    /*
                     * //将匹配到的所有门店以门店名字进行展示 (目前更换为街道名)
                     * DataTable dtStoreName = WxPoiHelper.GetStoreName(matchIds);
                     * string storeNameBtns = "";
                     * foreach (DataRow row in dtStoreName.Rows)
                     * {
                     *  storeNameBtns += "<span role='btnStreet' distributorId='" + row["userid"].ToString() + "'>" + row["storeName"].ToString() + "</span>";
                     * }
                     */
                    //将匹配到的所有街道以街道名字进行展示
                    DataTable dtStreetName   = WxPoiHelper.GetStoreStreets(matchIds);
                    string    streetNameBtns = "";
                    foreach (DataRow row in dtStreetName.Rows)
                    {
                        streetNameBtns += "<span role='btnStreet' la='" + row["latitude"] + "' lo='" + row["longitude"] + "'  distributorId='" + row["distributorid"].ToString() + "'>" + row["regionName"].ToString() + "</span>";
                    }


                    context.Response.Write("{\"success\":true,\"isUserInRange\":\"" + isUserInRange + "\",\"distributorId\":\"" + streetNameBtns + "\"}");
                }

                else
                {
                    context.Response.Write("{\"success\":true,\"isUserInRange\":\"" + isUserInRange + "\"}");
                }

                /*
                 * //调试
                 * string[] la0 = offsetList[0].Split(',');
                 * double distance = GetDistance(userLatitude,userLongtitude,Convert.ToDouble(la0[1]),Convert.ToDouble(la0[0]));
                 * context.Response.Write("{\"success\":true,\"userLo\":" + userLongtitude + ",\"userLa\":" + userLatitude + ",\"poiLA\":\"" + offsetList[0] + "\",\"distance\":"+distance+"}");
                 */
            }
            catch (Exception ex)
            {
                context.Response.Write("{\"success\":false,\"errMsg\":\"" + ex.Message + "\"}");
            }
        }
Ejemplo n.º 4
0
        private HtmlInputHidden hidUserStoreName; //隐藏域,当前匹配的门店名


        protected override void AttachChildControls()
        {
            this.litOrderAlert     = (Literal)this.FindControl("litOrderAlert");//公告栏
            this.litStoreList      = (Literal)this.FindControl("litStoreList");
            this.litDefaultAddress = (Literal)this.FindControl("litDefaultAddress");
            this.hidMinPrice       = (HtmlInputHidden)this.FindControl("hidMinPrice");
            this.hidFromUserId     = (HtmlInputHidden)this.FindControl("hidFromUserId");
            this.hidUserDistance   = (HtmlInputHidden)this.FindControl("hidUserDistance");
            this.hidUserStoreId    = (HtmlInputHidden)this.FindControl("hidUserStoreId");
            this.hidUserStoreName  = (HtmlInputHidden)this.FindControl("hidUserStoreName");

            SiteSettings masterSettings = SettingsManager.GetMasterSettings(false);
            MemberInfo   currentMember  = MemberProcessor.GetCurrentMember();

            this.litOrderAlert.Text = masterSettings.orderAlert;

            this.hidMinPrice.Value = masterSettings.roadPriceInfo;

            //获取我的推广人id
            try
            {
                string VisitFromMemberId = HiCache.Get(string.Format("DataCache-FromMemberId-{0}", currentMember.OpenId)) as string;
                if (!string.IsNullOrEmpty(VisitFromMemberId))
                {
                    this.hidFromUserId.Value = VisitFromMemberId;
                }
            }
            catch (Exception ex) {
                //WriteLog(ex.Message);
            }

            //获取用户默认配送地址,如果没有填写,则跳转到新增地址页面
            ShippingAddressInfo shippingAddress = MemberProcessor.GetDefaultShippingAddress();

            if (shippingAddress == null)
            {
                this.Page.Response.Redirect("AddShippingAddressPro.aspx?returnUrl=picOrder.aspx"); return;
            }

            this.litDefaultAddress.Text = MemberProcessor.GetDefaultShippingAddress().Address;


            //如果填写了地址,获取所有门店坐标,并且匹配用户的默认配送地址,获取最近门店,并计算出相应的配送费和配送距离等
            DataTable          dtPoiInfo   = WxPoiHelper.GetPoiListInfo();
            List <PoiInfoList> poiInfoList = new List <PoiInfoList>();

            if (dtPoiInfo.Rows.Count == 0)//如果没有同步,则调用微信接口重新获取
            {
                //获取access_token
                string token = Access_token.GetAccess_token(Access_token.Access_Type.weixin, true);
                //门店列表接口提交url
                string url = "https://api.weixin.qq.com/cgi-bin/poi/getpoilist?access_token=" + token;
                //提交json串,门店列表索引开始:begin,门店列表返回数量限制:limit
                string json = @"{""begin"":0,""limit"":10}";
                //调用post提交方法
                string strPOIList = new Hishop.Weixin.MP.Util.WebUtils().DoPost(url, json);
                //将传回的json字符串转换为json对象
                JObject obj3 = JsonConvert.DeserializeObject(strPOIList) as JObject;
                //将json对象转换为实体类对象
                poiInfoList = JsonHelper.JsonToList <PoiInfoList>(obj3["business_list"].ToString());

                //同步微信门店信息
                if (WxPoiHelper.SyncPoiListInfo(poiInfoList))
                {
                    dtPoiInfo = WxPoiHelper.GetPoiListInfo();
                }
            }


            //拼装门店列表
            string storelisthtml = "<div class='storeNow'><p><span class='switch' onclick='chooseStore()'>选择门店</span></p></div>";

            storelisthtml += "<ul class='chooseStore'>";
            foreach (DataRow row in dtPoiInfo.Rows)
            {
                DataTable dtSender = WxPoiHelper.GetSenderByPoiId(row["poi_id"].ToString());
                storelisthtml += string.Format("<li poi_id='{0}'>{1}</li>", row["poi_id"].ToString(), DistributorsBrower.GetDistributorInfo(int.Parse(dtSender.Rows[0]["clientuserid"].ToString())).StoreName);
            }
            storelisthtml += "</ul>";

            litStoreList.Text = storelisthtml;


            //如果手动选择了门店,那么门店列表除了该门店的一律删除
            DataTable dtt = new DataTable();

            if (!string.IsNullOrEmpty(this.Page.Request.QueryString["poi_id"]))
            {
                dtt = dtPoiInfo.Clone();
                DataRow[] dr = dtPoiInfo.Select("poi_id = '" + this.Page.Request.QueryString["poi_id"] + "'   ");
                for (int i = 0; i < dr.Length; i++)
                {
                    dtt.ImportRow((DataRow)dr[i]);
                }
                dtPoiInfo = dtt;
            }



            //获取所有门店的坐标
            string offset = string.Empty;

            foreach (DataRow row in dtPoiInfo.Rows)
            {
                offset += row["latitude"] + "," + row["longitude"] + ";";//增加精度纬度
            }
            offset = offset.TrimEnd(';');
            //将门店坐标放入数组
            string[] offsetList = offset.Split(';');
            //循环判断获取距离,得到配送范围内的门店poi_id
            List <string> poi_id            = new List <string>();
            List <double> poi_user_distance = new List <double>();

            for (int i = 0; i < offsetList.Length; i++)
            {
                string[] oa       = offsetList[i].Split(',');//获取门店经度,纬度
                double   distance = GetDistance(shippingAddress.lat, shippingAddress.lng, Convert.ToDouble(oa[0]), Convert.ToDouble(oa[1]));
                poi_id.Add(dtPoiInfo.Rows[i]["poi_id"].ToString());
                poi_user_distance.Add(distance);
            }

            string matchIds      = "";
            string matchDistance = "";

            if (poi_id.Count > 0)
            {
                for (int i = 0; i < poi_id.Count; i++)
                {
                    DataTable dtSender = WxPoiHelper.GetSenderByPoiId(poi_id[i]);
                    foreach (DataRow row in dtSender.Rows)
                    {
                        if (row["clientUserId"].ToString() != "")
                        {
                            matchIds      += row["clientUserId"] + ",";
                            matchDistance += poi_user_distance[i] + ",";
                        }
                    }
                }
                matchDistance = matchDistance.TrimEnd(',');
                matchIds      = matchIds.TrimEnd(',');
            }

            string[] matchDistanceArrStr = matchDistance.Split(',');
            if (matchDistanceArrStr.Length <= 0)
            {
                return;
            }
            double[] matchDistanceArr = new double[matchDistanceArrStr.Length];
            for (int i = 0; i < matchDistanceArrStr.Length; i++)
            {
                matchDistanceArr[i] = Convert.ToDouble(matchDistanceArrStr[i]);
            }
            string[] matchIdsArr = matchIds.Split(',');
            int      minIndex    = GetMinAndIndex(matchDistanceArr);

            hidUserDistance.Value   = matchDistanceArr[minIndex].ToString(); //获取距离最小的值
            this.litOrderAlert.Text = this.litOrderAlert.Text + "当前配送距离:" + hidUserDistance.Value + "公里";
            hidUserStoreId.Value    = matchIdsArr[minIndex].ToString();      //获取距离最小的值的门店id
            if (matchIdsArr.Length > 0)
            {
                hidUserStoreName.Value = DistributorsBrower.GetDistributorInfo(int.Parse(matchIdsArr[minIndex])).StoreName;
            }
        }