Exemplo n.º 1
0
        /// <summary>
        /// 获取所有标签
        /// </summary>
        /// <returns>标签集合</returns>
        public List <TagInfo> Get()
        {
            string url    = $"https://api.weixin.qq.com/cgi-bin/tags/get?access_token={_accountModel.GetAccessToken()}";
            var    result = WeiXinHttpHelper.GetResultByJson <TagWarp>(url);

            return(result.Tags);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取公众号的全局唯一票据。
        /// </summary>
        /// <param name="ignoreCached">是否忽略缓存。</param>
        /// <returns>第三方用户唯一凭证密钥,即appsecret。</returns>
        public AccessTokenModel GetAccessToken(bool ignoreCached = false)
        {
            const string grantType = "client_credential";

            var appId     = _accountModel.AppId;
            var appSecret = _accountModel.AppSecret;

            Func <AccessTokenModel> get = () =>
            {
                var url = string.Format("https://api.weixin.qq.com/cgi-bin/token?grant_type={0}&appid={1}&secret={2}", grantType, appId, appSecret);
                return(WeiXinHttpHelper.GetResultByJson <AccessTokenModel>(url));
            };

            return(Dictionary.AddOrUpdate(appId, key => get(), (k, m) =>
            {
                //忽略缓存则负担和最新的数据。
                if (ignoreCached)
                {
                    return get();
                }

                //没有过期则直接返回。
                if (!m.IsExpired())
                {
                    return m;
                }

                var newModel = get();
                return newModel.AccessToken == m.AccessToken ? m : newModel;
            }));
        }
Exemplo n.º 3
0
        private AccessTokenModel InternalGetAccessToken()
        {
            const string grantType = "client_credential";

            var appId     = _accountModel.AppId;
            var appSecret = _accountModel.AppSecret;

            var url = string.Format("https://api.weixin.qq.com/cgi-bin/token?grant_type={0}&appid={1}&secret={2}", grantType, appId, appSecret);

            return(WeiXinHttpHelper.GetResultByJson <AccessTokenModel>(url));
        }
Exemplo n.º 4
0
        /// <summary>
        /// 获取用户信息。
        /// </summary>
        /// <param name="openId">普通用户的标识,对当前公众号唯一</param>
        /// <param name="language">返回国家地区语言版本,zh_CN 简体,zh_TW 繁体,en 英语</param>
        /// <returns>用户信息。</returns>
        public UserInfo GetUser(string openId, string language = null)
        {
            var url = string.Format("https://api.weixin.qq.com/cgi-bin/user/info?access_token={0}&openid={1}",
                                    _accountModel.GetAccessToken(), openId);

            if (!string.IsNullOrWhiteSpace(language))
            {
                url = url + "&lang=" + language;
            }

            return(WeiXinHttpHelper.GetResultByJson <UserInfo>(url));
        }
Exemplo n.º 5
0
        /// <summary>
        /// 获取用户信息。
        /// </summary>
        /// <param name="oAuthAccessToken">网页授权接口调用凭证,注意:此access_token与基础支持的access_token不同。</param>
        /// <param name="openId">用户的唯一标识。</param>
        /// <param name="language">返回国家地区语言版本,zh_CN 简体,zh_TW 繁体,en 英语。</param>
        /// <returns>用户信息。</returns>
        public OAuthUserInfo GetUserInfo(GetOAuthAccessTokenResult oAuthAccessToken, string openId, string language)
        {
            oAuthAccessToken.NotNull("accessToken");

            //票据过期则刷新票据。
            if (oAuthAccessToken.IsExpires())
            {
                oAuthAccessToken = RefreshToken(oAuthAccessToken.RefreshToken);
            }

            var url = string.Format("https://api.weixin.qq.com/sns/userinfo?access_token={0}&openid={1}&lang={2}",
                                    oAuthAccessToken.AccessToken, openId, language);

            return(WeiXinHttpHelper.GetResultByJson <OAuthUserInfo>(url));
        }
Exemplo n.º 6
0
        /// <summary>
        /// 获取永久素材数量。
        /// </summary>
        /// <returns>获取素材数量的结果模型。</returns>
        public GetMaterialCountResultModel GetMaterialCount(string accessToken)
        {
            var url = "https://api.weixin.qq.com/cgi-bin/material/get_materialcount?access_token=" + _accountModel.GetAccessToken();

            return(WeiXinHttpHelper.GetResultByJson <GetMaterialCountResultModel>(url));
        }
        /// <summary>
        /// 获取未接入会话列表。
        /// </summary>
        /// <returns>等待服务的信息。</returns>
        /// <remarks>开发者可以通过本接口获取当前正在等待队列中的会话列表,此接口最多返回最早进入队列的100个未接入会话。</remarks>
        public WaitServiceInfo GetWaitList()
        {
            var url = string.Format("https://api.weixin.qq.com/customservice/kfsession/getwaitcase?access_token={0}", _accountModel.GetAccessToken());

            return(WeiXinHttpHelper.GetResultByJson <WaitServiceInfo>(url));
        }
        /// <summary>
        /// 获取客户的会话状态.
        /// </summary>
        /// <param name="openId">客户openid</param>
        /// <returns>会话信息。</returns>
        public UserSessionInfo Get(string openId)
        {
            var url = string.Format("https://api.weixin.qq.com/customservice/kfsession/getsession?access_token={0}&openid={1}", _accountModel.GetAccessToken(), openId);

            return(WeiXinHttpHelper.GetResultByJson <UserSessionInfo>(url));
        }