public static RequestApiResult Update(DomainContext domainContext, WeixinTag args)
        {
            string           accessToken = domainContext.AccessToken;
            RequestApiResult result      = TagsApi.Update(accessToken, args);

            if (result.Success == false)
            {
                if (result.Retry)
                {
                    if (result.ApiError.ErrorCode == 40001)
                    {
                        accessToken = AccessTokenGetter.Refresh(domainContext.AppId, accessToken);
                    }

                    result = TagsApi.Update(accessToken, args);
                    if (result.Success == false)
                    {
                        _log.Write("TagsApi.Update 失败",
                                   result.GetDetail(), TraceEventType.Warning);
                    }
                }
                else
                {
                    _log.Write("TagsApi.Update 失败",
                               result.GetDetail(), TraceEventType.Warning);
                }
            }

            return(result);
        }
Beispiel #2
0
        public static RequestApiResult Send(DomainContext domainContext, KFMessageBase message)
        {
            string           accessToken = domainContext.AccessToken;
            RequestApiResult result      = KFApi.Send(accessToken, message);

            if (result.Success == false)
            {
                if (result.Retry)
                {
                    if (result.ApiError.ErrorCode == 40001)
                    {
                        accessToken = AccessTokenGetter.Refresh(domainContext.AppId, accessToken);
                    }

                    result = KFApi.Send(accessToken, message);
                    if (result.Success == false)
                    {
                        _log.Write("KFApi.Send 失败",
                                   result.GetDetail(), TraceEventType.Warning);
                    }
                }
                else
                {
                    _log.Write("KFApi.Send 失败",
                               result.GetDetail(), TraceEventType.Warning);
                }
            }

            return(result);
        }
Beispiel #3
0
        public static RequestApiResult <WeixinGroupMessagePreviewResult> Preview(DomainContext domainContext, WeixinGroupMessagePreviewArgs args)
        {
            string accessToken = domainContext.AccessToken;
            RequestApiResult <WeixinGroupMessagePreviewResult> result = GroupMessageApi.Preview(accessToken, args);

            if (result.Success == false)
            {
                if (result.Retry)
                {
                    if (result.ApiError.ErrorCode == 40001)
                    {
                        accessToken = AccessTokenGetter.Refresh(domainContext.AppId, accessToken);
                    }

                    result = GroupMessageApi.Preview(accessToken, args);
                    if (result.Success == false)
                    {
                        _log.Write("GroupMessageApi.Preview 失败",
                                   result.GetDetail(), TraceEventType.Warning);
                    }
                }
                else
                {
                    _log.Write("GroupMessageApi.Preview 失败",
                               result.GetDetail(), TraceEventType.Warning);
                }
            }

            return(result);
        }
        public static RequestApiResult <WeixinGetUserTagListResult> GetUserTagList(DomainContext domainContext, string openId)
        {
            string accessToken = domainContext.AccessToken;
            RequestApiResult <WeixinGetUserTagListResult> result = TagsApi.GetUserTagList(accessToken, openId);

            if (result.Success == false)
            {
                if (result.Retry)
                {
                    if (result.ApiError.ErrorCode == 40001)
                    {
                        accessToken = AccessTokenGetter.Refresh(domainContext.AppId, accessToken);
                    }

                    result = TagsApi.GetUserTagList(accessToken, openId);
                    if (result.Success == false)
                    {
                        _log.Write("TagsApi.GetUserTagList 失败",
                                   result.GetDetail(), TraceEventType.Warning);
                    }
                }
                else
                {
                    _log.Write("TagsApi.GetUserTagList 失败",
                               result.GetDetail(), TraceEventType.Warning);
                }
            }

            return(result);
        }
Beispiel #5
0
        public static RequestApiResult Remove(DomainContext domainContext, int groupId)
        {
            string           accessToken = domainContext.AccessToken;
            RequestApiResult result      = GroupApi.Remove(accessToken, groupId);

            if (result.Success == false)
            {
                if (result.Retry)
                {
                    if (result.ApiError.ErrorCode == 40001)
                    {
                        accessToken = AccessTokenGetter.Refresh(domainContext.AppId, accessToken);
                    }

                    result = GroupApi.Remove(accessToken, groupId);
                    if (result.Success == false)
                    {
                        _log.Write("GroupApi.Remove 失败",
                                   result.GetDetail(), TraceEventType.Warning);
                    }
                }
                else
                {
                    _log.Write("GroupApi.Remove 失败",
                               result.GetDetail(), TraceEventType.Warning);
                }
            }

            return(result);
        }
Beispiel #6
0
        public static RequestApiResult SetUserListGroup(DomainContext domainContext, WeixinSetUserListGroupArgs args)
        {
            string           accessToken = domainContext.AccessToken;
            RequestApiResult result      = GroupApi.SetUserListGroup(accessToken, args);

            if (result.Success == false)
            {
                if (result.Retry)
                {
                    if (result.ApiError.ErrorCode == 40001)
                    {
                        accessToken = AccessTokenGetter.Refresh(domainContext.AppId, accessToken);
                    }

                    result = GroupApi.SetUserListGroup(accessToken, args);
                    if (result.Success == false)
                    {
                        _log.Write("GroupApi.SetUserListGroup 失败",
                                   result.GetDetail(), TraceEventType.Warning);
                    }
                }
                else
                {
                    _log.Write("GroupApi.SetUserListGroup 失败",
                               result.GetDetail(), TraceEventType.Warning);
                }
            }

            return(result);
        }
        public static RequestApiResult <WeixinAddMaterialResult> AddNormalMaterial(DomainContext domainContext, string file, MaterialType type)
        {
            string accessToken = domainContext.AccessToken;
            RequestApiResult <WeixinAddMaterialResult> result = MaterialApi.AddNormalMaterial(accessToken, file, type);

            if (result.Success == false)
            {
                if (result.Retry)
                {
                    if (result.ApiError.ErrorCode == 40001)
                    {
                        accessToken = AccessTokenGetter.Refresh(domainContext.AppId, accessToken);
                    }

                    result = MaterialApi.AddNormalMaterial(accessToken, file, type);
                    if (result.Success == false)
                    {
                        _log.Write("MaterialApi.AddNormalMaterial 失败",
                                   result.GetDetail(), TraceEventType.Warning);
                    }
                }
                else
                {
                    _log.Write("MaterialApi.AddNormalMaterial 失败",
                               result.GetDetail(), TraceEventType.Warning);
                }
            }

            return(result);
        }
        public static RequestApiResult <WeixinArticleMaterialListItemContent> GetArticleMaterial(DomainContext domainContext, string mediaId)
        {
            string accessToken = domainContext.AccessToken;
            RequestApiResult <WeixinArticleMaterialListItemContent> result = MaterialApi.GetArticleMaterial(accessToken, mediaId);

            if (result.Success == false)
            {
                if (result.Retry)
                {
                    if (result.ApiError.ErrorCode == 40001)
                    {
                        accessToken = AccessTokenGetter.Refresh(domainContext.AppId, accessToken);
                    }

                    result = MaterialApi.GetArticleMaterial(accessToken, mediaId);
                    if (result.Success == false)
                    {
                        _log.Write("MaterialApi.GetArticleMaterial 失败",
                                   result.GetDetail(), TraceEventType.Warning);
                    }
                }
                else
                {
                    _log.Write("MaterialApi.GetArticleMaterial 失败",
                               result.GetDetail(), TraceEventType.Warning);
                }
            }

            return(result);
        }
        public static RequestApiResult <WeixinGetNormalMaterialListResult> GetNormalMaterialList(DomainContext domainContext, WeixinGetMaterialListArgs args)
        {
            string accessToken = domainContext.AccessToken;
            RequestApiResult <WeixinGetNormalMaterialListResult> result = MaterialApi.GetNormalMaterialList(accessToken, args);

            if (result.Success == false)
            {
                if (result.Retry)
                {
                    if (result.ApiError.ErrorCode == 40001)
                    {
                        accessToken = AccessTokenGetter.Refresh(domainContext.AppId, accessToken);
                    }

                    result = MaterialApi.GetNormalMaterialList(accessToken, args);
                    if (result.Success == false)
                    {
                        _log.Write("MaterialApi.GetNormalMaterialList 失败",
                                   result.GetDetail(), TraceEventType.Warning);
                    }
                }
                else
                {
                    _log.Write("MaterialApi.GetNormalMaterialList 失败",
                               result.GetDetail(), TraceEventType.Warning);
                }
            }

            return(result);
        }
        public static RequestApiResult <WeixinCreateShortUrlResult> GetShortUrl(DomainContext domainContext, string longUrl)
        {
            string accessToken = domainContext.AccessToken;
            RequestApiResult <WeixinCreateShortUrlResult> result = ShortUrlApi.GetShortUrl(accessToken, longUrl);

            if (result.Success == false)
            {
                if (result.Retry)
                {
                    if (result.ApiError.ErrorCode == 40001)
                    {
                        accessToken = AccessTokenGetter.Refresh(domainContext.AppId, accessToken);
                    }

                    result = ShortUrlApi.GetShortUrl(accessToken, longUrl);
                    if (result.Success == false)
                    {
                        _log.Write("ShortUrlApi.GetShortUrl 失败",
                                   result.GetDetail(), TraceEventType.Warning);
                    }
                }
                else
                {
                    _log.Write("ShortUrlApi.GetShortUrl 失败",
                               result.GetDetail(), TraceEventType.Warning);
                }
            }

            return(result);
        }
Beispiel #11
0
        /// <summary>
        /// 用户管理-获取用户基本信息
        /// 未认证订阅号 未认证服务号 没有此权限
        /// </summary>
        /// <param name="domainContext"></param>
        /// <param name="openId"></param>
        /// <returns></returns>
        public static RequestApiResult <WeixinUser> GetUserInfo(DomainContext domainContext, string openId)
        {
            RequestApiResult <WeixinUser> result;

            if (domainContext == null || domainContext.Authorizer == null)
            {
                result                       = new RequestApiResult <WeixinUser>();
                result.ApiError              = new WeixinApiErrorResult();
                result.ApiError.ErrorCode    = -1;
                result.ApiError.ErrorMessage = "无域信息或无授权信息。";
                return(result);
            }

            if (domainContext.Authorizer.AuthorizationType == EnumAuthorizationType.UnauthorizedService ||
                domainContext.Authorizer.AuthorizationType == EnumAuthorizationType.UnauthorizedSubscription)
            {
                result                       = new RequestApiResult <WeixinUser>();
                result.ApiError              = new WeixinApiErrorResult();
                result.ApiError.ErrorCode    = -1;
                result.ApiError.ErrorMessage = "未认证订阅号 及 未认证服务号 没有获取用户基本信息权限。";
                return(result);
            }

            string accessToken = domainContext.AccessToken;

            result = UserApi.GetUserInfo(accessToken, openId);

            if (result.Success == false)
            {
                if (result.Retry)
                {
                    if (result.ApiError.ErrorCode == 40001)
                    {
                        accessToken = AccessTokenGetter.Refresh(domainContext.AppId, accessToken);
                    }

                    result = UserApi.GetUserInfo(accessToken, openId);
                    if (result.Success == false)
                    {
                        _log.Write("UserApi.GetUserInfo 失败",
                                   result.GetDetail(), TraceEventType.Warning);
                    }
                }
                else
                {
                    _log.Write("UserApi.GetUserInfo 失败",
                               result.GetDetail(), TraceEventType.Warning);
                }
            }

            return(result);
        }
Beispiel #12
0
        /// <summary>
        /// 用户管理-获取用户列表
        /// 未认证订阅号 未认证服务号 没有此权限
        /// </summary>
        /// <param name="domainContext"></param>
        /// <param name="next_openid"></param>
        /// <returns></returns>
        public static RequestApiResult <WeixinGetUserListResult> GetUserList(DomainContext domainContext, string next_openid)
        {
            RequestApiResult <WeixinGetUserListResult> result;

            if (domainContext.Authorizer.AuthorizationType == EnumAuthorizationType.UnauthorizedService ||
                domainContext.Authorizer.AuthorizationType == EnumAuthorizationType.UnauthorizedSubscription)
            {
                result                       = new RequestApiResult <WeixinGetUserListResult>();
                result.ApiError              = new WeixinApiErrorResult();
                result.ApiError.ErrorCode    = -1;
                result.ApiError.ErrorMessage = "未认证订阅号 及 未认证服务号 没有获取用户列表权限。";
                return(result);
            }

            string accessToken = domainContext.AccessToken;

            result = UserApi.GetUserList(accessToken, next_openid);

            if (result.Success == false)
            {
                if (result.Retry)
                {
                    if (result.ApiError.ErrorCode == 40001)
                    {
                        accessToken = AccessTokenGetter.Refresh(domainContext.AppId, accessToken);
                    }

                    result = UserApi.GetUserList(accessToken, next_openid);
                    if (result.Success == false)
                    {
                        string logMessage = result.GetDetail() + Environment.NewLine + new StackTrace().ToString();
                        _log.Write("UserApi.GetUserList 失败", logMessage, TraceEventType.Warning);
                    }
                }
                else
                {
                    string logMessage = result.GetDetail() + Environment.NewLine + new StackTrace().ToString();
                    _log.Write("UserApi.GetUserList 失败", logMessage, TraceEventType.Warning);
                }
            }

            return(result);
        }
Beispiel #13
0
        public static RequestApiResult <WeixinGetJsApiTicketResult> GetJsApiTicket(string appId)
        {
            string accessToken = AccessTokenGetter.Get(appId);
            RequestApiResult <WeixinGetJsApiTicketResult> result = TokenApi.GetJsApiTicket(accessToken);

            if (result.Success == false)
            {
                if (result.Retry)
                {
                    if (result.ApiError.ErrorCode == 40001)
                    {
                        accessToken = AccessTokenGetter.Refresh(appId, accessToken);
                    }

                    result = TokenApi.GetJsApiTicket(accessToken);
                    if (result.Success == false)
                    {
                        _log.Write("TokenApi.GetJsApiTicket 失败",
                                   result.GetDetail(), TraceEventType.Warning);
                    }
                }
                else
                {
                    _log.Write("TokenApi.GetJsApiTicket 失败",
                               result.GetDetail(), TraceEventType.Warning);
                }
            }
            else
            {
                //保存新的jsApiTicket到数据库
                WeixinGetJsApiTicketResult token = result.ApiResult;
                ThirdPartyManager.Instance.UpdateAuthorizerJsApiTicket(
                    appId, token.Ticket, DateTime.Now.AddSeconds(token.ExpiresIn));
            }

            return(result);
        }