예제 #1
0
        /// <summary>
        /// 设置客服账号的头像。
        /// </summary>
        /// <param name="account">完整客服账号,格式为:账号前缀@公众号微信号</param>
        /// <param name="pictureData">客服人员的头像,头像图片文件必须是jpg格式,推荐使用640*640大小的图片以达到最佳效果</param>
        public void SetAccountHeadPicture(string account, byte[] pictureData)
        {
            if (!FileHelper.IsJpg(pictureData))
                throw new NotSupportedException("头像图片文件必须是jpg格式。");

            var url = string.Format("http://api.weixin.qq.com/customservice/kfaccount/uploadheadimg?access_token={0}&kf_account={1}", _accountModel.GetAccessToken(), account);

            var createBytes = new CreateBytes();
            var list = new ArrayList
            {
                createBytes.CreateFieldData("media", FileHelper.GetRandomFileName(pictureData), FileHelper.GetContentType(pictureData), pictureData),
            };
            var data = createBytes.JoinBytes(list);

            WeiXinHttpHelper.Post(url, data, createBytes.ContentType);
        }
예제 #2
0
 /// <summary>
 /// 上传图片。
 /// </summary>
 /// <param name="data">图片数据(大小限制1MB,支持JPG格式)。</param>
 /// <returns>如果上传成功则返回图片的绝对url地址。</returns>
 public string UploadImage(byte[] data)
 {
     var url = "http://file.api.weixin.qq.com/cgi-bin/media/uploadimg?access_token=" + _accountModel.GetAccessToken();
     var createBytes = new CreateBytes();
     var postData = createBytes.JoinBytes(new ArrayList
     {
         createBytes.CreateFieldData("buffer", FileHelper.GetRandomFileName(data), "image/jpeg", data)
     });
     var json = WeiXinHttpHelper.PostString(url, postData, createBytes.ContentType);
     return JObject.Parse(json)["url"].Value<string>();
 }