Esempio n. 1
0
        /// <summary>
        /// 设置(上传)客服头像
        /// </summary>
        /// <param name="userName">公众号</param>
        /// <param name="kfAccount">客服账号</param>
        /// <param name="imageData">图像数据</param>
        /// <returns>返回设置是否成功</returns>
        /// <returns></returns>
        public static ErrorMessage UploadHeadImage(string userName, string kfAccount, byte[] imageData)
        {
            ErrorMessage errorMessage = new ErrorMessage(ErrorMessage.ExceptionCode, "");

            if (!CheckKfAccount(kfAccount))
            {
                errorMessage.errmsg = "客服账号不正确。";
                return(errorMessage);
            }
            if (imageData == null || imageData.Length == 0)
            {
                errorMessage.errmsg = "没有图像数据。";
                return(errorMessage);
            }
            AccessToken token = AccessToken.Get(userName);

            if (token == null)
            {
                errorMessage.errmsg = "获取许可令牌失败。";
                return(errorMessage);
            }
            string url = string.Format(urlForUploadingHeadImg, token.access_token, kfAccount);
            string responseContent;

            if (!HttpHelper.Request(url, out responseContent, httpMethodForUploadingHeadImg, imageData))
            {
                errorMessage.errmsg = "从微信服务器获取响应失败。";
                return(errorMessage);
            }
            if (ErrorMessage.TryParse(responseContent, out errorMessage))
            {
                return(errorMessage);
            }
            else
            {
                return(new ErrorMessage(ErrorMessage.ExceptionCode, "解析返回结果失败。"));
            }
        }