Beispiel #1
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);
    }
Beispiel #2
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");
    }
Beispiel #3
0
    public string setinfo(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();

                setinfo("https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" + str, postData);
            }


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


            return(content);
        }
        catch (Exception ex)
        {
            string err = ex.Message;
            return(string.Empty);
        }
    }
Beispiel #4
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);
    }
Beispiel #5
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);
        }
    }
Beispiel #6
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()));
            }
        }
    }
Beispiel #7
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);
        }
    }
Beispiel #8
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);
        }
    }
Beispiel #9
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);
        }
    }
Beispiel #10
0
    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);
        }
    }
Beispiel #11
0
    /// <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);
    }