コード例 #1
0
        /// <summary>
        /// 发送视频客服信息
        /// </summary>
        /// <param name="accessToken">调用凭据</param>
        /// <param name="toUser">接收方</param>
        /// <param name="title">视频标题</param>
        /// <param name="description">视频描述</param>
        /// <param name="videoPath">视频文件路径</param>
        /// <returns></returns>
        public static SendCustomMessageResponse SendVideoCustomMessage(string accessToken, string toUser, string title, string description, string videoPath)
        {
            IMpClient mpClient = new MpClient();
            var       request  = new UploadMediaRequest()
            {
                AccessToken = accessToken,
                Type        = "video",
                FileName    = videoPath
            };

            var response = mpClient.Execute(request);

            if (response.IsError)
            {
                var response2 = new SendCustomMessageResponse()
                {
                    Body    = response.Body,
                    ErrInfo = response.ErrInfo,
                    ReqUrl  = response.ReqUrl
                };
                return(response2);
            }
            var msg = new VideoCustomMessage()
            {
                AccessToken = accessToken,
                MediaId     = response.MediaId,
                MsgType     = "video",
                ToUser      = toUser,
                Description = description,
                Title       = title
            };

            return(SendCustomMessage(accessToken, msg));
        }
コード例 #2
0
        /// <summary>
        /// 发送图片客服消息
        /// </summary>
        /// <param name="accessToken">调用凭据</param>
        /// <param name="toUser">接收方</param>
        /// <param name="imgPath">图片路径</param>
        /// <returns></returns>
        public static SendCustomMessageResponse SendImageCustomMessage(string accessToken, string toUser, string imgPath)
        {
            IMpClient mpClient = new MpClient();
            var       request  = new UploadMediaRequest()
            {
                AccessToken = accessToken,
                Type        = "image",
                FileName    = imgPath
            };

            var response = mpClient.Execute(request);

            if (response.IsError)
            {
                var response2 = new SendCustomMessageResponse()
                {
                    Body    = response.Body,
                    ErrInfo = response.ErrInfo,
                    ReqUrl  = response.ReqUrl
                };
                return(response2);
            }
            var msg = new ImageCustomMessage()
            {
                AccessToken = accessToken,
                MediaId     = response.MediaId,
                MsgType     = "image",
                ToUser      = toUser
            };

            return(SendCustomMessage(accessToken, msg));
        }
コード例 #3
0
        /// <summary>
        /// 发送被动响应音乐消息
        /// </summary>
        /// <param name="accessToken">调用接口凭证</param>
        /// <param name="fromUserName">发送方</param>
        /// <param name="toUserName">接收方</param>
        /// <param name="title">标题</param>
        /// <param name="description">描述</param>
        /// <param name="musicUrl">音乐链接</param>
        /// <param name="hqMusicUrl">高质量音乐链接</param>
        /// <param name="thumbMediaFilePath">缩略图文件路径(64KB,支持JPG格式 )</param>
        /// <returns>是否成功</returns>
        public static bool SendMusicReplyMessage(string accessToken, string fromUserName, string toUserName, string title, string description, string musicUrl, string hqMusicUrl, string thumbMediaFilePath)
        {
            IMpClient mpClient = new MpClient();
            var       request  = new UploadMediaRequest()
            {
                AccessToken = accessToken,
                Type        = "thumb",
                FileName    = thumbMediaFilePath
            };

            var response = mpClient.Execute(request);

            if (response.IsError)
            {
                return(false);
            }
            var msg = new MusicReplyMessage()
            {
                CreateTime   = Tools.ConvertDateTimeInt(DateTime.Now),
                FromUserName = fromUserName,
                ToUserName   = toUserName,
                Description  = description,
                Title        = title,
                ThumbMediaId = response.MediaId,
                HqMusicUrl   = hqMusicUrl,
                MusicUrl     = musicUrl
            };

            HttpContext.Current.Response.Write(msg.ToXmlString());
            return(true);
        }
コード例 #4
0
        /// <summary>
        /// 发送被动响应语音消息
        /// </summary>
        /// <param name="accessToken">调用接口凭证</param>
        /// <param name="fromUserName">发送方</param>
        /// <param name="toUserName">接收方</param>
        /// <param name="voicePath">语音文件路径(支持AMR\MP3,最大256K,播放长度不超过60s)</param>
        /// <returns>是否成功</returns>
        public static bool SendVoiceReplyMessage(string accessToken, string fromUserName, string toUserName, string voicePath)
        {
            IMpClient mpClient = new MpClient();
            var       request  = new UploadMediaRequest()
            {
                AccessToken = accessToken,
                Type        = "voice",
                FileName    = voicePath
            };

            var response = mpClient.Execute(request);

            if (response.IsError)
            {
                return(false);
            }
            var msg = new VoiceReplyMessage()
            {
                CreateTime   = Tools.ConvertDateTimeInt(DateTime.Now),
                FromUserName = fromUserName,
                ToUserName   = toUserName,
                MediaId      = response.MediaId
            };

            HttpContext.Current.Response.Write(msg.ToXmlString());
            return(true);
        }
コード例 #5
0
        /// <summary>
        /// 发送客服信息
        /// </summary>
        /// <param name="accessToken">调用凭据</param>
        /// <param name="msg">客服消息</param>
        /// <returns></returns>
        public static SendCustomMessageResponse SendCustomMessage(string accessToken, CustomMessage msg)
        {
            IMpClient mpClient = new MpClient();
            var       request  = new SendCustomMessageRequest
            {
                AccessToken = accessToken,
                SendData    = msg.ToJsonString()
            };
            var response = mpClient.Execute(request);

            return(response);
        }