Пример #1
0
        public void CreateMemberTest(string userId)
        {
            Extattr extattr = new Extattr()
            {
                attrs = new List <Attr>()
                {
                    new Attr()
                    {
                        name = "员工角色", value = "123"
                    }
                }
            };
            var accessToken = AccessTokenContainer.GetToken(_corpId, base._corpSecret);

            var memberCreateRequest = new  MemberCreateRequest()
            {
                userid       = userId,
                name         = string.Format("单元测试生成-{0}", SystemTime.Now.ToString("yyMMdd-HH:mm")),
                english_name = "english name",
                department   = new long[] { 2 },
                gender       = "1",
                email        = "*****@*****.**",
                extattr      = extattr
            };

            var result = MailListApi.CreateMember(accessToken, memberCreateRequest);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.errcode == ReturnCode_Work.请求成功);
        }
Пример #2
0
        /// <summary>
        /// 创建成员(mobile/weixinid/email三者不能同时为空)【QY移植修改】
        /// 文档:http://work.weixin.qq.com/api/doc#10018
        /// </summary>
        /// <param name="accessTokenOrAppKey">调用接口凭证</param>
        /// <param name="userId">员工UserID。必须企业内唯一</param>
        /// <param name="name">成员名称。长度为1~64个字符</param>
        /// <param name="englishName">(非必须)英文名。长度为1-64个字节。第三方暂不支持</param>
        /// <param name="department">成员所属部门id列表。注意,每个部门的直属员工上限为1000个</param>
        /// <param name="order">部门内的排序值,默认为0。数量必须和department一致,数值越大排序越前面。第三方暂不支持</param>
        /// <param name="position">职位信息。长度为0~64个字符</param>
        /// <param name="mobile">手机号码。必须企业内唯一</param>
        /// <param name="telephone">座机。长度0-64个字节。第三方暂不支持</param>
        /// <param name="email">邮箱。长度为0~64个字符。必须企业内唯一</param>
        /// <param name="gender">性别。gender=0表示男,=1表示女。默认gender=0(QY由此说明,Work无)</param>
        /// <param name="avatarMediaid"></param>
        /// <param name="extattr">扩展属性。扩展属性需要在WEB管理端创建后才生效,否则忽略未知属性的赋值</param>
        /// <param name="isLeader">(非必填)上级字段,标识是否为上级(1为是,0为否)。第三方暂不支持</param>
        /// <param name="enable">(非必填)</param>
        /// <param name="timeOut">代理请求超时时间(毫秒)</param>
        /// <returns></returns>
        public static WorkJsonResult CreateMember(string accessTokenOrAppKey, string userId, string name = null,
                                                  string mobile    = null, string englishName = null,
                                                  int[] department = null, int[] order        = null, string gender    = null,
                                                  string position  = null, string email       = null, string telephone = null, string avatarMediaid = null,
                                                  int?isLeader     = null, int?enable         = null,
                                                  Extattr extattr  = null, int timeOut        = Config.TIME_OUT)
        {
            return(ApiHandlerWapper.TryCommonApi(accessToken =>
            {
                var url = "https://qyapi.weixin.qq.com/cgi-bin/user/create?access_token={0}";

                var data = new
                {
                    userid = userId,
                    name = name,
                    english_name = englishName,
                    mobile = mobile,
                    department = department,
                    order = order,
                    position = position,
                    gender = gender,
                    email = email,
                    telephone = telephone,
                    isleader = isLeader,
                    avatar_mediaid = avatarMediaid,
                    enable = enable,
                    extattr = extattr
                };

                JsonSetting jsonSetting = new JsonSetting(true);

                return Senparc.Weixin.CommonAPIs.CommonJsonSend.Send <WorkJsonResult>(accessToken, url, data, CommonJsonSendType.POST, timeOut, jsonSetting: jsonSetting);
            }, accessTokenOrAppKey));
        }
Пример #3
0
        /// <summary>
        /// 确认事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Accept_Click(object sender, EventArgs e)
        {
            bool IsOk = false;

            bpms_employee              = ControlBindHelper.GetWebControls <BPMS_Employee>(this.Page);
            bpms_employee.Enabled      = Enabled.Checked ? 1 : 0;
            bpms_employee.IsDimission  = IsDimission.Checked ? 1 : 0;
            bpms_employee.CompanyId    = hiddenCompanyId.Value;
            bpms_employee.DepartmentId = hiddenDepartmentId.Value;
            bpms_employee.WorkgroupId  = hiddenWorkgroupId.Value;
            bpms_employee.Spell        = PinyinHelper.PinyinString(bpms_employee.RealName);
            if (!string.IsNullOrEmpty(_key))//判断是否编辑
            {
                bpms_employee.EmployeeId     = _key;
                bpms_employee.ModifyDate     = DateTime.Now;
                bpms_employee.ModifyUserId   = RequestSession.GetSessionUser().UserId;
                bpms_employee.ModifyUserName = RequestSession.GetSessionUser().UserName;
                IsOk = bpms_employeeibll.Update(bpms_employee);
                if (IsOk)
                {
                    //保存成功后将数据同步到微信企业号
                    string[] tempDepart = new string[3] {
                        bpms_employee.CompanyId, bpms_employee.DepartmentId, bpms_employee.WorkgroupId
                    };
                    Extattr extattr = new Extattr();
                    extattr = null;
                    if (!myCommFun.UpdateMember(bpms_employee.Code, bpms_employee.RealName, toDepartmentId(tempDepart), toPosition(bpms_employee.DutyId), bpms_employee.Mobile, toGender(bpms_employee.Gender), bpms_employee.Email, bpms_employee.WeixinId, Convert.ToInt32(bpms_employee.Enabled), bpms_employee.headpic, extattr))
                    {
                        ShowMsgHelper.AlertCallback(MessageHelper.MSG0032);
                    }
                    ShowMsgHelper.AlertParmCallback(MessageHelper.MSG0006);
                }
            }
            else
            {
                bpms_employee.EmployeeId     = CommonHelper.GetGuid;
                bpms_employee.CreateUserId   = RequestSession.GetSessionUser().UserId;
                bpms_employee.CreateUserName = RequestSession.GetSessionUser().UserName;
                IsOk = bpms_employeeibll.Insert(bpms_employee);
                if (IsOk)
                {
                    //保存成功后将数据同步到微信企业号
                    string[] tempDepart = new string[3] {
                        bpms_employee.CompanyId, bpms_employee.DepartmentId, bpms_employee.WorkgroupId
                    };
                    Extattr extattr = new Extattr();
                    extattr = null;
                    if (!myCommFun.CreateMember(bpms_employee.Code, bpms_employee.RealName, toDepartmentId(tempDepart), toPosition(bpms_employee.DutyId), bpms_employee.Mobile, toGender(bpms_employee.Gender), bpms_employee.Email, bpms_employee.WeixinId, bpms_employee.headpic, extattr))
                    {
                        ShowMsgHelper.AlertCallback(MessageHelper.MSG0032);
                    }
                    ShowMsgHelper.AlertParmCallback(MessageHelper.MSG0005);
                }
            }
            if (!IsOk)
            {
                ShowMsgHelper.Alert_Error(MessageHelper.MSG0022);
            }
        }
Пример #4
0
 public void CreateMemberTest(string userId)
 {
     Extattr extattr = new Extattr()
     {
         attrs = new List<Attr>()
                 {
                     new Attr(){ name = "员工角色",value = "123"}
                 }
     };
     var accessToken = AccessTokenContainer.GetToken(_corpId);
     var result = MailListApi.CreateMember(accessToken, userId, "ceshi", new[] { 2 }, null, "18913536683", null, null, null, extattr);
     Assert.IsNotNull(result);
     Assert.IsTrue(result.errcode == ReturnCode_QY.请求成功);
 }
Пример #5
0
        public void CreateMemberTest(string userId)
        {
            Extattr extattr = new Extattr()
            {
                attrs = new List <Attr>()
                {
                    new Attr()
                    {
                        name = "员工角色", value = "123"
                    }
                }
            };
            var accessToken = AccessTokenContainer.GetToken(_corpId, base._corpSecret);
            var result      = MailListApi.CreateMember(accessToken, userId, string.Format("单元测试生成-{0}", DateTime.Now.ToString("yyMMdd-HH:mm")), "13900000000", "english name", new long[] { 2 }, null, "1", null, null, null, extattr: extattr);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.errcode == ReturnCode_Work.请求成功);
        }
Пример #6
0
        public void CreateMemberTest(string userId)
        {
            Extattr extattr = new Extattr()
            {
                attrs = new List <Attr>()
                {
                    new Attr()
                    {
                        name = "员工角色", value = "123"
                    }
                }
            };
            var accessToken = AccessTokenContainer.GetToken(_corpId, base._corpSecret);
            var result      = MailListApi.CreateMember(accessToken, userId, "ceshi", new[] { 2 }, null, "18913536683", null, null, null, extattr);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.errcode == ReturnCode_QY.请求成功);
        }
Пример #7
0
        ///// <param name="tel">办公电话。长度为0~64个字符</param>
        ///// <param name="gender">性别。gender=0表示男,=1表示女。默认gender=0</param>
        /// <summary>
        /// 更新成员(mobile/weixinid/email三者不能同时为空)
        /// </summary>
        /// <param name="accessToken">调用接口凭证</param>
        /// <param name="userId">员工UserID。必须企业内唯一</param>
        /// <param name="name">成员名称。长度为1~64个字符</param>
        /// <param name="department">成员所属部门id列表。注意,每个部门的直属员工上限为1000个</param>
        /// <param name="position">职位信息。长度为0~64个字符</param>
        /// <param name="mobile">手机号码。必须企业内唯一</param>
        /// <param name="email">邮箱。长度为0~64个字符。必须企业内唯一</param>
        /// <param name="weixinId">微信号。必须企业内唯一</param>
        /// <param name="enable">启用/禁用成员。1表示启用成员,0表示禁用成员</param>
        /// <param name="avatarMediaid"></param>
        /// <param name="extattr">扩展属性。扩展属性需要在WEB管理端创建后才生效,否则忽略未知属性的赋值</param>
        /// <param name="timeOut">代理请求超时时间(毫秒)</param>
        /// accessToken和userId为必须的参数,其余参数不是必须的,可以传入null
        /// <returns></returns>
        public static QyJsonResult UpdateMember(string accessToken, string userId, string name = null, int[] department = null, string position = null,
            string mobile = null, string email = null, string weixinId = null, int enable = 1, /*string tel = null,
            int gender = 0,*/string avatarMediaid = null, Extattr extattr = null, int timeOut = Config.TIME_OUT)
        {
            var url = "https://qyapi.weixin.qq.com/cgi-bin/user/update?access_token={0}";

            var data = new
            {
                userid = userId,
                name = name,
                department = department,
                position = position,
                mobile = mobile,

                //最新的接口中去除了以下两个字段
                //gender = gender,
                //tel = tel,

                email = email,
                weixinid = weixinId,
                enable = enable,
                avatar_mediaid = avatarMediaid,
                extattr = extattr
            };

            return CommonJsonSend.Send<QyJsonResult>(accessToken, url, data, CommonJsonSendType.POST, timeOut);
        }
Пример #8
0
        /// <summary>
        /// 更新人员
        /// </summary>
        /// <param name="_userId">成员UserID。对应管理端的帐号,企业内必须唯一。长度为1~64个字节</param>
        /// <param name="_name">成员名称。长度为1~64个字节</param>
        /// <param name="_departmnet">成员所属部门id列表 [1, 2],</param>
        /// <param name="_position">职位信息。长度为0~64个字节</param>
        /// <param name="_mobile">手机号码。企业内必须唯一,mobile/weixinid/email三者不能同时为空</param>
        /// <param name="_gender">性别。1表示男性,2表示女性</param>
        /// <param name="_email">邮箱。长度为0~64个字节。企业内必须唯一</param>
        /// <param name="_weixinid">微信号。企业内必须唯一。(注意:是微信号,不是微信的名字)</param>
        /// <param name="_enable">启用/禁用成员。1表示启用成员,0表示禁用成员</param>
        /// <param name="_avatar_mediaid">成员头像的mediaid,通过多媒体接口上传图片获得的mediaid</param>
        /// <param name="_extattr">扩展属性。扩展属性需要在WEB管理端创建后才生效,否则忽略未知属性的赋值</param>
        /// <returns></returns>
        public static bool UpdateMember(string _userId, string _name, int[] _departmnet, string _position, string _mobile, string _gender, string _email, string _weixinid, int _enable, string _avatar_mediaid, Extattr _extattr)
        {
            AccessTokenResult access_token_result = new AccessTokenResult();
            QYConfigInfo      config = GetQYConfig();

            access_token_result = CommonApi.GetToken(config.QYCorpId, config.QYSecret);
            //调用接口
            var result = MailListApi.UpdateMember(access_token_result.access_token, _userId, _name, _departmnet, _position, _mobile, _email, _weixinid, _enable, _avatar_mediaid, _extattr);

            if (result.errmsg == "updated")
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #9
0
        /// <summary>
        /// 更新成员
        /// </summary>
        /// <param name="QyID">企业ID</param>
        /// <param name="userId">员工UserID。必须企业内唯一</param>
        /// <param name="name">成员名称。长度为1~64个字符</param>
        /// <param name="department">成员所属部门id列表。注意,每个部门的直属员工上限为1000个</param>
        /// <param name="position">职位信息。长度为0~64个字符</param>
        /// <param name="mobile">手机号码。必须企业内唯一</param>
        /// <param name="tel">办公电话。长度为0~64个字符</param>
        /// <param name="email">邮箱。长度为0~64个字符。必须企业内唯一</param>
        /// <param name="weixinId">微信号。必须企业内唯一</param>
        /// <returns></returns>
        public QyJsonResult UpdateUser(string QyID, string userId, string name, int[] department = null,
                                       string position = null, string mobile     = null, string email    = null, string weixinId = null, int enable = 1, string tel = null,
                                       int gender      = 0, string avatarMediaid = null, Extattr extattr = null)
        {
            QyJsonResult result = null;

            try
            {
                result = MailListApi.UpdateMember(GetAccessToken(QyID), userId, name, department, position, mobile, email, weixinId, enable, tel, gender, avatarMediaid, extattr);
            }
            catch (Exception ex)
            {
                LogWriter.Error(ex, string.Format("更新QyID为{0}的成员失败", QyID));
                result = MailListApi.UpdateMember(GetAccessToken(QyID, true), userId, name, department, position, mobile, email, weixinId, enable, tel, gender, avatarMediaid, extattr);
            }
            if (result.errcode != ReturnCode_QY.请求成功)
            {
                LogWriter.Info(string.Format("更新QyID为{0}的成员失败,原因:{1}", QyID, result.errmsg));
            }
            return(result);
        }
Пример #10
0
        ///// <param name="tel">办公电话。长度为0~64个字符</param>
        /// <summary>
        /// 更新成员(mobile/weixinid/email三者不能同时为空)
        /// </summary>
        /// <param name="userId">员工UserID。必须企业内唯一</param>
        /// <param name="name">成员名称。长度为1~64个字符</param>
        /// <param name="department">成员所属部门id列表。注意,每个部门的直属员工上限为1000个</param>
        /// <param name="position">职位信息。长度为0~64个字符</param>
        /// <param name="mobile">手机号码。必须企业内唯一</param>
        /// <param name="email">邮箱。长度为0~64个字符。必须企业内唯一</param>
        /// <param name="weixinId">微信号。必须企业内唯一</param>
        /// <param name="enable">启用/禁用成员。1表示启用成员,0表示禁用成员</param>
        /// <param name="gender">性别。gender=0表示男,=1表示女。默认gender=0</param>
        /// <param name="avatarMediaid"></param>
        /// <param name="extattr">扩展属性。扩展属性需要在WEB管理端创建后才生效,否则忽略未知属性的赋值</param>
        /// <param name="timeOut">代理请求超时时间(毫秒)</param>
        /// accessToken和userId为必须的参数,其余参数不是必须的,可以传入null
        /// <returns></returns>
        public JsonResult UpdateMember(string userId, string name = null, int[] department = null, string position = null,
                                       string mobile = null, string email      = null, string weixinId = null, int enable  = 1, /*string tel = null,*/
                                       int gender    = 0, string avatarMediaid = null, Extattr extattr = null, int timeOut = Config.TIME_OUT)
        {
            var accessToken = _api.GetAccessToken();


            var url = "https://qyapi.weixin.qq.com/cgi-bin/user/update?access_token={0}";

            var data = new
            {
                userid     = userId,
                name       = name,
                department = department,
                position   = position,
                mobile     = mobile,

                //最新的接口中去除了以下两个字段
                gender = gender,
                //tel = tel,

                email          = email,
                weixinid       = weixinId,
                enable         = enable,
                avatar_mediaid = avatarMediaid,
                extattr        = extattr
            };

            return(Post <JsonResult>(url, data, timeOut));
        }
Пример #11
0
        ///// <param name="tel">办公电话。长度为0~64个字符</param>
        ///// <param name="gender">性别。gender=0表示男,=1表示女。默认gender=0</param>
        /// <summary>
        /// 【异步方法】更新成员(mobile/weixinid/email三者不能同时为空)
        /// </summary>
        /// <param name="accessToken">调用接口凭证</param>
        /// <param name="userId">员工UserID。必须企业内唯一</param>
        /// <param name="name">成员名称。长度为1~64个字符</param>
        /// <param name="department">成员所属部门id列表。注意,每个部门的直属员工上限为1000个</param>
        /// <param name="position">职位信息。长度为0~64个字符</param>
        /// <param name="mobile">手机号码。必须企业内唯一</param>
        /// <param name="email">邮箱。长度为0~64个字符。必须企业内唯一</param>
        /// <param name="weixinId">微信号。必须企业内唯一</param>
        /// <param name="enable">启用/禁用成员。1表示启用成员,0表示禁用成员</param>
        /// <param name="avatarMediaid"></param>
        /// <param name="extattr">扩展属性。扩展属性需要在WEB管理端创建后才生效,否则忽略未知属性的赋值</param>
        /// <param name="timeOut">代理请求超时时间(毫秒)</param>
        /// accessToken和userId为必须的参数,其余参数不是必须的,可以传入null
        /// <returns></returns>
        public static async Task <QyJsonResult> UpdateMemberAsync(string accessToken, string userId, string name = null, int[] department = null, string position = null,
                                                                  string mobile = null, string email = null, string weixinId = null, int enable = 1, /*string tel = null,
                                                                                                                                                      * int gender = 0,*/string avatarMediaid = null, Extattr extattr = null, int timeOut = Config.TIME_OUT)
        {
            var url = "https://qyapi.weixin.qq.com/cgi-bin/user/update?access_token={0}";

            var data = new
            {
                userid = userId, name, department, position, mobile,

                //最新的接口中去除了以下两个字段
                //gender = gender,
                //tel = tel,

                email,
                weixinid       = weixinId, enable,
                avatar_mediaid = avatarMediaid, extattr
            };

            return(await Core.CommonAPIs.CommonJsonSend.SendAsync <QyJsonResult>(accessToken, url, data, CommonJsonSendType.POST, timeOut));
        }
Пример #12
0
        /// <summary>
        /// 创建成员(mobile/weixinid/email三者不能同时为空)
        /// </summary>
        /// <param name="accessToken">调用接口凭证</param>
        /// <param name="userId">员工UserID。必须企业内唯一</param>
        /// <param name="name">成员名称。长度为1~64个字符</param>
        /// <param name="department">成员所属部门id列表。注意,每个部门的直属员工上限为1000个</param>
        /// <param name="position">职位信息。长度为0~64个字符</param>
        /// <param name="mobile">手机号码。必须企业内唯一</param>
        /// <param name="tel">办公电话。长度为0~64个字符</param>
        /// <param name="email">邮箱。长度为0~64个字符。必须企业内唯一</param>
        /// <param name="weixinId">微信号。必须企业内唯一</param>
        /// <param name="gender">性别。gender=0表示男,=1表示女。默认gender=0</param>
        /// <param name="avatarMediaid"></param>
        /// <param name="extattr">扩展属性。扩展属性需要在WEB管理端创建后才生效,否则忽略未知属性的赋值</param>
        /// <param name="timeOut">代理请求超时时间(毫秒)</param>
        /// accessToken、userId和name为必须的参数,其余参数不是必须的,可以传入null
        /// <returns></returns>
        public static QyJsonResult CreateMember(string accessToken, string userId, string name, int[] department = null,
                                                string position = null, string mobile = null, string email = null, string weixinId = null, /*string tel = null,
                                                                                                                                            * int gender = 0,*/string avatarMediaid = null, Extattr extattr = null, int timeOut = Config.TIME_OUT)
        {
            var url = "https://qyapi.weixin.qq.com/cgi-bin/user/create?access_token={0}";

            var data = new
            {
                userid     = userId,
                name       = name,
                department = department,
                position   = position,
                mobile     = mobile,

                //最新的接口中去除了以下两个字段
                //gender = gender,
                //tel = tel,

                email          = email,
                weixinid       = weixinId,
                avatar_mediaid = avatarMediaid,
                extattr        = extattr,
                to_invite      = false
            };

            return(CommonJsonSend.Send <QyJsonResult>(accessToken, url, data, CommonJsonSendType.POST, timeOut));
        }