Пример #1
0
        public MenuCreateResponse Create <T>(T request)
        {
            string strJson = JsonConvert.SerializeObject(request);

            //throw new Exception(strJson);
            //_SendLog.WriteLog("new: " + strJson);
            base.url             = "https://qyapi.weixin.qq.com/cgi-bin/menu/create?agentid=5&access_token=" + TokenBiz.GetAccessToken(str_corpid, str_corpsecret);
            base.para            = strJson;
            base.method          = "POST";
            base.needAccessToken = true;
            return(base.GetUrlReturn <MenuCreateResponse>());
        }
Пример #2
0
 /// <summary>
 /// 通过media_id删除上传的图文消息、图片、语音、文件、视频素材。
 /// </summary>
 /// <param name="media_id"></param>
 public void DelMateria(string media_id)
 {
     base.url             = "https://qyapi.weixin.qq.com/cgi-bin/material/del";
     base.para            = "agentid=5&media_id=" + media_id + "&access_token=" + TokenBiz.GetAccessToken(str_corpid, str_corpsecret);
     base.method          = "GET";
     base.needAccessToken = true;
     base.GetUrlReturn <Object>();
 }
Пример #3
0
        /// <summary>
        /// 上传临时素材文件
        /// </summary>
        /// <param name="filepath"></param>
        /// <param name="token"></param>
        /// <param name="mt"></param>
        /// <returns></returns>
        public UploadResponse Upload(string filepath, string token, EnumMediaType mt)
        {
            using (WebClient client = new WebClient())
            {
                string retdata = string.Empty;

                var cacheValue = CacheHelper.GetCache("file" + filepath);
                if (cacheValue != null)
                {
                    retdata = CacheHelper.GetCache("file" + filepath).ToString();
                }

                if (string.IsNullOrEmpty(retdata))
                {
                    byte[] b = client.UploadFile(string.Format("https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token={0}&type={1}", token, mt.ToString()), filepath); //调用接口上传文件
                    retdata = Encoding.Default.GetString(b);                                                                                                                   //获取返回值
                }
                if (retdata.Contains("40001"))
                {
                    CacheHelper.RemoveAllCache("file" + filepath);
                    CacheHelper.RemoveAllCache("AccessToken" + str_corpid);                                                                                                                                                  //过期移除缓存,这样会重新去请求获取token
                    byte[] b = client.UploadFile(string.Format("https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token={0}&type={1}", TokenBiz.GetAccessToken(str_corpid, str_corpsecret), mt.ToString()), filepath); //调用接口上传文件
                    retdata = Encoding.Default.GetString(b);                                                                                                                                                                 //获取返回值
                }

                if (retdata.Contains("media_id"))//判断返回值是否包含media_id,包含则说明上传成功,然后将返回的json字符串转换成json
                {
                    CacheHelper.SetCache("file" + filepath, retdata, new TimeSpan(8, 0, 0));
                    return(JsonConvert.DeserializeObject <UploadResponse>(retdata));
                }
                else
                {  //否则,写错误日志
                    _SendLog.WriteLog(retdata);
                    return(null);
                }
            }
        }
Пример #4
0
        /// <summary>
        /// 获取应用素材素材列表
        /// </summary>
        /// <returns></returns>
        public BatchgetResponse GetBatchgetResponse(BatchgetRequest bRequest)
        {
            string strJson = JsonConvert.SerializeObject(bRequest);

            base.url             = "https://qyapi.weixin.qq.com/cgi-bin/material/batchget?access_token=" + TokenBiz.GetAccessToken(str_corpid, str_corpsecret);
            base.para            = strJson;
            base.method          = "POST";
            base.needAccessToken = true;
            var res = base.GetUrlReturn <BatchgetResponse>();

            return(res);
        }
Пример #5
0
        public SendResponse Send <T>(T request)
        {
            string strJson = JsonConvert.SerializeObject(request);

            //_SendLog.WriteLog("new: " + strJson);
            base.url             = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + TokenBiz.GetAccessToken(str_corpid, str_corpsecret);
            base.para            = strJson;
            base.method          = "POST";
            base.needAccessToken = true;
            var res = base.GetUrlReturn <SendResponse>();

            return(res);
        }