예제 #1
0
파일: menu.aspx.cs 프로젝트: zklve/WxMall
    public void Bind()
    {
        Cms.BLL.wx_info   wxinfo = new Cms.BLL.wx_info();
        Cms.Model.wx_info minfo  = new Cms.Model.wx_info();
        minfo = wxinfo.GetModel(1);

        hdid.Value = minfo.access_token;

        Cms.BLL.wx_menu   wm  = new Cms.BLL.wx_menu();
        Cms.Model.wx_menu wmd = new Cms.Model.wx_menu();
        DataTable         dt  = wm.GetList("pid=0").Tables[0];

        rmenu.DataSource = dt.DefaultView;
        rmenu.DataBind();


        dt = wm.GetList("pid=1").Tables[0];
        rmenu1.DataSource = dt.DefaultView;
        rmenu1.DataBind();

        dt = wm.GetList("pid=2").Tables[0];
        rmenu2.DataSource = dt.DefaultView;
        rmenu2.DataBind();

        dt = wm.GetList("pid=3").Tables[0];
        rmenu3.DataSource = dt.DefaultView;
        rmenu3.DataBind();
    }
예제 #2
0
    protected void btnsave_Click(object sender, EventArgs e)
    {
        Cms.BLL.wx_info   wx  = new Cms.BLL.wx_info();
        Cms.Model.wx_info mwx = new Cms.Model.wx_info();
        DataTable         dt  = wx.GetList("id=1").Tables[0];
        bool bl = false;

        if (dt.Rows.Count > 0)
        {
            mwx              = wx.GetModel(1);
            mwx.AppId        = AppId.Text.Trim();
            mwx.AppSecret    = AppSecret.Text.Trim();
            mwx.access_token = hdid.Text.Trim();
            bl = wx.Update(mwx);
        }
        else
        {
            mwx.AppId        = AppId.Text.Trim();
            mwx.AppSecret    = AppSecret.Text.Trim();
            mwx.access_token = Gettoken();
            if (wx.Add(mwx) > 0)
            {
                bl = true;
            }
        }
        if (bl)
        {
            Bind();
            ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('设置成功!')</script>");
        }
        else
        {
            ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('设置失败!')</script>");
        }
    }
예제 #3
0
    public string UploadMultimedia(string ACCESS_TOKEN, string Type)
    {
        string result   = "";
        string wxurl    = "http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=" + ACCESS_TOKEN + "&type=" + Type;
        string filepath = Server.MapPath("image") + "\\01.jpg"; //(本地服务器的地址)
        // string filepath = "http://www.muhn.org.cn/Upload/image/20140827/20140827100505_4660.jpg";
        //WriteLog("上传路径:" + filepath);
        WebClient myWebClient = new WebClient();

        myWebClient.Credentials = CredentialCache.DefaultCredentials;
        try
        {
            byte[] responseArray = myWebClient.UploadFile(wxurl, "POST", filepath);
            result = System.Text.Encoding.Default.GetString(responseArray, 0, responseArray.Length);
            if (result.IndexOf("42001") > -1)
            {
                string            str = Gettoken();
                Cms.BLL.wx_info   wx  = new Cms.BLL.wx_info();
                Cms.Model.wx_info mwx = new Cms.Model.wx_info();
                mwx = wx.GetModel(1);
                mwx.access_token = str;
                wx.Update(mwx);
                Bind();
                UploadMultimedia(str, Type);
            }
            string[] s = result.Split(',');
            result = s[1].Replace("\"media_id\":\"", "").Replace("\"", "");
        }
        catch (Exception ex)
        {
            result = "Error:" + ex.Message;
        }
        // WriteLog("上传MediaId:" + result);
        return(result);
    }
예제 #4
0
    public static string getwxCode(string code, string httpUrl)
    {
        string result   = "123";
        string xtopenid = "";

        Cms.BLL.wx_info info      = new Cms.BLL.wx_info();
        string          appid     = info.GetModel(1).AppId;
        string          appsecret = info.GetModel(1).AppSecret;

        if (code != null && code != "")
        {
            string Code = code;
            string Str  = GetJson("https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + appid + "&secret=" + appsecret + "&code=" + Code + "&grant_type=authorization_code");
            //微信回传的数据为Json格式,将Json格式转化成对象
            OAuth_Token Model = wxuser.JSONToObject <OAuth_Token>(Str);

            xtopenid = Model._openid;
            result   = Model._openid + code;

            Cms.BLL.wx_info       wxinfo     = new Cms.BLL.wx_info();
            Cms.Model.wx_info     Model_info = new Cms.Model.wx_info();
            Cms.BLL.wx_userinfo   userinfo   = new Cms.BLL.wx_userinfo();
            Cms.Model.wx_userinfo muserinfo  = new Cms.Model.wx_userinfo();
            Model_info = wxinfo.GetModel(1);
            string str    = "";
            string openid = Model._openid;
            str       = setinfo("https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + Model.access_token + "&openid=" + openid, "", openid);
            muserinfo = JSONToObject <Cms.Model.wx_userinfo>(str);
            Cms.Model.wx_userinfo wxs = new Cms.Model.wx_userinfo();
            wxs.subscribe      = muserinfo.subscribe;
            wxs.openid         = muserinfo.openid;
            wxs.nickname       = muserinfo.nickname;
            wxs.sex            = muserinfo.sex;
            wxs.language       = muserinfo.language;
            wxs.city           = muserinfo.city;
            wxs.province       = muserinfo.province;
            wxs.country        = muserinfo.country;
            wxs.headimgurl     = muserinfo.headimgurl;
            wxs.subscribe_time = muserinfo.subscribe_time;
            wxs.remark         = muserinfo.remark;
            wxs.updatetime     = DateTime.Now;
            if (!Cms.DBUtility.DbHelperSQL.Exists("select count(1) from wx_userinfo where openid='" + muserinfo.openid + "'"))
            {
                if (wxs.openid != "")
                {
                    userinfo.Add(wxs);
                }
            }
            else
            {
                Cms.DBUtility.DbHelperSQL.ExecuteSql("update wx_userinfo set updatetime='" + DateTime.Now + "' where openid='" + muserinfo.openid + "'");
            }
        }

        return(result);
    }
예제 #5
0
 public static Cms.Model.wx_userinfo getwxCode(string code, string httpUrl)
 {
     Cms.Model.wx_info     wxInfo    = new Cms.BLL.wx_info().GetModel(1);
     Cms.BLL.wx_userinfo   userinfo  = new Cms.BLL.wx_userinfo();
     Cms.Model.wx_userinfo muserinfo = new Cms.Model.wx_userinfo();
     if (code != null && code != "")
     {
         string strOpenId = GetJson("https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + wxInfo.AppId + "&secret=" + wxInfo.AppSecret + "&code=" + code + "&grant_type=authorization_code");
         //微信回传的数据为Json格式,将Json格式转化成对象
         OAuth_Token oAuth_Token = wxuser.JSONToObject <OAuth_Token>(strOpenId);
         string      strInfo     = GetJson("https://api.weixin.qq.com/sns/userinfo?access_token=" + oAuth_Token.access_token + "&openid=" + oAuth_Token.openid + "&lang=zh_CN");
         wxuserinfo  Wxuserinfo  = wxuser.JSONToObject <wxuserinfo>(strInfo);
         muserinfo.subscribe      = Wxuserinfo.subscribe;
         muserinfo.openid         = Wxuserinfo.openid;
         muserinfo.nickname       = Wxuserinfo.nickname;
         muserinfo.sex            = Wxuserinfo.sex;
         muserinfo.language       = Wxuserinfo.language;
         muserinfo.city           = Wxuserinfo.city;
         muserinfo.province       = Wxuserinfo.province;
         muserinfo.country        = Wxuserinfo.country;
         muserinfo.headimgurl     = Wxuserinfo.headimgurl;
         muserinfo.subscribe_time = Wxuserinfo.subscribe_time;
         muserinfo.remark         = Wxuserinfo.remark;
         muserinfo.updatetime     = DateTime.Now;
         //string str = setinfo("https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + Model_info.access_token + "&openid=" + openid, "", openid);
         if (!Cms.DBUtility.DbHelperSQL.Exists("select count(1) from wx_userinfo where openid='" + muserinfo.openid + "'"))
         {
             if (muserinfo.openid != "")
             {
                 setlog("添加访问信息", oAuth_Token.openid);
                 userinfo.Add(muserinfo);
             }
             else
             {
                 DataTable dtUserInfo = new Cms.BLL.wx_userinfo().GetList("openid='" + muserinfo.openid + "' order by updatetime desc").Tables[0];
                 if (dtUserInfo != null && dtUserInfo.Rows.Count > 0)
                 {
                     muserinfo.id = int.Parse(dtUserInfo.Rows[0]["id"].ToString());
                     userinfo.Update(muserinfo);
                 }
             }
         }
         else
         {
             DataTable dtUserInfo = new Cms.BLL.wx_userinfo().GetList("openid='" + muserinfo.openid + "' order by updatetime desc").Tables[0];
             if (dtUserInfo != null && dtUserInfo.Rows.Count > 0)
             {
                 muserinfo.id = int.Parse(dtUserInfo.Rows[0]["id"].ToString());
                 userinfo.Update(muserinfo);
             }
         }
     }
     return(muserinfo);
 }
예제 #6
0
    /// <summary>
    ///发送获取会员的请求
    /// </summary>
    public static string setinfo(string posturl, string postData, string openid)
    {
        Stream          outstream = null;
        Stream          instream  = null;
        StreamReader    sr        = null;
        HttpWebResponse response  = null;
        HttpWebRequest  request   = null;
        Encoding        encoding  = Encoding.UTF8;

        byte[] data = encoding.GetBytes(postData);
        // 准备请求...
        try
        {
            // 设置参数
            request = WebRequest.Create(posturl) as HttpWebRequest;
            CookieContainer cookieContainer = new CookieContainer();
            request.CookieContainer   = cookieContainer;
            request.AllowAutoRedirect = true;
            request.Method            = "POST";
            request.ContentType       = "application/x-www-form-urlencoded";
            request.ContentLength     = data.Length;
            outstream = request.GetRequestStream();
            outstream.Write(data, 0, data.Length);
            outstream.Close();
            //发送请求并获取相应回应数据
            response = request.GetResponse() as HttpWebResponse;
            //直到request.GetResponse()程序才开始向目标网页发送Post请求
            instream = response.GetResponseStream();
            sr       = new StreamReader(instream, encoding);
            //返回结果网页(html)代码
            string content = sr.ReadToEnd();
            string err     = string.Empty;

            if (content.IndexOf("42001") > -1)
            {
                string            str = Gettoken();
                Cms.BLL.wx_info   wx  = new Cms.BLL.wx_info();
                Cms.Model.wx_info mwx = new Cms.Model.wx_info();
                mwx = wx.GetModel(1);
                mwx.access_token = str;
                wx.Update(mwx);

                setinfo("https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + str + "&openid=" + openid, postData, openid);
            }
            return(content);
        }
        catch (Exception ex)
        {
            string err = ex.Message;
            return(string.Empty);
        }
    }
예제 #7
0
    /// <summary>
    ///获取token
    /// </summary>
    public static string Gettoken()
    {
        Cms.BLL.wx_info   wxinfo = new Cms.BLL.wx_info();
        Cms.Model.wx_info Model  = new Cms.Model.wx_info();
        Model = wxinfo.GetModel(1);


        string sAppId     = Model.AppId;
        string sAppSecret = Model.AppSecret;
        string posturl    = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + sAppId + "&secret=" + sAppSecret + "";
        string postData   = "";


        //Stream outstream = null;
        Stream          instream = null;
        StreamReader    sr       = null;
        HttpWebResponse response = null;
        HttpWebRequest  request  = null;
        Encoding        encoding = Encoding.UTF8;

        byte[] data = encoding.GetBytes(postData);
        // 准备请求...
        try
        {
            request = WebRequest.Create(posturl) as HttpWebRequest;
            CookieContainer cookieContainer = new CookieContainer();
            request.CookieContainer   = cookieContainer;
            request.AllowAutoRedirect = true;
            request.Method            = "GET";
            request.ContentType       = "application/x-www-form-urlencoded";
            //发送请求并获取相应回应数据
            response = request.GetResponse() as HttpWebResponse;
            //直到request.GetResponse()程序才开始向目标网页发送Post请求
            instream = response.GetResponseStream();
            sr       = new StreamReader(instream, encoding);
            //返回结果网页(html)代码
            string content = sr.ReadToEnd();
            string err     = string.Empty;

            string[] s   = content.Split(',');
            string   str = s[0].Replace("access_token", "").Replace(":", "").Replace("{", "").Replace("\"", "");
            //Response.Write(content);
            return(str);
        }
        catch (Exception ex)
        {
            string err = ex.Message;
            return(string.Empty);
        }
    }
예제 #8
0
    public void Bind()
    {
        Cms.BLL.wx_info   wx  = new Cms.BLL.wx_info();
        Cms.Model.wx_info mwx = new Cms.Model.wx_info();
        DataTable         dt  = wx.GetList("").Tables[0];

        if (dt.Rows.Count > 0)
        {
            mwx = wx.GetModel(1);
            if (mwx != null)
            {
                AppId.Text     = mwx.AppId;
                AppSecret.Text = mwx.AppSecret;
                hdid.Text      = mwx.access_token;
                wurl.Text      = mwx.url;
                WxId.Text      = mwx.wxid;
            }
        }
    }
예제 #9
0
    protected void btnsave_Click(object sender, EventArgs e)
    {
        Cms.BLL.wx_info   wx  = new Cms.BLL.wx_info();
        Cms.Model.wx_info mwx = new Cms.Model.wx_info();
        DataTable         dt  = wx.GetList("id=1").Tables[0];
        bool bl = false;

        if (dt.Rows.Count > 0)
        {
            mwx              = wx.GetModel(1);
            mwx.AppId        = AppId.Text.Trim();
            mwx.AppSecret    = AppSecret.Text.Trim();
            mwx.access_token = hdid.Text.Trim();
            mwx.url          = wurl.Text.Trim();
            mwx.wxid         = WxId.Text.Trim();
            adminUser.AddAdminLog(DTEnums.ActionEnum.Edit.ToString(), mwx.AppId); //记录日志
            bl = wx.Update(mwx);
        }
        else
        {
            mwx.AppId        = AppId.Text.Trim();
            mwx.AppSecret    = AppSecret.Text.Trim();
            mwx.access_token = hdid.Text.Trim();
            mwx.url          = wurl.Text.Trim();
            mwx.wxid         = WxId.Text.Trim();
            if (wx.Add(mwx) > 0)
            {
                adminUser.AddAdminLog(DTEnums.ActionEnum.Add.ToString(), mwx.AppId); //记录日志
                bl = true;
            }
        }
        if (bl)
        {
            Bind();
            ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('设置成功!');", true);
            // ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('设置成功!')</script>");
        }
        else
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('设置失败!');", true);
            //ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('设置失败!')</script>");
        }
    }
예제 #10
0
    public string HttpUploadFile(string postData)
    {
        Cms.BLL.wx_info   wxinfo = new Cms.BLL.wx_info();
        Cms.Model.wx_info Model  = new Cms.Model.wx_info();
        Model = wxinfo.GetModel(1);
        string result  = "";
        string posturl = "http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=" + Model.access_token + "&type=voice";

        string filepath = Server.MapPath("~" + postData);

        WebClient myWebClient = new WebClient();

        myWebClient.Credentials = CredentialCache.DefaultCredentials;
        try
        {
            byte[] responseArray = myWebClient.UploadFile(posturl, "POST", filepath);
            result = System.Text.Encoding.Default.GetString(responseArray, 0, responseArray.Length);

            if (result.IndexOf("42001") > -1)
            {
                string            str = Gettoken();
                Cms.BLL.wx_info   wx  = new Cms.BLL.wx_info();
                Cms.Model.wx_info mwx = new Cms.Model.wx_info();
                mwx = wx.GetModel(1);
                mwx.access_token = str;
                wx.Update(mwx);

                HttpUploadFile(postData);
            }

            string   s  = result.Replace("{", "").Replace("}", "").Replace("\"", "");
            string[] ss = s.Split(',');
            result = ss[1].Replace("media_id:", "");
        }
        catch (Exception ex)
        {
            result = "Error:" + ex.Message;
        }

        return(result);
    }
예제 #11
0
    public static string getUser_info(string poststr)
    {
        string result = "123";

        try
        {
            wxuser.setstatistics("", "微信消息", poststr, 1, 1);
            string res = "";
            if (poststr != null)
            {
                wxmessage   wx  = new wxmessage();
                XmlDocument xml = new XmlDocument();
                xml.LoadXml(poststr);
                XmlElement root = xml.DocumentElement;


                wx.ToUserName   = root.SelectSingleNode("ToUserName").InnerText;
                wx.FromUserName = root.SelectSingleNode("FromUserName").InnerText;
                wx.MsgType      = root.SelectSingleNode("MsgType").InnerText;
                if (wx.MsgType.Trim() == "text")
                {
                    wx.Content = root.SelectSingleNode("Content").InnerText;
                }
                if (wx.MsgType.Trim() == "event")
                {
                    wx.EventName = root.SelectSingleNode("Event").InnerText;
                    wx.EventKey  = root.SelectSingleNode("EventKey").InnerText;
                }
                if (wx.MsgType.Trim() == "voice")
                {
                    wx.Recognition = root.SelectSingleNode("Recognition").InnerText;
                }
                Cms.BLL.wx_info       wxinfo    = new Cms.BLL.wx_info();
                Cms.Model.wx_info     Model     = new Cms.Model.wx_info();
                Cms.BLL.wx_userinfo   userinfo  = new Cms.BLL.wx_userinfo();
                Cms.Model.wx_userinfo muserinfo = new Cms.Model.wx_userinfo();
                Model = wxinfo.GetModel(1);
                string str    = "";
                string openid = wx.FromUserName;
                str       = setinfo("https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + Model.access_token + "&openid=" + openid, "", openid);
                muserinfo = JSONToObject <Cms.Model.wx_userinfo>(str);
                Cms.Model.wx_userinfo wxs = new Cms.Model.wx_userinfo();
                wxs.subscribe      = muserinfo.subscribe;
                wxs.openid         = muserinfo.openid;
                wxs.nickname       = muserinfo.nickname;
                wxs.sex            = muserinfo.sex;
                wxs.language       = muserinfo.language;
                wxs.city           = muserinfo.city;
                wxs.province       = muserinfo.province;
                wxs.country        = muserinfo.country;
                wxs.headimgurl     = muserinfo.headimgurl;
                wxs.subscribe_time = muserinfo.subscribe_time;
                wxs.remark         = muserinfo.remark;
                wxs.updatetime     = DateTime.Now;
                if (!Cms.DBUtility.DbHelperSQL.Exists("select count(1) from wx_userinfo where openid='" + muserinfo.openid + "'"))
                {
                    if (muserinfo.openid != "")
                    {
                        userinfo.Add(wxs);
                    }
                }
                else
                {
                    Cms.DBUtility.DbHelperSQL.ExecuteSql("update wx_userinfo set updatetime='" + DateTime.Now + "' where openid='" + muserinfo.openid + "'");
                }
                wxuser.setstatistics("", "", "", 3, 1);
                result = muserinfo.openid;
            }


            HttpContext.Current.Response.ContentType = "text/xml";
            HttpContext.Current.Response.Write(res);
        }
        catch (Exception ex)
        {
            setlog(ex.Message, "错误1");
        }
        return(result = "21313");
    }
예제 #12
0
    protected void btnts_Click(object sender, EventArgs e)
    {
        Cms.BLL.C_article cb = new Cms.BLL.C_article();
        int id = int.Parse(tbid.Text.Trim() == ""?"0":tbid.Text.Trim());

        if (id == 0)
        {
            return;
        }
        DataTable dt = cb.GetList("articleId=" + id).Tables[0];

        if (dt.Rows.Count == 0)
        {
            ScriptManager.RegisterStartupScript(UpdatePanel2, UpdatePanel2.GetType(), "", "alert('文章不存在!');", true);
            return;
        }
        DataRow dr     = dt.Rows[0];
        string  strurl = tburls.Text.Trim();

        if (strurl == "")
        {
            ScriptManager.RegisterStartupScript(UpdatePanel2, UpdatePanel2.GetType(), "", "alert('请输入文章路径!');", true);
            return;
        }
        string[] suser = GetPage4("https://api.weixin.qq.com/cgi-bin/user/get?access_token=" + hdid.Text, "").Split(',');

        //string str = UploadMultimedia(hdid.Text, "image");
        string surl = "http://" + HttpContext.Current.Request.Url.Host.ToString();
        string spic = surl + dr["photourl"].ToString();

        foreach (string s in suser)
        {
            if (s == "")
            {
                continue;
            }
            StringBuilder sb = new StringBuilder();
            //sb.Append("{");
            //sb.Append("\"touser\":"+s+",");
            //sb.Append("\"msgtype\":\"image\",");
            //sb.Append("\"image\":");
            //sb.Append("{");
            //sb.Append("\"media_id\":\"" + str + "\"");
            //sb.Append("}");
            //sb.Append("}");

            sb.Append("{");
            sb.Append("\"touser\":" + s + ",");
            sb.Append("\"msgtype\":\"news\",");
            sb.Append("\"news\":{");
            sb.Append("\"articles\":[");
            sb.Append("{");
            sb.Append("\"title\":\"" + dr["title"].ToString() + "\",");
            sb.Append("\"description\":\"" + dr["intro"].ToString() + "\",");
            sb.Append("\"url\":\"" + strurl + "\",");
            sb.Append("\"picurl\":\"" + spic + "\"");
            sb.Append(" }");
            sb.Append("]");
            sb.Append("}");
            sb.Append("}");
            setinfo("https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" + hdid.Text.Trim(), sb.ToString());
        }

        //StringBuilder sb = new StringBuilder();
        //string str = UploadMultimedia(hdid.Text, "image");
        //sb.Append("{");
        //sb.Append("\"articles\": [");
        //sb.Append("{");
        //sb.Append("\"thumb_media_id\":\"" + str + "\",");
        //sb.Append("\"author\":\"\",");
        //sb.Append("\"title\":\"小额贷款审计我之见\",");
        //sb.Append("\"content_source_url\":\"http://www.muhn.org.cn/contents9.html\",");
        //sb.Append("\"content\":\"自2008年银监会、央行发布《关于小额贷款公司试点的指导意见》以来\",");
        //sb.Append("\"digest\":\"digest\",");
        //sb.Append("\"show_cover_pic\":\"1\"");
        //sb.Append("}");
        //sb.Append("]");
        //sb.Append("}");
        //GetPage3("https://api.weixin.qq.com/cgi-bin/media/uploadnews?access_token="+hdid.Text, sb.ToString(), 1);
        Cms.BLL.wx_info   wx  = new Cms.BLL.wx_info();
        Cms.Model.wx_info mwx = new Cms.Model.wx_info();
        dt = wx.GetList("id=2").Tables[0];
        bool bl = false;

        if (dt.Rows.Count > 0)
        {
            mwx           = wx.GetModel(2);
            mwx.AppId     = tbid.Text.Trim();
            mwx.AppSecret = tburls.Text.Trim();
            bl            = wx.Update(mwx);
        }
        else
        {
            mwx.AppId     = tbid.Text.Trim();
            mwx.AppSecret = tburls.Text.Trim();

            if (wx.Add(mwx) > 0)
            {
                bl = true;
            }
        }
        ScriptManager.RegisterStartupScript(UpdatePanel2, UpdatePanel2.GetType(), "", "alert('推送成功!');", true);
    }
예제 #13
0
    public string GetPage2(string posturl, string postData)
    {
        Stream          outstream = null;
        Stream          instream  = null;
        StreamReader    sr        = null;
        HttpWebResponse response  = null;
        HttpWebRequest  request   = null;
        Encoding        encoding  = Encoding.UTF8;

        byte[] data = encoding.GetBytes(postData);
        // 准备请求...
        try
        {
            // 设置参数
            request = WebRequest.Create(posturl) as HttpWebRequest;
            CookieContainer cookieContainer = new CookieContainer();
            request.CookieContainer   = cookieContainer;
            request.AllowAutoRedirect = true;
            request.Method            = "POST";
            request.ContentType       = "application/x-www-form-urlencoded";
            request.ContentLength     = data.Length;
            outstream = request.GetRequestStream();
            outstream.Write(data, 0, data.Length);
            outstream.Close();
            //发送请求并获取相应回应数据
            response = request.GetResponse() as HttpWebResponse;
            //直到request.GetResponse()程序才开始向目标网页发送Post请求
            instream = response.GetResponseStream();
            sr       = new StreamReader(instream, encoding);
            //返回结果网页(html)代码
            string content = sr.ReadToEnd();
            string err     = string.Empty;

            if (content.IndexOf("42001") > -1)
            {
                string            str = Gettoken();
                Cms.BLL.wx_info   wx  = new Cms.BLL.wx_info();
                Cms.Model.wx_info mwx = new Cms.Model.wx_info();
                mwx = wx.GetModel(1);
                mwx.access_token = str;
                wx.Update(mwx);
                GetPage2("https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=" + str, setmenu());
                Bind();
                //ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('停用失败!" + content + "')</script>");
                //   Response.Write("<script>alert('停用失败!" + content + "');window.location.href ='menu.aspx'</script>");
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('停用失败!');", true);
            }
            if (content.IndexOf("ok") > -1)
            {
                //ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('停用成功!')</script>");
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('停用成功!');", true);
                // Response.Write("<script>alert('停用成功!');window.location.href ='menu.aspx'</script>");
            }
            //  Response.Write(content);
            return(content);
        }
        catch (Exception ex)
        {
            string err = ex.Message;
            return(string.Empty);
        }
    }
예제 #14
0
    public void Bind()
    {
        // Response.Write(setmenu());
        Cms.BLL.wx_info   wx  = new Cms.BLL.wx_info();
        Cms.Model.wx_info mwx = new Cms.Model.wx_info();
        DataTable         dt  = wx.GetList("").Tables[0];

        if (dt.Rows.Count > 0)
        {
            mwx = wx.GetModel(1);
            if (mwx != null)
            {
                AppId.Text     = mwx.AppId;
                AppSecret.Text = mwx.AppSecret;
                hdid.Text      = mwx.access_token;
            }
            mwx = wx.GetModel(2);
            if (mwx != null)
            {
                tbid.Text   = mwx.AppId;
                tburls.Text = mwx.AppSecret;
            }
        }
        Cms.BLL.wx_menu   wm  = new Cms.BLL.wx_menu();
        Cms.Model.wx_menu wmd = new Cms.Model.wx_menu();
        dt = wm.GetList("pid=0").Tables[0];

        foreach (DataRow dr in dt.Rows)
        {
            int    id   = int.Parse(dr["id"].ToString());
            string name = dr["name"].ToString();
            int    pid  = int.Parse(dr["pid"].ToString());
            if (id == 1)
            {
                DataTable dts = wm.GetList("pid=" + id).Tables[0];


                ListBox1.DataSource     = dts.DefaultView;
                ListBox1.DataTextField  = "name";
                ListBox1.DataValueField = "id";
                ListBox1.DataBind();
                ListBox1.Items.Insert(0, new ListItem(name, id.ToString()));
            }
            if (id == 2)
            {
                DataTable dts = wm.GetList("pid=" + id).Tables[0];

                ListBox2.DataSource     = dts.DefaultView;
                ListBox2.DataTextField  = "name";
                ListBox2.DataValueField = "id";
                ListBox2.DataBind();
                ListBox2.Items.Insert(0, new ListItem(name, id.ToString()));
            }
            if (id == 3)
            {
                DataTable dts = wm.GetList("pid=" + id).Tables[0];

                ListBox3.DataSource     = dts.DefaultView;
                ListBox3.DataTextField  = "name";
                ListBox3.DataValueField = "id";
                ListBox3.DataBind();
                ListBox3.Items.Insert(0, new ListItem(name, id.ToString()));
            }
        }
    }
예제 #15
0
    public string GetPage4(string posturl, string postData)
    {
        Stream          outstream = null;
        Stream          instream  = null;
        StreamReader    sr        = null;
        HttpWebResponse response  = null;
        HttpWebRequest  request   = null;
        Encoding        encoding  = Encoding.UTF8;

        byte[] data = encoding.GetBytes(postData);
        // 准备请求...
        try
        {
            // 设置参数
            request = WebRequest.Create(posturl) as HttpWebRequest;
            CookieContainer cookieContainer = new CookieContainer();
            request.CookieContainer   = cookieContainer;
            request.AllowAutoRedirect = true;
            request.Method            = "POST";
            request.ContentType       = "application/x-www-form-urlencoded";
            request.ContentLength     = data.Length;
            outstream = request.GetRequestStream();
            outstream.Write(data, 0, data.Length);
            outstream.Close();
            //发送请求并获取相应回应数据
            response = request.GetResponse() as HttpWebResponse;
            //直到request.GetResponse()程序才开始向目标网页发送Post请求
            instream = response.GetResponseStream();
            sr       = new StreamReader(instream, encoding);
            //返回结果网页(html)代码
            string content = sr.ReadToEnd();
            string err     = string.Empty;

            if (content.IndexOf("42001") > -1)
            {
                string            str = Gettoken();
                Cms.BLL.wx_info   wx  = new Cms.BLL.wx_info();
                Cms.Model.wx_info mwx = new Cms.Model.wx_info();
                mwx = wx.GetModel(1);
                mwx.access_token = str;
                wx.Update(mwx);
                Bind();

                GetPage4("https://api.weixin.qq.com/cgi-bin/user/get?access_token=" + str, postData);
            }


            if (content.IndexOf("openid") > -1)
            {
                string[] s = content.Split('[');

                string[] scount = s[0].Split(',');
                int      stotal = int.Parse(scount[0].Replace("\"", "").Replace("total:", "").Replace("{", ""));

                string[] s2 = s[1].Split(']');
                content = s2[0].ToString();
                string snextid = s2[1].Replace("\"", "").Replace("}", "").Replace("next_openid:", "");
                if (stotal > 10000 && snextid.Length > 1)
                {
                    content = content + "," + GetPage4("https://api.weixin.qq.com/cgi-bin/user/get?access_token=" + hdid.Text + "&next_openid=" + snextid + "", "");
                }
            }


            return(content);
        }
        catch (Exception ex)
        {
            string err = ex.Message;
            return(string.Empty);
        }
    }
예제 #16
0
파일: wxuser.cs 프로젝트: zklve/MallWechat
    /// <summary>
    /// 获取微信用户信息
    /// </summary>
    /// <param name="openid"></param>
    /// <returns></returns>
    public static Cms.Model.wx_userinfo getwxuserinfo(string openid)
    {
        Cms.BLL.wx_info       wxinfo    = new Cms.BLL.wx_info();
        Cms.Model.wx_info     Model     = new Cms.Model.wx_info();
        Cms.BLL.wx_userinfo   userinfo  = new Cms.BLL.wx_userinfo();
        Cms.Model.wx_userinfo muserinfo = new Cms.Model.wx_userinfo();
        Model = wxinfo.GetModel(1);
        string    str = "";
        DataTable dt  = userinfo.GetList("openid='" + openid + "' order by updatetime desc").Tables[0];

        if (dt.Rows.Count > 0)
        {
            string uptime = Convert.ToDateTime(dt.Rows[0]["updatetime"]).ToString("yyyy-MM-dd");
            string time   = DateTime.Now.ToString("yyyy-MM-dd");

            if (uptime == time)
            {
                muserinfo = userinfo.GetModel(int.Parse(dt.Rows[0]["id"].ToString()));
            }
            else
            {
                string Str = GetJson("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + Model.AppId + "&secret=" + Model.AppSecret + "");
                //微信回传的数据为Json格式,将Json格式转化成对象
                OAuth_Token ModelOAuth_Token = wxuser.JSONToObject <OAuth_Token>(Str);
                setlog("添加ModelOAuth_Token", ModelOAuth_Token.access_token);
                string     StrTwo   = GetJson("https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + ModelOAuth_Token.access_token + "&openid=" + openid + "");
                wxuserinfo ModelTwo = wxuser.JSONToObject <wxuserinfo>(StrTwo);
                muserinfo.subscribe      = ModelTwo.subscribe;
                muserinfo.openid         = ModelTwo.openid;
                muserinfo.nickname       = ModelTwo.nickname;
                muserinfo.sex            = ModelTwo.sex;
                muserinfo.language       = ModelTwo.language;
                muserinfo.city           = ModelTwo.city;
                muserinfo.province       = ModelTwo.province;
                muserinfo.country        = ModelTwo.country;
                muserinfo.headimgurl     = ModelTwo.headimgurl;
                muserinfo.subscribe_time = ModelTwo.subscribe_time;
                muserinfo.remark         = ModelTwo.remark;
                muserinfo.updatetime     = DateTime.Now;

                //str = setinfo("https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + Model.access_token + "&openid=" + openid, "", openid);
                //muserinfo = JSONToObject<Cms.Model.wx_userinfo>(str);
                //Cms.Model.wx_userinfo wx = new Cms.Model.wx_userinfo();
                ////wx.id = int.Parse(dt.Rows[0]["id"].ToString());
                //wx.subscribe = muserinfo.subscribe;
                //wx.openid = muserinfo.openid;
                //wx.nickname = muserinfo.nickname;
                //wx.sex = muserinfo.sex;
                //wx.language = muserinfo.language;
                //wx.city = muserinfo.city;
                //wx.province = muserinfo.province;
                //wx.country = muserinfo.country;
                //wx.headimgurl = muserinfo.headimgurl;
                //wx.subscribe_time = muserinfo.subscribe_time;
                //wx.remark = muserinfo.remark;
                //wx.updatetime = DateTime.Now;
                userinfo.Add(muserinfo);
            }
        }



        return(muserinfo);
    }
예제 #17
0
    public string GetPage3(string posturl, string postData, int type)
    {
        Stream          outstream = null;
        Stream          instream  = null;
        StreamReader    sr        = null;
        HttpWebResponse response  = null;
        HttpWebRequest  request   = null;
        Encoding        encoding  = Encoding.UTF8;

        byte[] data = encoding.GetBytes(postData);
        // 准备请求...
        try
        {
            // 设置参数
            request = WebRequest.Create(posturl) as HttpWebRequest;
            CookieContainer cookieContainer = new CookieContainer();
            request.CookieContainer   = cookieContainer;
            request.AllowAutoRedirect = true;
            request.Method            = "POST";
            request.ContentType       = "application/x-www-form-urlencoded";
            request.ContentLength     = data.Length;
            outstream = request.GetRequestStream();
            outstream.Write(data, 0, data.Length);
            outstream.Close();
            //发送请求并获取相应回应数据
            response = request.GetResponse() as HttpWebResponse;
            //直到request.GetResponse()程序才开始向目标网页发送Post请求
            instream = response.GetResponseStream();
            sr       = new StreamReader(instream, encoding);
            //返回结果网页(html)代码
            string content = sr.ReadToEnd();
            string err     = string.Empty;

            if (content.IndexOf("42001") > -1)
            {
                string            str = Gettoken();
                Cms.BLL.wx_info   wx  = new Cms.BLL.wx_info();
                Cms.Model.wx_info mwx = new Cms.Model.wx_info();
                mwx = wx.GetModel(1);
                mwx.access_token = str;
                wx.Update(mwx);
                Bind();
                //if (type == 0)
                //{
                //    GetPage3("http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=" + str + "&type=image", postData, type);
                //}
                if (type == 1)
                {
                    GetPage3("https://api.weixin.qq.com/cgi-bin/media/uploadnews?access_token=" + str, postData, type);
                }
            }
            string[] s        = content.Split(',');
            string   contents = s[1].Replace("\"media_id\":\"", "").Replace("\"", "");


            if (content.IndexOf("media_id") > -1)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("{");
                sb.Append("\"touser\":[");
                sb.Append("" + GetPage4("https://api.weixin.qq.com/cgi-bin/user/get?access_token=" + hdid.Text, "") + "");
                sb.Append(" ],");
                sb.Append("\"mpnews\":{");
                sb.Append("\"media_id\":\"" + contents + "\"");
                sb.Append(" },");
                sb.Append("\"msgtype\":\"mpnews\"");
                sb.Append("}");

                string str = GetPage3("https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token=" + hdid.Text + "", sb.ToString(), 0);
            }
            else if (content.IndexOf("0") > -1)
            {
                ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('推送成功!')</script>");
                return(null);
            }
            else
            {
                ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('推送失败!" + content + "')</script>");
                return(null);
            }
            //Response.Write(content);
            return(content);
        }
        catch (Exception ex)
        {
            string err = ex.Message;
            return(string.Empty);
        }
    }
예제 #18
0
    public static string setinfo(string postData)
    {
        Cms.BLL.wx_info   wxinfo = new Cms.BLL.wx_info();
        Cms.Model.wx_info Model  = new Cms.Model.wx_info();
        Model = wxinfo.GetModel(1);
        //string postData = "";
        string          posturl   = "http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=" + Model.access_token + "&type=voice";
        Stream          outstream = null;
        Stream          instream  = null;
        StreamReader    sr        = null;
        HttpWebResponse response  = null;
        HttpWebRequest  request   = null;
        Encoding        encoding  = Encoding.UTF8;

        byte[] data = encoding.GetBytes(postData);
        // 准备请求...
        try
        {
            // 设置参数
            request = WebRequest.Create(posturl) as HttpWebRequest;
            CookieContainer cookieContainer = new CookieContainer();
            request.CookieContainer   = cookieContainer;
            request.AllowAutoRedirect = true;
            request.Method            = "POST";
            request.ContentType       = "audior";
            request.ContentLength     = data.Length;
            outstream = request.GetRequestStream();
            outstream.Write(data, 0, data.Length);
            outstream.Close();
            //发送请求并获取相应回应数据
            response = request.GetResponse() as HttpWebResponse;
            //直到request.GetResponse()程序才开始向目标网页发送Post请求
            instream = response.GetResponseStream();
            sr       = new StreamReader(instream, encoding);
            //返回结果网页(html)代码
            string content = sr.ReadToEnd();
            string err     = string.Empty;

            if (content.IndexOf("42001") > -1)
            {
                string            str = Gettoken();
                Cms.BLL.wx_info   wx  = new Cms.BLL.wx_info();
                Cms.Model.wx_info mwx = new Cms.Model.wx_info();
                mwx = wx.GetModel(1);
                mwx.access_token = str;
                wx.Update(mwx);

                setinfo(postData);
            }

            string   s  = content.Replace("{", "").Replace("}", "").Replace("\"", "");
            string[] ss = s.Split(',');

            return(ss[1]);
        }
        catch (Exception ex)
        {
            string err = ex.Message;
            return(string.Empty);
        }
    }
예제 #19
0
파일: menu.aspx.cs 프로젝트: zklve/WxMall
    public string GetPage3(string posturl, string postData)
    {
        Stream          outstream = null;
        Stream          instream  = null;
        StreamReader    sr        = null;
        HttpWebResponse response  = null;
        HttpWebRequest  request   = null;
        Encoding        encoding  = Encoding.UTF8;

        byte[] data = encoding.GetBytes(postData);
        // 准备请求...
        try
        {
            // 设置参数
            request = WebRequest.Create(posturl) as HttpWebRequest;
            CookieContainer cookieContainer = new CookieContainer();
            request.CookieContainer   = cookieContainer;
            request.AllowAutoRedirect = true;
            request.Method            = "POST";
            request.ContentType       = "application/x-www-form-urlencoded";
            request.ContentLength     = data.Length;
            outstream = request.GetRequestStream();
            outstream.Write(data, 0, data.Length);
            outstream.Close();
            //发送请求并获取相应回应数据
            response = request.GetResponse() as HttpWebResponse;
            //直到request.GetResponse()程序才开始向目标网页发送Post请求
            instream = response.GetResponseStream();
            sr       = new StreamReader(instream, encoding);
            //返回结果网页(html)代码
            string content = sr.ReadToEnd();
            string err     = string.Empty;

            if (content.IndexOf("42001") > -1)
            {
                string            str = Gettoken();
                Cms.BLL.wx_info   wx  = new Cms.BLL.wx_info();
                Cms.Model.wx_info mwx = new Cms.Model.wx_info();
                mwx = wx.GetModel(1);
                mwx.access_token = str;
                wx.Update(mwx);
                Bind();

                GetPage3("https://api.weixin.qq.com/cgi-bin/media/uploadnews?access_token=" + str, postData);
            }


            if (content.IndexOf("0") > -1)
            {
                adminUser.AddAdminLog(DTEnums.ActionEnum.Edit.ToString(), "微信菜单推送成功"); //记录日志
                ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('推送成功!');", true);
                //ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('推送成功!')</script>");
            }
            else
            {
                adminUser.AddAdminLog(DTEnums.ActionEnum.Edit.ToString(), "微信菜单推送失败"); //记录日志
                ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('推送失败!" + content + "');", true);
                // ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('推送失败!" + content + "')</script>");
            }
            //Response.Write(content);
            return(content);
        }
        catch (Exception ex)
        {
            string err = ex.Message;
            return(string.Empty);
        }
    }