Esempio n. 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();
            UploadMediaRequest request  = new UploadMediaRequest()
            {
                AccessToken = accessToken,
                Type        = "video",
                FileName    = videoPath
            };

            UploadMediaResponse response = mpClient.Execute(request);

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

            return(SendCustomMessage(accessToken, msg));
        }
Esempio n. 2
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();
            UploadMediaRequest request  = new UploadMediaRequest()
            {
                AccessToken = accessToken,
                Type        = "voice",
                FileName    = voicePath
            };

            UploadMediaResponse response = mpClient.Execute(request);

            if (response.IsError)
            {
                return(false);
            }
            else
            {
                VoiceReplyMessage msg = new VoiceReplyMessage()
                {
                    CreateTime   = WeiXin.Util.Tools.ConvertDateTimeInt(DateTime.Now),
                    FromUserName = fromUserName,
                    ToUserName   = toUserName,
                    MediaId      = response.MediaId
                };
                System.Web.HttpContext.Current.Response.Write(msg.ToXmlString());
                return(true);
            }
        }
Esempio n. 3
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();
            UploadMediaRequest request  = new UploadMediaRequest()
            {
                AccessToken = accessToken,
                Type        = "image",
                FileName    = imgPath
            };

            UploadMediaResponse response = mpClient.Execute(request);

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

            return(SendCustomMessage(accessToken, msg));
        }
Esempio n. 4
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();
            UploadMediaRequest request  = new UploadMediaRequest()
            {
                AccessToken = accessToken,
                Type        = "thumb",
                FileName    = thumbMediaFilePath
            };

            UploadMediaResponse response = mpClient.Execute(request);

            if (response.IsError)
            {
                return(false);
            }
            else
            {
                MusicReplyMessage msg = new MusicReplyMessage()
                {
                    CreateTime   = WeiXin.Util.Tools.ConvertDateTimeInt(DateTime.Now),
                    FromUserName = fromUserName,
                    ToUserName   = toUserName,
                    Description  = description,
                    Title        = title,
                    ThumbMediaId = response.MediaId,
                    HQMusicUrl   = hqMusicUrl,
                    MusicURL     = musicUrl
                };
                System.Web.HttpContext.Current.Response.Write(msg.ToXmlString());
                return(true);
            }
        }
Esempio n. 5
0
        public static UploadImgResponse UploadImg(string accessToken, string imgPath)
        {
            IMpClient        mpClient = new MpClient();
            UploadImgRequest request  = new UploadImgRequest()
            {
                AccessToken = accessToken,
                FileName    = imgPath,
                Type        = "image"
            };
            UploadImgResponse response = mpClient.Execute(request);

            return(response);
        }
Esempio n. 6
0
        public static SendCustomMessageResponse SendCustomMessage(string accessToken, string sendData)
        {
            IMpClient mpClient = new MpClient();
            SendCustomMessageRequest request = new SendCustomMessageRequest()
            {
                AccessToken = accessToken,
                SendData    = sendData
            };
            SendCustomMessageResponse response = mpClient.Execute(request);

            if (response.IsError)
            {
                Utility.LogHelper.WriteDebug("发送客服消息", sendData);
                Utility.LogHelper.WriteDebug("客服消息响应", response.Body);
            }
            return(response);
        }
Esempio n. 7
0
        /// <summary>
        /// 获取模板列表
        /// </summary>
        /// <param name="accessToken"></param>
        /// <returns></returns>
        public static GetTemplateInfo GetTemplateInfo(string accessToken)
        {
            IMpClient mpClient = new MpClient();

            Request.TemPlateMessage request = new Request.TemPlateMessage()
            {
                Method      = "GET",
                AccessToken = accessToken,
                ReqUrl      = "https://api.weixin.qq.com/cgi-bin/template/get_all_private_template?access_token={0}",
            };
            TemPlateMessageResponse response = mpClient.Execute(request);

            if (response.IsError)
            {
                Utility.LogHelper.WriteDebug("获取模板列表响应", response.Body);
            }
            return(response.TemplateInfo);
        }
Esempio n. 8
0
        /// <summary>
        /// 发送模板消息
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static TemPlateMessageResponse SendTemPlateMessageOperate(string accessToken, SendTemPlateMessage msg)
        {
            IMpClient mpClient = new MpClient();

            Request.TemPlateMessage request = new Request.TemPlateMessage()
            {
                Method      = "POST",
                AccessToken = accessToken,
                ReqUrl      = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={0}",
                SendData    = msg.ToJsonString()
            };
            //LogHelper.WriteInfo("template_msg: ", msg.ToJsonString());
            TemPlateMessageResponse response = mpClient.Execute(request);

            if (response.IsError)
            {
                LogHelper.WriteDebug("发送模板消息响应", response.Body);
            }
            return(response);
        }
Esempio n. 9
0
        /// <summary>
        /// 删除模板
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static TemPlateMessageResponse DeleteTemPlate(string accessToken, DeleteTemPlate msg)
        {
            IMpClient mpClient = new MpClient();

            Request.TemPlateMessage request = new Request.TemPlateMessage()
            {
                Method      = "POST",
                AccessToken = accessToken,
                ReqUrl      = "https://api.weixin.qq.com/cgi-bin/template/del_private_template?access_token={0}",
                SendData    = msg.ToJsonString()
            };
            TemPlateMessageResponse response = mpClient.Execute(request);

            if (response.IsError)
            {
                Utility.LogHelper.WriteDebug("删除模板", request.SendData);
                Utility.LogHelper.WriteDebug("删除模板响应", response.Body);
            }
            return(response);
        }
Esempio n. 10
0
        /// <summary>
        /// 设置所属行业
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static TemPlateMessageResponse SetIndustry(string accessToken, SetIndustry msg)
        {
            IMpClient mpClient = new MpClient();

            Request.TemPlateMessage request = new Request.TemPlateMessage()
            {
                Method      = "POST",
                AccessToken = accessToken,
                ReqUrl      = "https://api.weixin.qq.com/cgi-bin/template/api_set_industry?access_token={0}",
                SendData    = msg.ToJsonString()
            };
            TemPlateMessageResponse response = mpClient.Execute(request);

            if (response.IsError)
            {
                Utility.LogHelper.WriteDebug("模板消息设置所属行业", request.SendData);
                Utility.LogHelper.WriteDebug("模板消息设置所属行业响应", response.Body);
            }
            return(response);
        }
Esempio n. 11
0
        /// <summary>
        /// 发送音乐客服信息
        /// </summary>
        /// <param name="accessToken">调用凭据</param>
        /// <param name="toUser">接收方</param>
        /// <param name="title">音乐标题</param>
        /// <param name="description">音乐描述</param>
        /// <param name="musicUrl">音乐地址</param>
        /// <param name="hqMusicUrl">高质量音乐地址</param>
        /// <param name="thumbMediaFilePath">音乐缩略图路径</param>
        /// <returns></returns>
        public static SendCustomMessageResponse SendMusicCustomMessage(string accessToken, string toUser, string title, string description, string musicUrl, string hqMusicUrl, string thumbMediaFilePath)
        {
            IMpClient          mpClient = new MpClient();
            UploadMediaRequest request  = new UploadMediaRequest()
            {
                AccessToken = accessToken,
                Type        = "thumb",
                FileName    = thumbMediaFilePath
            };

            UploadMediaResponse response = mpClient.Execute(request);

            if (response.IsError)
            {
                SendCustomMessageResponse response2 = new SendCustomMessageResponse()
                {
                    Body    = response.Body,
                    ErrInfo = response.ErrInfo,
                    ReqUrl  = response.ReqUrl
                };
                return(response2);
            }
            MusicCustomMessage msg = new MusicCustomMessage()
            {
                AccessToken  = accessToken,
                ThumbMediaId = response.MediaId,
                HqMusicUrl   = hqMusicUrl,
                MusicUrl     = musicUrl,
                MsgType      = "music",
                ToUser       = toUser,
                Description  = description,
                Title        = title
            };

            return(SendCustomMessage(accessToken, msg));
        }
Esempio n. 12
0
        /// <summary>
        /// 创建会话
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="kf_account"></param>
        /// <param name="openid"></param>
        /// <returns></returns>
        public static CustomerServiceCreateResponse CreateCustomerService(string accessToken, string kf_account, string openid)
        {
            CustomerServiceCreate msg = new CustomerServiceCreate()
            {
                AccessToken = accessToken,
                kf_account  = kf_account,
                openid      = openid
            };
            IMpClient mpClient = new MpClient();
            string    sendData = msg.ToJsonString();
            CustomerServiceCreateRequest request = new CustomerServiceCreateRequest()
            {
                AccessToken = accessToken,
                SendData    = sendData
            };
            CustomerServiceCreateResponse response = mpClient.Execute(request);

            if (response.IsError)
            {
                Utility.LogHelper.WriteDebug("创建会话", sendData);
                Utility.LogHelper.WriteDebug("创建会话", response.Body);
            }
            return(response);
        }
Esempio n. 13
0
        /// <summary>
        /// 更新客服信息
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="kf_account"></param>
        /// <param name="nickname"></param>
        /// <returns></returns>
        public static CustomerServiceEditAccountResponse UpdateCustomerServiceAccount(string accessToken, string kf_account, string nickname)
        {
            CustomerServiceAccount msg = new CustomerServiceAccount()
            {
                AccessToken = accessToken,
                kf_account  = kf_account,
                nickname    = nickname
            };
            IMpClient mpClient = new MpClient();
            string    sendData = msg.ToJsonString();
            CustomerServiceEditAccountRequest request = new CustomerServiceEditAccountRequest()
            {
                AccessToken = accessToken,
                SendData    = sendData
            };
            CustomerServiceEditAccountResponse response = mpClient.Execute(request);

            if (response.IsError)
            {
                Utility.LogHelper.WriteDebug("更新客服", sendData);
                Utility.LogHelper.WriteDebug("更新客服", response.Body);
            }
            return(response);
        }