Beispiel #1
0
        public static MainButton GetMenu(string accessToken)
        {
            var url = WxUrl.GetMenu.ToFormat(accessToken);

            try
            {
                return(WxHttp.Get <FullButtonGroupMenu>(url).ToMainButton());
            }
            catch (Exception ex)
            {
                TxtLogServices.WriteTxtLogEx("WeiXinBase", ex);
                return(null);
            }
        }
Beispiel #2
0
        public static bool DeleteMenu(string companyId, string accessToken)
        {
            ResError result = WxHttp.Get(WxUrl.DeleteMenu.ToFormat(accessToken));

            if (result.errcode == ResCode.请求成功)
            {
                return(true);
            }
            if (result.errcode == ResCode.获取accessToken时AppSecret错误或者accessToken无效)
            {
                WX_ApiConfig config         = WXApiConfigServices.QueryWXApiConfig(companyId);
                var          newAccessToken = AccessTokenContainer.TryGetToken(config.AppId, config.AppSecret, true);
                ResError     newResult      = WxHttp.Get(WxUrl.DeleteMenu.ToFormat(newAccessToken));
                return(newResult.errcode == ResCode.请求成功);
            }
            return(false);
        }
Beispiel #3
0
        /// <summary>
        /// 获取凭证接口
        /// </summary>
        /// <param name="grantType">获取access_token填写client_credential</param>
        /// <param name="appid">第三方用户唯一凭证</param>
        /// <param name="secret">第三方用户唯一凭证密钥,既appsecret</param>
        /// <returns></returns>
        public static AccessToken GetToken(string appid, string secret, string grantType = "client_credential")
        {
            var url = WxUrl.GetAccessToken.ToFormat(grantType, appid, secret);

            return(WxHttp.Get <AccessToken>(url));
        }
Beispiel #4
0
        /// <summary>
        /// 获取JsapiTicket
        /// </summary>
        public static JsapiTicket GetTicket(string accesstoken)
        {
            var url = WxUrl.GetTicket.ToFormat(accesstoken, DateTime.Now.Ticks);

            return(WxHttp.Get <JsapiTicket>(url));
        }
Beispiel #5
0
        /// <summary>
        /// 取帐号的关注者列表
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="nextOpenId"></param>
        /// <returns></returns>
        public static UserGet GetUserList(string accessToken, string nextOpenId)
        {
            var url = WxUrl.GetUsers.ToFormat(accessToken, nextOpenId);

            return(WxHttp.Get <UserGet>(url));
        }
Beispiel #6
0
        /// <summary>
        /// 获取JsapiTicket
        /// </summary>
        public static JsapiTicket GetTicket(AccessToken token)
        {
            var url = WxUrl.UpdateUserGroup.ToFormat(token.Accesstoken, DateTime.Now.Ticks);

            return(WxHttp.Get <JsapiTicket>(url));
        }
Beispiel #7
0
        /// <summary>
        /// 获取用户基本信息
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="openId"></param>
        /// <param name="lang"></param>
        /// <returns></returns>
        public static UserInfo GetUserInfo(string accessToken, string openId, string lang = "zh_CN")
        {
            var url = WxUrl.GetUserInfo.ToFormat(accessToken, openId, lang);

            return(WxHttp.Get <UserInfo>(url));
        }
Beispiel #8
0
        /// <summary>
        /// 查询所有分组
        /// </summary>
        /// <param name="accessToken"></param>
        /// <returns></returns>
        public static GroupList GetGroup(string accessToken)
        {
            var url = WxUrl.GetGroups.ToFormat(accessToken);

            return(WxHttp.Get <GroupList>(url));
        }
Beispiel #9
0
        /// <summary>
        /// 通过OAuthAccessToken获取用户信息
        /// </summary>
        /// <returns></returns>
        public static OAuthUserInfo GetOAuthUserInfo(string oAuthAccessToken, string openId, string lang = "zh_CN")
        {
            var url = WxUrl.SnsApiUserInfo.ToFormat(oAuthAccessToken, openId, lang);

            return(WxHttp.Get <OAuthUserInfo>(url));
        }
Beispiel #10
0
        /// <summary>
        /// 刷新access_token(如果需要)
        /// </summary>
        /// <param name="appId"></param>
        /// <param name="refreshToken">填写通过access_token获取到的refresh_token参数</param>
        /// <param name="grantType"></param>
        /// <returns></returns>
        public static OAuthAccessToken RefreshToken(string appId, string refreshToken, string grantType = "refresh_token")
        {
            var url = WxUrl.RefreshCodeAccessToken.ToFormat(appId, grantType, refreshToken);

            return(WxHttp.Get <OAuthAccessToken>(url));
        }
Beispiel #11
0
        /// <summary>
        /// 获取AccessToken
        /// </summary>
        /// <param name="appId"></param>
        /// <param name="secret"></param>
        /// <param name="code">code作为换取access_token的票据,每次用户授权带上的code将不一样,code只能使用一次,5分钟未被使用自动过期。</param>
        /// <param name="grantType"></param>
        /// <returns></returns>
        public static OAuthAccessToken GetAccessToken(string appId, string secret, string code, string grantType = "authorization_code")
        {
            var url = WxUrl.GetCodeAccessToken.ToFormat(appId, secret, code, grantType);

            return(WxHttp.Get <OAuthAccessToken>(url));
        }