コード例 #1
0
        public string VerificaOpenId(string OpenId)
        {
            try
            {
                WXCouponGiveInfo model = _xyhService.GetWXCouponGiveInfoByOpenid(OpenId, ActivityName);
                if (model == null)
                {
                    response.Status = 1;//没有参加过活动
                }
                else
                {
                    response.Status  = 0;
                    response.Data    = model;
                    response.Message = "参加过活动";
                }

                WriteTxt("验证微信号是否参加过活动,结果" + response.Status);
            }
            catch (Exception ex)
            {
                response.Status  = 0;
                response.Message = "操作异常:" + ex.Message;
                WriteTxt("验证微信号是否参加过活动,异常" + ex.Message);
            }

            return(JsonHelper.ToJSON(response));
        }
コード例 #2
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);
                }
            }
        }