Пример #1
0
        public static string GetChildUserInfo(string token, string openid)
        {
            string url = string.Format("https://api.weixin.qq.com/cgi-bin/user/info?access_token={0}&openid={1}&lang=zh_CN", token, openid);
            string str = Submit.HttpGet(url);

            //return wui;
            return(str);
        }
Пример #2
0
        public static Dictionary <string, object> GetToken()
        {
            string url       = string.Format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}", WeChatConfig.AppId, WeChatConfig.AppSecret);
            string returnStr = Submit.HttpGet(url);
            JavaScriptSerializer        serializer = new JavaScriptSerializer();
            Dictionary <string, object> dic        = (Dictionary <string, object>)serializer.DeserializeObject(returnStr);

            return(dic);
        }
Пример #3
0
        public static string GetToken(string appid, string secret)
        {
            string url       = string.Format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}", appid, secret);
            string returnStr = Submit.HttpGet(url);
            JavaScriptSerializer        serializer = new JavaScriptSerializer();
            Dictionary <string, object> dictionary = (Dictionary <string, object>)serializer.DeserializeObject(returnStr);

            return(dictionary["access_token"].ToString());
        }
Пример #4
0
        public static string GetUserInfo(string token, string openid)
        {
            string url = string.Format("https://api.weixin.qq.com/cgi-bin/user/info?access_token={0}&openid={1}&lang=zh_CN", token, openid);
            string str = Submit.HttpGet(url);

            //JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
            //WeChatUserInfo wui = jsonSerializer.Deserialize<WeChatUserInfo>(str);
            //return wui;
            return(str);
        }
Пример #5
0
        private void GetOpenId()
        {
            string _Code = Request.QueryString["code"];

            if (string.IsNullOrEmpty(_Code))
            {
                string url = string.Format(POSTCODEURL + "?appid={0}&redirect_uri={1}&response_type=code&scope={2}#wechat_redirect", WeChatConfig.AppId, HttpUtility.UrlEncode(Request.Url.AbsoluteUri), SCOPE);
                Response.Redirect(url);
            }
            else
            {
                string  url    = string.Format(POSTTOKENURL + "?appid={0}&secret={1}&code={2}&grant_type=authorization_code", WeChatConfig.AppId, WeChatConfig.AppSecret, _Code);
                string  str    = Submit.HttpGet(url);
                JObject json   = JObject.Parse(str);
                string  OpenId = json["openid"].ToString();
                Session["OpenIdE"] = OpenId;
            }
        }
Пример #6
0
        /// <summary>
        /// 机器人
        /// </summary>
        /// <param name="requestContent"></param>
        /// <returns></returns>
        private string HandleOther(string str, string fromuser, string touser)
        {
            string  response    = string.Empty;
            string  tempstr     = string.Empty;
            string  url         = string.Format("http://www.tuling123.com/openapi/api?key={0}&info={1}", TULINKEY, str);
            string  responseStr = Submit.HttpGet(url);
            JObject json        = JObject.Parse(responseStr);
            string  code        = json["code"].ToString();

            if (!string.IsNullOrEmpty(code))
            {
                int type = Convert.ToInt32(code);
                switch (type)
                {
                case 100000:
                    response = string.Format(ReplyType.Message_Text,
                                             fromuser,
                                             touser,
                                             DateTime.Now.Ticks,
                                             (json["text"] + "").Replace("<br>", "\n"));
                    break;

                case 200000:
                    response = string.Format(ReplyType.Message_Text,
                                             fromuser,
                                             touser,
                                             DateTime.Now.Ticks,
                                             json["text"] + "\n" + json["url"]);
                    break;

                case 302000:
                    tempstr = "";
                    JToken jtk302 = json["list"];
                    for (int i = 0; i < jtk302.Count(); i++)
                    {
                        tempstr += string.Format(ReplyType.Message_News_Item,
                                                 jtk302[i]["article"],
                                                 jtk302[i]["source"],
                                                 jtk302[i]["icon"],
                                                 jtk302[i]["detailurl"]);
                    }
                    response = string.Format(ReplyType.Message_News_Main,
                                             fromuser,
                                             touser,
                                             DateTime.Now.Ticks,
                                             jtk302.Count(),
                                             tempstr);
                    break;

                case 305000:
                    tempstr = "";
                    JToken jtk305 = json["list"];
                    tempstr += json["text"] + "\n\n";
                    for (int i = 0; i < jtk305.Count(); i++)
                    {
                        tempstr += "车次:" + jtk305[i]["trainnum"] + "\n";
                        tempstr += "起始站:" + jtk305[i]["start"] + "\n";
                        tempstr += "到达站:" + jtk305[i]["terminal"] + "\n";
                        tempstr += "开车时间:" + jtk305[i]["starttime"] + "\n";
                        tempstr += "到达时间:" + jtk305[i]["endtime"] + "\n";
                        if (i < jtk305.Count() - 1)
                        {
                            tempstr += "\n";
                        }
                    }
                    response = string.Format(ReplyType.Message_Text,
                                             fromuser,
                                             touser,
                                             DateTime.Now.Ticks,
                                             tempstr);
                    break;

                case 308000:
                    tempstr = "";
                    JToken jtk308 = json["list"];
                    tempstr += json["text"] + "\n\n";
                    for (int i = 0; i < jtk308.Count(); i++)
                    {
                        tempstr += "名称:" + jtk308[i]["name"] + "\n";
                        tempstr += "详情:" + jtk308[i]["info"] + "\n";
                        if (i < jtk308.Count() - 1)
                        {
                            tempstr += "\n";
                        }
                    }
                    response = string.Format(ReplyType.Message_Text,
                                             fromuser,
                                             touser,
                                             DateTime.Now.Ticks,
                                             tempstr);
                    break;

                default:
                    response = string.Format(ReplyType.Message_Text,
                                             fromuser,
                                             touser,
                                             DateTime.Now.Ticks,
                                             json["code"] + "");
                    break;
                }
            }


            //if (requestContent.Contains("你好") || requestContent.Contains("您好"))
            //{
            //    response = "您也好~";
            //}
            //else if (requestContent.Contains("傻"))
            //{
            //    response = "我不傻!哼~ ";
            //}
            //else if (requestContent.Contains("逼") || requestContent.Contains("操"))
            //{
            //    response = "哼,你说脏话! ";
            //}
            //else if (requestContent.Contains("是谁"))
            //{
            //    response = "我是大哥大,有什么能帮您的吗?~";
            //}
            //else if (requestContent.Contains("再见"))
            //{
            //    response = "再见!";
            //}
            //else if (requestContent.Contains("bye"))
            //{
            //    response = "Bye!";
            //}
            //else if (requestContent.Contains("谢谢"))
            //{
            //    response = "不客气!嘿嘿";
            //}
            //else if (requestContent == "h" || requestContent == "H" || requestContent.Contains("帮助"))
            //{
            //    response = @"查询天气,输入tq 城市名称\拼音\首字母";
            //}
            //else
            //{
            //    response = "您说的,可惜,我没明白啊,试试其他关键字吧。";
            //}

            return(response);
        }
Пример #7
0
        /// <summary>
        /// 机器人
        /// </summary>
        /// <param name="requestContent"></param>
        /// <returns></returns>
        private string HandleOther(string str, string fromuser, string touser)
        {
            string  response    = string.Empty;
            string  tempstr     = string.Empty;
            string  url         = string.Format("http://www.tuling123.com/openapi/api?key={0}&info={1}", TULINKEY, str);
            string  responseStr = Submit.HttpGet(url);
            JObject json        = JObject.Parse(responseStr);
            string  code        = json["code"].ToString();

            if (!string.IsNullOrEmpty(code))
            {
                int type = Convert.ToInt32(code);
                switch (type)
                {
                case 100000:
                    response = string.Format(ReplyTyper.Message_Text,
                                             fromuser,
                                             touser,
                                             DateTime.Now.Ticks,
                                             (json["text"] + "").Replace("<br>", "\n"));
                    break;

                case 200000:
                    response = string.Format(ReplyTyper.Message_Text,
                                             fromuser,
                                             touser,
                                             DateTime.Now.Ticks,
                                             json["text"] + "\n" + json["url"]);
                    break;

                case 302000:
                    tempstr = "";
                    JToken jtk302 = json["list"];
                    for (int i = 0; i < jtk302.Count(); i++)
                    {
                        tempstr += string.Format(ReplyTyper.Message_News_Item,
                                                 jtk302[i]["article"],
                                                 jtk302[i]["source"],
                                                 jtk302[i]["icon"],
                                                 jtk302[i]["detailurl"]);
                    }
                    response = string.Format(ReplyTyper.Message_News_Main,
                                             fromuser,
                                             touser,
                                             DateTime.Now.Ticks,
                                             jtk302.Count(),
                                             tempstr);
                    break;

                case 305000:
                    tempstr = "";
                    JToken jtk305 = json["list"];
                    tempstr += json["text"] + "\n\n";
                    for (int i = 0; i < jtk305.Count(); i++)
                    {
                        tempstr += "车次:" + jtk305[i]["trainnum"] + "\n";
                        tempstr += "起始站:" + jtk305[i]["start"] + "\n";
                        tempstr += "到达站:" + jtk305[i]["terminal"] + "\n";
                        tempstr += "开车时间:" + jtk305[i]["starttime"] + "\n";
                        tempstr += "到达时间:" + jtk305[i]["endtime"] + "\n";
                        if (i < jtk305.Count() - 1)
                        {
                            tempstr += "\n";
                        }
                    }
                    response = string.Format(ReplyTyper.Message_Text,
                                             fromuser,
                                             touser,
                                             DateTime.Now.Ticks,
                                             tempstr);
                    break;

                case 308000:
                    tempstr = "";
                    JToken jtk308 = json["list"];
                    tempstr += json["text"] + "\n\n";
                    for (int i = 0; i < jtk308.Count(); i++)
                    {
                        tempstr += "名称:" + jtk308[i]["name"] + "\n";
                        tempstr += "详情:" + jtk308[i]["info"] + "\n";
                        if (i < jtk308.Count() - 1)
                        {
                            tempstr += "\n";
                        }
                    }
                    response = string.Format(ReplyTyper.Message_Text,
                                             fromuser,
                                             touser,
                                             DateTime.Now.Ticks,
                                             tempstr);
                    break;

                default:
                    response = string.Format(ReplyTyper.Message_Text,
                                             fromuser,
                                             touser,
                                             DateTime.Now.Ticks,
                                             json["code"] + "");
                    break;
                }
            }
            return(response);
        }