公众号客服管理

    /// <summary>
        /// 添加客服/需要邀请那个微信为客服
        /// </summary>
 
        /// <param name="nickname">客服名称</param>
        /// <param name="invite_wx">微信号</param>
        /// <returns></returns>
        public static string AddCustomer(sring nickname,string invite_wx)
        {

     string kf_account=“1234@gt_29855241f1babec” //自定义前面几位数不可以中文+“@”+公众号id (1234@gt_29855241f1babec) 公众号id在公众号设置注册信息找到原始ID
            string url = string.Format("https://api.weixin.qq.com/customservice/kfaccount/add?access_token={0}", “这个是access_token参数”);//之前有讲方法获取,可以看下第一期的公众号开发
            Dictionary<string, string> data = new Dictionary<string, string>();
            data.Add("kf_account", kf_account);
            data.Add("nickname", nickname);
            string content = JsonConvert.SerializeObject(data);
            string result = HttpMethods.HttpPost(url, content);//这个请求是post上面有写方法
            LogHelper.Info("添加客服:" + result);
            url = string.Format("https://api.weixin.qq.com/customservice/kfaccount/inviteworker?access_token={0}", GetAccessToken(StationId));
            data = new Dictionary<string, string>();
            data.Add("kf_account", kf_account);
            data.Add("invite_wx", invite_wx);
            content = JsonConvert.SerializeObject(data);
            result = HttpMethods.HttpPost(url, content);
            LogHelper.Info("邀请绑定客服帐号:" + result);//写日志
            return result;
        }

      /// <summary>
        /// 删除客服
        /// </summary>
        /// <param name="kf_account">客服账号</param>
        /// <returns></returns>
        public static string DelCustomer(string kf_account,access_token)
        {
            Dictionary<string, string> data = new Dictionary<string, string>();
            data.Add("kf_account", kf_account);
            data.Add("access_token",access_token);
            string url = "https://api.weixin.qq.com/customservice/kfaccount/del?" +ToUrl(data); ;
            string result = HttpMethods.HttpGet(url);
            LogHelper.Info("删除客服:" + result);
            return result;
        }

 

//参数拼接  适用于GET请求  

public static string ToUrl(Dictionary<string, string> data)
        {
            string result = "";
            foreach (var item in data)
            {
                result += string.Format("{0}={1}&", item.Key, item.Value);
            }
            return result.Substring(0, result.Length - 1);
        }

  /// <summary>
        ///获取所有客服
        /// </summary>
        /// <param name="StationId">站点</param>
        /// <returns></returns>
        public static string GetKflist( string access_token)
        {
            string url = string.Format("https://api.weixin.qq.com/cgi-bin/customservice/getkflist?access_token={0}",access_token );
            string result = HttpMethods.HttpGet(url);
           return result;
        }

 

  /// <summary>
        /// 创建用户与客服之间的会话
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="kf_account">客服账号</param>
        /// <param name="openid">用户openid</param>
        /// <returns></returns>
        public static string Create(string access_token,string kf_account,string openid)
        {
            string url = string.Format("https://api.weixin.qq.com/customservice/kfsession/create?access_token={0}",access_token);
            Dictionary<string, string> data = new Dictionary<string, string>();
            data.Add("kf_account", kf_account);
            data.Add("openid", openid);
            string content = JsonConvert.SerializeObject(data);
            string result = HttpMethods.HttpPost(url, content);
            return result;
        }

 

   /// <summary>
     /// 自定义客服表 命名不规范 
     /// </summary>
        public class KflistMode
        {
            /// <summary>
            /// 客服账号
            /// </summary>
            public string kf_account { get; set; }
            /// <summary>
            /// 客服头像
            /// </summary>
            public string kf_headimgurl { get; set; }
            /// <summary>
            /// ID
            /// </summary>
            public string kf_id { get; set; }
            /// <summary>
            ///客服名称
            /// </summary>
            public string kf_nick { get; set; }
            /// <summary>
            /// 绑定人微信
            /// </summary>
            public string kf_wx { get; set; }

        }

原数据

{
    "kf_list": [
        {
            "kf_account": "xxx@xxxx",
            "kf_headimgurl": "",
            "kf_id": 1002,
            "kf_nick": "财务02",
            "kf_wx": "xxxx"
        }
    ]
}

 var jon =  GetKflistt(“xxxxxxxx”);

   JObject jObj = JObject.Parse(jon);
     var kf_list = jObj["kf_list"].ToString();

//转集合      

var x= JsonConvert.DeserializeObject<List<KflistMode>>(returnCode);

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值