コード例 #1
0
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="corpid">公司ID</param>
        /// <param name="secret">密匙</param>
        /// <param name="json">要发送的JSON数据包</param>
        /// <returns>返回一个JSON包</returns>
        public string SendMsg(string corpid, string secret, string json)
        {
            //先获取到access_token
            string accessToken = Get_access_token.GetAccessToken(corpid, secret);

            string urlFormat = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={0}";
            var    url       = string.Format(urlFormat, accessToken);

            string str_json = HttpRequestUtil.RequestUrlSendMsg(url, "POST", json);

            return(str_json);
        }
コード例 #2
0
        /// <summary>
        /// 先获取到access_token 然后使用access_token和传递进来的code去获取用户信息
        /// </summary>
        /// <param name="corpid">企业ID</param>
        /// <param name="secret">应用的凭证密钥</param>
        /// <param name="code">Code</param>
        /// <returns></returns>
        public static string GetUserinfo(string corpid, string secret, string code)
        {
            //先获取到access_token
            string str_token = Get_access_token.GetAccessToken(corpid, secret);

            //使用access_token和code去获取用户信息 返回一个Model对象
            string strJson = string.Empty;

            strJson = HttpRequestUtil.RequestUrl(string.Format("https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token={0}&code={1}", str_token, code));
            //反序列化json,把json串序列化成model包,使用了json.net工具包。
            Userinfo userinfo = JsonConvert.DeserializeObject <Userinfo>(strJson);

            if (userinfo.errcode == 0)
            {
                return(strJson);
            }
            else
            {
                return(userinfo.errmsg);
            }
        }