Ejemplo n.º 1
0
        public static void DownloadFile(int channelId, string saveFilePath, string mediaId)
        {
            var configDto             = WeixinConfigHelper.GetWeixinConfigDTOAsync(channelId).Result;
            var weixinDownloadFileUrl = string.Format("https://qyapi.weixin.qq.com/cgi-bin/media/get?access_token={0}&media_id={1}", configDto.AccessToken, mediaId);

            using (var fileStream = File.Create(saveFilePath))
            {
                WeixinDownloadFile(weixinDownloadFileUrl, fileStream);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 企业号上传临时素材
        /// </summary>
        /// <param name="channelId"></param>
        /// <param name="fileType"></param>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static WeixinWorkFileUploadDTO UploadFile(int channelId, UploadMediaFileType fileType, string filePath)
        {
            var configDto = WeixinConfigHelper.GetWeixinConfigDTOAsync(channelId).Result;

            var weixinUploadUrl = string.Format("https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token={0}&type={1}", configDto.AccessToken, fileType.ToString());

            using (var fileStream = File.OpenRead(filePath))
            {
                var fileName = Path.GetFileName(filePath);
                var html     = WeixinUploadFile(weixinUploadUrl, fileName, fileStream);

                var result = html.FromJson <WeixinWorkFileUploadDTO>();
                return(result);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 校验渠道微信签名
        /// </summary>
        /// <param name="channelId">渠道id</param>
        /// <returns></returns>
        public ExecuteResult <Tuple <bool, string> > CheckChannelWeixinSign(int channelId, string msg_signature, string signature, string timestamp, string nonce, string echo)
        {
            var result = new ExecuteResult <Tuple <bool, string> >
            {
                ErrorCode = ExecuteResult.ErrorCodeEnum.Fail,
                Success   = false,
                ErrorMsg  = "校验渠道微信签名失败"
            };

            try
            {
                var checkResult = false;
                var replyEcho   = string.Empty;
                var configDto   = WeixinConfigHelper.GetWeixinConfigDTOAsync(channelId).Result;
                switch (configDto.WxType)
                {
                case Enums.WeixinType.WxMp:
                {
                    checkResult = SignHelper.CheckSignature(channelId, signature, timestamp, nonce, echo, out replyEcho);
                }
                break;

                case Enums.WeixinType.WxWork:
                default:
                {
                    checkResult = SignHelper.ValidateUrl(channelId, msg_signature, timestamp, nonce, echo, out replyEcho);
                }
                break;
                }
                result.Data      = new Tuple <bool, string>(checkResult, replyEcho);
                result.Success   = true;
                result.ErrorCode = ExecuteResult.ErrorCodeEnum.Success;
                result.ErrorMsg  = "校验渠道微信签名成功";
                return(result);
            }
            catch (Exception ex)
            {
                ex.WriteExceptionLog("校验渠道微信签名失败");
            }
            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取菜单
        /// </summary>
        /// <param name="channelId"></param>
        /// <param name="buttonData">菜单内容</param>
        /// <returns></returns>
        public static async Task <ResponseBaseDTO> DeleteMenuAsync(int channelId)
        {
            var configDto = await WeixinConfigHelper.GetWeixinConfigDTOAsync(channelId);

            var weixinDeleteMenuUrl = string.Empty;

            switch (configDto.WxType)
            {
            case Enums.WeixinType.WxMp:
                weixinDeleteMenuUrl = string.Format("https://api.weixin.qq.com/cgi-bin/menu/delete?access_token={0}", configDto.AccessToken);
                break;

            case Enums.WeixinType.WxWork:
            default:
                weixinDeleteMenuUrl = string.Format("https://qyapi.weixin.qq.com/cgi-bin/menu/delete?access_token={0}&agentid={1}", configDto.AccessToken, configDto.AgentId);
                break;
            }

            var result = await HttpHelper.GetHtmlAsync <ResponseBaseDTO>(weixinDeleteMenuUrl);

            return(result);
        }