Ejemplo n.º 1
0
        /// <summary>
        /// 发送图文消息(客服)
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="access_token">访问令牌</param>
        /// <returns></returns>
        public static RequestResultBaseModel SendNewsByKF(kfNewsMsg msg, string access_token)
        {
            if (null == msg || string.IsNullOrWhiteSpace(msg.touser))
            {
                throw new ArgumentException("参数错误", nameof(msg.touser));
            }
            if (null == msg.news || null == msg.news.articles || 1 > msg.news.articles.Count || 8 < msg.news.articles.Count)
            {
                throw new ArgumentException("图文消息条数限制在8条以内");
            }
            if (null == msg.customservice || string.IsNullOrWhiteSpace(msg.customservice.kf_account))
            {
                throw new ArgumentException("customservice参数不能为空");
            }

            string jsonString = JsonHelper.Serialize(msg);

            return(SendToWeCart(jsonString, access_token));
        }
Ejemplo n.º 2
0
        public static string SendNewsByKF(kfNewsMsg msg)
        {
            if (null == msg || string.IsNullOrWhiteSpace(msg.touser))
            {
                return(string.Empty);
            }
            if (null == msg.news || null == msg.news.articles || 1 > msg.news.articles.Count || 8 < msg.news.articles.Count)
            {
                throw new ArgumentException("图文消息条数限制在8条以内");
            }
            if (null == msg.customservice || string.IsNullOrWhiteSpace(msg.customservice.kf_account))
            {
                throw new ArgumentException("customservice参数不能为空");
            }

            string jsonString = JsonHelper.Serialize(msg);

            if (!string.IsNullOrWhiteSpace(jsonString))
            {
                return(jsonString);
            }
            return(string.Empty);
        }