Example #1
0
        /// <summary>
        /// 创建临时二维码
        /// </summary>
        public async Task <WcReply <WcQrcode> > Create(WcAccessToken token, int sceneId)
        {
            string url = string.Format(URL_QRCODE_CREATE, token.Token);
            var    obj = new
            {
                action_name = "QR_LIMIT_SCENE",
                action_info = new
                {
                    scene = new
                    {
                        scene_id = sceneId
                    }
                }
            };
            var res = await HttpHelper.HttpPostAsync(url, JsonConvert.SerializeObject(obj));

            if (res.IndexOf("errcode") >= 0)
            {
                WcReply <WcQrcode> error = JsonConvert.DeserializeObject <WcReply <WcQrcode> >(res);
                _logger.LogError(error.ToString());
                return(error);
            }
            WcQrcode data = JsonConvert.DeserializeObject <WcQrcode>(res);

            return(new WcReply <WcQrcode>
            {
                Data = data,
                ErrCode = 0
            });
        }
Example #2
0
        /// <summary>
        /// 更新用户标签
        /// </summary>
        public async Task <WcReply <string> > UpdateUserTag(WcAccessToken token, int tagId, string name)
        {
            string url = string.Format(URL_TAG_UPDATE, token.Token);
            var    res = await HttpHelper.HttpPostAsync(url, "{\"tag\":{\"id\":" + tagId + ", \"name\":\"" + name + "\"}}");

            WcReply <string> rsp = JsonConvert.DeserializeObject <WcReply <string> >(res);

            if (rsp.ErrCode != 0)
            {
                _logger.LogError(rsp.ToString());
            }
            return(rsp);
        }
Example #3
0
        /// <summary>
        /// 更新用户备注名
        /// </summary>
        public async Task <WcReply <string> > UpdateUserRemark(WcAccessToken token, string openid, string remark)
        {
            string url = string.Format(URL_USER_REMARK_UPDATE, token.Token);
            var    res = await HttpHelper.HttpPostAsync(url, "{\"openid\":\"" + openid + "\", \"remark\":\"" + remark + "\"}");

            WcReply <string> rsp = JsonConvert.DeserializeObject <WcReply <string> >(res);

            if (rsp.ErrCode != 0)
            {
                _logger.LogError(rsp.ToString());
            }
            return(rsp);
        }
Example #4
0
        /// <summary>
        /// 取得用户标签列表
        /// </summary>
        public async Task <WcReply <WcUserTagListRsp> > GetUserTagListAsync(WcAccessToken token)
        {
            var res = await HttpHelper.HttpGetAsync(string.Format(URL_TAGS_GET, token.Token));

            if (res.IndexOf("errcode") >= 0)
            {
                WcReply <WcUserTagListRsp> error = JsonConvert.DeserializeObject <WcReply <WcUserTagListRsp> >(res);
                _logger.LogError(error.ToString());
                return(error);
            }

            WcUserTagListRsp data = JsonConvert.DeserializeObject <WcUserTagListRsp>(res);

            return(new WcReply <WcUserTagListRsp>
            {
                Data = data,
                ErrCode = 0
            });
        }
Example #5
0
        /// <summary>
        /// 取得微信用户信息
        /// </summary>
        public async Task <WcReply <WcUserDetailRsp> > GetUserDetailAsync(WcAccessToken token, string openId)
        {
            var res = await HttpHelper.HttpGetAsync(string.Format(URL_USERS_DETAIL, token.Token, openId));

            if (res.IndexOf("errcode") >= 0)
            {
                WcReply <WcUserDetailRsp> error = JsonConvert.DeserializeObject <WcReply <WcUserDetailRsp> >(res);
                _logger.LogError(error.ToString());
                return(error);
            }

            WcUserDetailRsp data = JsonConvert.DeserializeObject <WcUserDetailRsp>(res);

            return(new WcReply <WcUserDetailRsp>
            {
                Data = data,
                ErrCode = 0
            });
        }
Example #6
0
        /// <summary>
        /// 创建用户标签
        /// </summary>
        public async Task <WcReply <WcUserTagCreateRsp> > CreateUserTag(WcAccessToken token, string name)
        {
            string url = string.Format(URL_TAG_CREATE, token.Token);
            var    res = await HttpHelper.HttpPostAsync(url, "{\"tag\":{\"name\":\"" + name + "\"}}");

            if (res.IndexOf("errcode") >= 0)
            {
                WcReply <WcUserTagCreateRsp> error = JsonConvert.DeserializeObject <WcReply <WcUserTagCreateRsp> >(res);
                _logger.LogError(error.ToString());
                return(error);
            }

            WcUserTagCreateRsp data = JsonConvert.DeserializeObject <WcUserTagCreateRsp>(res);

            return(new WcReply <WcUserTagCreateRsp>
            {
                Data = data,
                ErrCode = 0
            });
        }
Example #7
0
        /// <summary>
        /// 刷新微信AccessToken
        /// </summary>
        /// <param name="appId">AppId</param>
        /// <param name="appSecret">AppSecret</param>
        /// <returns>WxAccessToken</returns>
        public async Task <WcReply <WcAccessToken> > RefreshAsync(string appId, string appSecret)
        {
            var res = await HttpHelper.HttpGetAsync(string.Format(URL_GET_TOKEN, appId, appSecret));

            if (res.IndexOf("errcode") >= 0)
            {
                WcReply <WcAccessToken> error = JsonConvert.DeserializeObject <WcReply <WcAccessToken> >(res);
                _logger.LogError(error.ToString());
                return(error);
            }

            WcAccessToken token = JsonConvert.DeserializeObject <WcAccessToken>(res);

            token.Time = DateTime.Now.AddSeconds(token.ExpiresIn - 600); //600秒做缓冲时间

            //保存到缓存
            await cacheService.SetAsync(string.Format(CACHE_ACCESSTOKEN, appId), token, new TimeSpan((token.ExpiresIn - 600) * (long)10_000_000));

            return(new WcReply <WcAccessToken>
            {
                Data = token,
                ErrCode = 0
            });
        }