/// <summary> /// 获取用户OpenID /// </summary> void GetUserOpenID() { if (null == Request.QueryString["state"]) { //return; } else { strSiteCode = Common.Common.NoHtml(Request.QueryString["state"].ToString()); Session["strSiteCode"] = strSiteCode; } string code = Request.QueryString["code"] as string; if (!string.IsNullOrEmpty(code)) { WXConfigDAL dal = new WXConfigDAL(); Model.WeiXin.WXConfig wxConfig = dal.GetWXConfigBySiteCode(strSiteCode); if (wxConfig != null) { WeiXinCore.Models.WeiXinConfig weixinConfig = new WeiXinCore.Models.WeiXinConfig() { ID = wxConfig.WXID, Name = wxConfig.WXName, Token = wxConfig.WXToken, AppId = wxConfig.WXAppID, AppSecret = wxConfig.WXAppSecret }; WeiXinCore.WeiXin weixin = new WeiXinCore.WeiXin(weixinConfig); Oauth2AccessToken oauth2AccessToken = weixin.GetOauth2AccessToken(code); if (oauth2AccessToken != null) { strOpenID = oauth2AccessToken.OpenID; } UserInfo userinfo = weixin.GetUserInfo(strOpenID); if (userinfo != null) { regNickName = userinfo.NickName; regSex = userinfo.Sex; regHeadImg = userinfo.Headimgurl; } } else { strOpenID = code; } } if (strOpenID == null || strOpenID == "") { if (Session["customerID"] != null && Session["customerID"].ToString() != "") { MSCustomersDAL CustomerDal = new MSCustomersDAL(); try { strOpenID = CustomerDal.GetCustomerValueByID("OpenID", Session["customerID"].ToString()).ToString(); } catch (Exception) { } } } if (strOpenID != null && strOpenID != "") { Session["OpenID"] = strOpenID; } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (null == Request["state"] || Request["state"] == "") { return; } else { strSiteCode = Common.Common.NoHtml(Request.QueryString["state"].ToString()); Session["strSiteCode"] = strSiteCode; } string code = Request.QueryString["code"] as string; if (!string.IsNullOrEmpty(code)) { WXConfigDAL dal = new WXConfigDAL(); Model.WeiXin.WXConfig wxConfig = dal.GetWXConfigBySiteCode(strSiteCode); if (wxConfig != null) { WeiXinCore.Models.WeiXinConfig weixinConfig = new WeiXinCore.Models.WeiXinConfig() { ID = wxConfig.WXID, Name = wxConfig.WXName, Token = wxConfig.WXToken, AppId = wxConfig.WXAppID, AppSecret = wxConfig.WXAppSecret }; WeiXinCore.WeiXin weixin = new WeiXinCore.WeiXin(weixinConfig); Oauth2AccessToken oauth2AccessToken = weixin.GetOauth2AccessToken(code); if (oauth2AccessToken != null) { strOpenID = oauth2AccessToken.OpenID; } } } //if (string.IsNullOrEmpty(strOpenID)) //{ // return; //} if (Request["action"] != null && Request["action"] != "") { if (Request["openid"] != null && Request["openid"] != "") { strOpenID = Request.QueryString["openid"].ToString(); Session["openid"] = strOpenID; } } else { if (null != Session["openid"]) { strOpenID = Session["openid"].ToString(); } } if (Request["openid"] != null && Request["openid"] != "") { strOpenID = Request.QueryString["openid"].ToString(); Session["openid"] = strOpenID; } //取有效竞猜ID DataSet dsQuiz = dalQuiz.GetJCQuizDataList(" DATEDIFF(MI,GETDATE(),StartTime) > 15 "); if (Request["id"] != null && Request["id"] != "") { strQuizID = Common.Common.NoHtml(Request["id"].ToString()); } else if (null != dsQuiz && dsQuiz.Tables.Count > 0 && dsQuiz.Tables[0].Rows.Count > 0) { strQuizID = dalQuiz.GetJCQuizDataList(" DATEDIFF(MI,GETDATE(),StartTime) > 15 ").Tables[0].Rows[0]["ID"].ToString(); } else { #region 消费完成发生消息 string strAppID = string.Empty; string strSecret = string.Empty; Model.WeiXin.WXConfig wc = new Model.WeiXin.WXConfig(); WXConfigDAL wcdal = new WXConfigDAL(); wc = wcdal.GetWXConfigBySiteCode(strSiteCode); if (null != wc) { strAppID = wc.WXAppID; strSecret = wc.WXAppSecret; } string strToken = WeiXinHelper.GetAccessToken(strAppID, strSecret); var KeyToken = new { access_token = "" }; var b = JsonConvert.DeserializeAnonymousType(strToken, KeyToken); string strRToken = b.access_token; WeiXinHelper.SendCustomTextMessage(strRToken, strOpenID, "当前没有竞猜场次!<a href='http://114.215.108.27/MicroSite/MyQuiz.aspx?sitecode=" + strSiteCode + "&openid=" + strOpenID + "'>查看所有参加的竞猜</a>"); #endregion Response.Write("<script>document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() { WeixinJSBridge.call('closeWindow');});</script>"); return; } if (Request["action"] != null && Request["action"] != "") { strAction = Common.Common.NoHtml(Request.QueryString["action"].ToString()); } if (strAction.Trim() != null && strAction.Trim() != "" && strAction.Trim().ToLower() == "save") { SaveJCGScore(); } else { GetDetailList(); } } }