Exemplo n.º 1
0
        /// <summary>
        /// 创建自定义菜单
        /// </summary>
        /// <param name="body">创建内容</param>
        /// <returns>接口返回值</returns>
        public void CreateCustomerMenu(string body)
        {
            HttpContent content = new StringContent(body);

            string Url       = "https://api.weixin.qq.com/cgi-bin/menu/create?";
            string GetResult = ToolKit.PostData(Url + "access_token=" + this.Accesstoken(), content);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取二维码Ticket
        /// </summary>
        /// <param name="scene_id">场景标识</param>
        /// <returns>接口返回值</returns>
        public HttpResponseMessage GetQRcode(string ticket)
        {
            string Url = "https://mp.weixin.qq.com/cgi-bin/showqrcode?";
            HttpResponseMessage GetResult = ToolKit.GetHttpResponseMessage(Url + "ticket=" + ticket);

            return(GetResult);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 获取二维码Ticket
        /// </summary>
        /// <param name="scene_id">场景标识</param>
        /// <returns>接口返回值</returns>
        public wx_backdata <wx_oauth2token> GetOauth2AccessToken(string code)
        {
            string Url       = "https://api.weixin.qq.com/sns/oauth2/access_token?";
            string GetResult = ToolKit.GetData(Url + "appid=" + appid + "&secret=" + secret + "&code=" + code + "&grant_type=authorization_code");

            return(GetJson <wx_oauth2token>(GetResult));
        }
Exemplo n.º 4
0
        /// <summary>
        /// 获取指定用户信息
        /// </summary>
        /// <param name="openid">用户标识</param>
        /// <returns>接口返回值</returns>
        public wx_backdata <wx_user_info> GetUserInfo(string openid)
        {
            string Url       = "https://api.weixin.qq.com/cgi-bin/user/info?";
            string GetResult = ToolKit.GetData(Url + "access_token=" + this.Accesstoken() + "&openid=" + openid + "&lang=zh_CN");

            return(GetJson <wx_user_info>(GetResult));
        }
Exemplo n.º 5
0
        /// <summary>
        /// 获取粉丝微信OpenId
        /// </summary>
        /// <returns>接口返回值</returns>
        public wx_backdata <wx_openidlist> GetOpenIdList()
        {
            string Url       = "https://api.weixin.qq.com/cgi-bin/user/get?";
            string GetResult = ToolKit.GetData(Url + "access_token=" + this.Accesstoken() + "&next_openid=");

            return(GetJson <wx_openidlist>(GetResult));
        }
Exemplo n.º 6
0
        /// <summary>
        /// 根据接口返回代码42001验证是否可用
        /// </summary>
        /// <returns>true可用|false失效</returns>
        public bool check_access_token()
        {
            XmlDocument Xml = new XmlDocument();

            Xml.Load(HttpContext.Current.Server.MapPath(WEIXIN_CONFIG_PATH));
            XmlNode access_token = Xml.SelectSingleNode("weixin/accesstoken");

            if (access_token != null)
            {
                this.accesstoken = access_token.InnerText;
            }
            string Url       = "https://api.weixin.qq.com/cgi-bin/get_current_selfmenu_info?access_token=" + this.accesstoken;
            string GetResult = ToolKit.GetData(Url);

            if (GetResult.IndexOf("errcode") != -1)
            {
                var ErrorMessage = JsonConvert.DeserializeObject <wx_apperror>(GetResult);
                if (ErrorMessage.errcode == "42001")
                {
                    return(false);
                }
                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 获取唯一接口调用凭据access_token
        /// </summary>
        /// <returns>access_token获取结果对象</returns>
        public wx_backdata <wx_access_token> get_access_token()
        {
            string Url        = "https://api.weixin.qq.com/cgi-bin/token?";
            string grant_type = "client_credential";
            string GetResult  = ToolKit.GetData(Url + "grant_type=" + grant_type + "&appid=" + appid + "&secret=" + secret);

            return(GetJson <wx_access_token>(GetResult));
        }
Exemplo n.º 8
0
        /// <summary>
        /// 获取二维码Ticket
        /// </summary>
        /// <param name="scene_id">场景标识</param>
        /// <returns>接口返回值</returns>
        public wx_backdata <wx_ticket> GetQRcodeTicket(int scene_id)
        {
            string jsonString = "{\"action_name\": \"QR_LIMIT_SCENE\", \"action_info\": {\"scene\": {\"scene_id\": " + scene_id + "}}}";

            HttpContent content = new StringContent(jsonString);

            string Url       = "https://api.weixin.qq.com/cgi-bin/qrcode/create?";
            string GetResult = ToolKit.PostData(Url + "access_token=" + this.Accesstoken(), content);

            return(GetJson <wx_ticket>(GetResult));
        }