Example #1
0
        /// <summary>
        /// 发送文本信息
        /// </summary>
        /// <param name="accessTokenOrAppId"></param>
        /// <param name="openId"></param>
        /// <param name="content"></param>
        /// <param name="timeOut">代理请求超时时间(毫秒)</param>
        /// <param name="kfAccount">客服</param>
        /// <returns></returns>
        public static WxJsonResult SendText(string accessTokenOrAppId, string openId, string content,
                                            int timeOut = Config.TIME_OUT, string kfAccount = "")
        {
            if (string.IsNullOrWhiteSpace(kfAccount))
            {
                return(CustomApi.SendText(accessTokenOrAppId, openId, content, timeOut));
            }


            return(ApiHandlerWapper.TryCommonApi(accessToken =>
            {
                var data = new
                {
                    touser = openId,
                    msgtype = "text",
                    text = new
                    {
                        content = content
                    },
                    customservice = new
                    {
                        kf_account = kfAccount
                    }
                };
                return CommonJsonSend.Send(accessToken, URL_FORMAT, data, timeOut: timeOut);
            }, accessTokenOrAppId));
        }
Example #2
0
 /// <summary>
 /// 【异步方法】发送图文消息
 /// </summary>
 /// <param name="accessTokenOrAppId"></param>
 /// <param name="openId"></param>
 /// <param name="articles"></param>
 /// <param name="timeOut">代理请求超时时间(毫秒)</param>
 /// <param name="kfAccount">客服</param>
 /// <returns></returns>
 public static async Task <WxJsonResult> SendNewsAsync(string accessTokenOrAppId, string openId, List <Article> articles, int timeOut = Config.TIME_OUT, string kfAccount = "")
 {
     if (string.IsNullOrWhiteSpace(kfAccount))
     {
         return(CustomApi.SendNews(accessTokenOrAppId, openId, articles, timeOut));
     }
     return(await ApiHandlerWapper.TryCommonApiAsync(accessToken =>
     {
         var data = new
         {
             touser = openId,
             msgtype = "news",
             news = new
             {
                 articles = articles.Select(z => new
                 {
                     title = z.Title,
                     description = z.Description,
                     url = z.Url,
                     picurl = z.PicUrl//图文消息的图片链接,支持JPG、PNG格式,较好的效果为大图640*320,小图80*80
                 }).ToList()
             },
             CustomService = new
             {
                 kf_account = kfAccount
             }
         };
         return Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync(accessToken, URL_FORMAT, data, timeOut: timeOut);
     }, accessTokenOrAppId));
 }
Example #3
0
 /// <summary>
 /// 【异步方法】发送音乐消息
 /// </summary>
 /// <param name="accessTokenOrAppId"></param>
 /// <param name="openId"></param>
 /// <param name="title">音乐标题(非必须)</param>
 /// <param name="description">音乐描述(非必须)</param>
 /// <param name="musicUrl">音乐链接</param>
 /// <param name="hqMusicUrl">高品质音乐链接,wifi环境优先使用该链接播放音乐</param>
 /// <param name="thumbMediaId">视频缩略图的媒体ID</param>
 /// <param name="timeOut">代理请求超时时间(毫秒)</param>
 /// <param name="kfAccount">客服</param>
 /// <returns></returns>
 public static async Task <WxJsonResult> SendMusicAsync(string accessTokenOrAppId, string openId, string title, string description,
                                                        string musicUrl, string hqMusicUrl, string thumbMediaId, int timeOut = Config.TIME_OUT, string kfAccount = "")
 {
     if (string.IsNullOrWhiteSpace(kfAccount))
     {
         return(CustomApi.SendMusic(accessTokenOrAppId, openId, title, description, musicUrl, hqMusicUrl,
                                    thumbMediaId, timeOut));
     }
     return(await ApiHandlerWapper.TryCommonApiAsync(accessToken =>
     {
         var data = new
         {
             touser = openId,
             msgtype = "music",
             music = new
             {
                 title = title,
                 description = description,
                 musicurl = musicUrl,
                 hqmusicurl = hqMusicUrl,
                 thumb_media_id = thumbMediaId
             },
             CustomService = new
             {
                 kf_account = kfAccount
             }
         };
         return Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync(accessToken, URL_FORMAT, data, timeOut: timeOut);
     }, accessTokenOrAppId));
 }
Example #4
0
        /// <summary>
        /// 【异步方法】发送文本信息
        /// </summary>
        /// <param name="accessTokenOrAppId"></param>
        /// <param name="openId"></param>
        /// <param name="content"></param>
        /// <param name="timeOut">代理请求超时时间(毫秒)</param>
        /// <param name="kfAccount">客服</param>
        /// <returns></returns>
        public static async Task <WxJsonResult> SendTextAsync(string accessTokenOrAppId, string openId, string content, int timeOut = Config.TIME_OUT, string kfAccount = "")
        {
            return(await ApiHandlerWapper.TryCommonApiAsync(accessToken =>
            {
                if (string.IsNullOrEmpty(kfAccount))
                {
                    return CustomApi.SendTextAsync(accessTokenOrAppId, openId, content, timeOut);
                }

                var data = new
                {
                    touser = openId,
                    msgtype = "text",
                    text = new
                    {
                        content = content
                    },
                    customservice = new
                    {
                        kf_account = kfAccount
                    }
                };

                return Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync(accessToken, URL_FORMAT, data, timeOut: timeOut);
            }, accessTokenOrAppId));
        }
Example #5
0
 /// <summary>
 /// 发送视频消息
 /// </summary>
 /// <param name="accessTokenOrAppId"></param>
 /// <param name="openId"></param>
 /// <param name="mediaId"></param>
 /// <param name="title"></param>
 /// <param name="description"></param>
 /// <param name="timeOut">代理请求超时时间(毫秒)</param>
 /// <param name="kfAccount">客服</param>
 /// <returns></returns>
 public static WxJsonResult SendVideo(string accessTokenOrAppId, string openId, string mediaId, string title, string description, int timeOut = Config.TIME_OUT, string kfAccount = "")
 {
     if (string.IsNullOrWhiteSpace(kfAccount))
     {
         return(CustomApi.SendVideo(accessTokenOrAppId, openId, mediaId, title, description, timeOut));
     }
     return(ApiHandlerWapper.TryCommonApi(accessToken =>
     {
         var data = new
         {
             touser = openId,
             msgtype = "video",
             video = new
             {
                 media_id = mediaId,
                 title = title,
                 description = description
             },
             CustomService = new
             {
                 kf_account = kfAccount
             }
         };
         return CommonJsonSend.Send(accessToken, URL_FORMAT, data, timeOut: timeOut);
     }, accessTokenOrAppId));
 }
Example #6
0
 /// <summary>
 /// 【异步方法】发送图文消息(点击跳转到图文消息页面)
 /// 图文消息条数限制在8条以内,注意,如果图文数超过8,则将会无响应。
 /// </summary>
 /// <param name="accessTokenOrAppId"></param>
 /// <param name="openId"></param>
 /// <param name="mediaId"></param>
 /// <param name="timeOut"></param>
 /// <param name="kfAccount">客服</param>
 /// <returns></returns>
 public static async Task <WxJsonResult> SendMpNewsAsync(string accessTokenOrAppId, string openId, string mediaId, int timeOut = Config.TIME_OUT, string kfAccount = "")
 {
     if (string.IsNullOrWhiteSpace(kfAccount))
     {
         return(CustomApi.SendMpNews(accessTokenOrAppId, openId, mediaId, timeOut));
     }
     return(await ApiHandlerWapper.TryCommonApiAsync(accessToken =>
     {
         var data = new
         {
             touser = openId,
             msgtype = "mpnews",
             mpnews = new
             {
                 media_id = mediaId
             },
             CustomService = new
             {
                 kf_account = kfAccount
             }
         };
         return Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync(accessToken, URL_FORMAT, data, timeOut: timeOut);
     }, accessTokenOrAppId));
 }
Example #7
0
        /// <summary>
        /// 发送图片客服消息
        /// </summary>
        /// <param name="accessTokenOrAppId"></param>
        /// <param name="openId"></param>
        /// <param name="mediaId"></param>
        /// <returns></returns>
        public override ApiResult SendImage(string accessTokenOrAppId, string openId, string mediaId)
        {
            var reuslt = CustomApi.SendImage(accessTokenOrAppId, openId, mediaId);

            return(new ApiResult((int)reuslt.errcode, reuslt.errmsg, reuslt));
        }
Example #8
0
        /// <summary>
        /// 发送文本客服消息
        /// </summary>
        /// <param name="accessTokenOrAppId"></param>
        /// <param name="openId"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        public override ApiResult SendText(string accessTokenOrAppId, string openId, string content)
        {
            var reuslt = CustomApi.SendText(accessTokenOrAppId, openId, content);

            return(new ApiResult((int)reuslt.errcode, reuslt.errmsg, reuslt));
        }