Пример #1
0
        public static RequestResultBaseModel SendTextByKF(kfTextMsg msg, string access_token)
        {
            if (null == msg)
            {
                throw new ArgumentException("参数错误", nameof(msg));
            }
            if (string.IsNullOrWhiteSpace(msg.touser))
            {
                throw new ArgumentException("参数错误", nameof(msg.touser));
            }
            if (null == msg.text || string.IsNullOrWhiteSpace(msg.text.content))
            {
                throw new ArgumentException("content参数错误");
            }
            if (null == msg.customservice || string.IsNullOrWhiteSpace(msg.customservice.kf_account))
            {
                throw new ArgumentException("customservice参数不能为空");
            }

            string jsonString = JsonHelper.Serialize(msg);
            string result     = HttpRequestHelper.Request(SendMsgApiUrl(access_token), jsonString, HttpRequestHelper.Method.POST, System.Text.Encoding.UTF8);

            if (Common.ReturnJSONisOK(result))
            {
                return new RequestResultBaseModel()
                       {
                           errcode = 0, errmsg = "ok"
                       }
            }
            ;
            else
            {
                RequestResultBaseModel entity = JsonHelper.DeSerialize <RequestResultBaseModel>(result);

                if (entity != null)
                {
                    entity.url  = SendMsgApiUrl(access_token);
                    entity.date = jsonString;
                }
                return(entity);
            }
        }
Пример #2
0
        /// <summary>
        /// 发送文本消息(客服)
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="access_token">访问令牌</param>
        /// <returns></returns>
        public static RequestResultBaseModel SendTextByKF(kfTextMsg msg, string access_token)
        {
            if (null == msg)
            {
                throw new ArgumentException("参数错误", nameof(msg));
            }
            if (string.IsNullOrWhiteSpace(msg.touser))
            {
                throw new ArgumentException("参数错误", nameof(msg.touser));
            }
            if (null == msg.text || string.IsNullOrWhiteSpace(msg.text.content))
            {
                throw new ArgumentException("content参数错误");
            }
            if (null == msg.customservice || string.IsNullOrWhiteSpace(msg.customservice.kf_account))
            {
                throw new ArgumentException("customservice参数不能为空");
            }

            string jsonString = JsonHelper.Serialize(msg);

            return(SendToWeCart(jsonString, access_token));
        }