Example #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["para"] == null)
            {
                if ((Request.QueryString["openid"] != null) || Session["FromUserName"] != null)
                {
                    //WriteTxt("结束授权");
                    string user         = Request.QueryString["openid"] == null ? Session["FromUserName"].ToString() : Request.QueryString["openid"].ToString();
                    string access_token = Request.QueryString["Access_token"] == null ? Session["Access_token"].ToString() : Request.QueryString["Access_token"].ToString();
                    Session["FromUserName"] = user;
                    Session["Access_token"] = access_token;

                    HttpCookie cookie = Request.Cookies["XYH_COUPON"];
                    if (cookie == null)
                    {
                        cookie = new HttpCookie("XYH_COUPON");
                    }
                    cookie.Values.Set("FromUserName", user);

                    string url   = "https://api.weixin.qq.com/sns/userinfo?access_token=" + access_token + "&openid=" + user + "&lang=zh_CN";
                    string token = PostRequest(url);
                    WriteTxt(url);
                    WriteTxt(token);
                    OpenInfo autho = JsonConvert.DeserializeObject <OpenInfo>(token);
                    if (!string.IsNullOrWhiteSpace(autho.headimgurl))
                    {
                        MySmallShopService mss = new MySmallShopService();
                        OAauth_Log         oa  = mss.GetOA(user, "商业集团送券活动");
                        if (oa == null)
                        {
                            oa = new OAauth_Log();
                            oa.FromUserName = user;
                            oa.ToUserName   = "******";
                            oa.headimgurl   = autho.headimgurl;
                            oa.Nickname     = autho.nickname;
                            oa.CreateDate   = DateTime.Now;
                            mss.SaveOA(oa);
                        }
                    }

                    XHYCouponService _xyhService = new XHYCouponService();
                    //判断是否参加并且可以领取卡券
                    WXCouponGiveInfo model = _xyhService.GetWXCouponGiveInfoByOpenid(user, "SYJT");
                    if (model != null)
                    {
                        if (model.GetCoupon == 1)
                        {
                            var phone = model.Mobile;
                            Response.Redirect("list.html?mobile=" + phone);
                        }
                    }
                }
                else
                {
                    //WriteTxt("开始授权");
                    OAuth(AbsoluteUri);
                }
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            List <string> list  = nvbo.GetOrderOpenidNotInOA();
            int           total = list.Count;
            int           cg    = 0;

            foreach (string o in list)
            {
                try
                {
                    OAauth_Log oa = new OAauth_Log();
                    oa.CreateDate   = DateTime.Now;
                    oa.FromUserName = o;
                    oa.ToUserName   = tousername;
                    string   url   = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + Token(mjuserid) + "&openid=" + o + "&lang=zh_CN";
                    string   token = PostRequest(url);
                    OpenInfo autho = JsonConvert.DeserializeObject <OpenInfo>(token);
                    if (autho.subscribe == 1)
                    {
                        oa.headimgurl = autho.headimgurl;
                        oa.Nickname   = autho.nickname;
                        oa.sex        = autho.sex;
                        oa.country    = autho.country;
                        oa.province   = autho.province;
                        oa.city       = autho.city;

                        DownHeadImage(oa);
                        mss.SaveOAtuh(oa);
                        cg++;
                    }
                }
                catch (Exception)
                {
                }
            }
            Response.Write("共计" + total + ",成功" + cg);
        }