Ejemplo n.º 1
0
        public async Task <WXMediaUploadResponse> UploadTempMaterial(MaterialTypeEnum mediaType, Stream stream, string mimeType, string fileName)
        {
            NameValueCollection qs = new NameValueCollection()
            {
                { "type", materialTypeMapper[mediaType] }
            };

            return(await _client.UploadStreamAsync <WXMediaUploadResponse>("cgi-bin/media/upload", DEFAULT_MEDIA_KEY, stream, fileName, mimeType, null, null, HttpMethod.Post.Method, qs));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 上传临时素材
        /// </summary>
        /// <param name="mediaType">素材类型</param>
        /// <param name="filePath">文件路径</param>
        /// <returns></returns>
        public async Task <WXMediaUploadResponse> UploadTempMaterial(MaterialTypeEnum mediaType, string filePath)
        {
            NameValueCollection qs = new NameValueCollection()
            {
                { "type", materialTypeMapper[mediaType] }
            };

            string contentType = GetFileMimeType(filePath);

            return(await _client.UploadFileAsync <WXMediaUploadResponse>("cgi-bin/media/upload", DEFAULT_MEDIA_KEY, filePath, contentType, null, null, HttpMethod.Post.Method, qs));
        }
 public override System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer> ReadFields(System.IO.BinaryReader binaryReader)
 {
     System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer> pointerQueue = new System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer>(base.ReadFields(binaryReader));
     this.MaterialName       = binaryReader.ReadStringID();
     this.MaterialType       = ((MaterialTypeEnum)(binaryReader.ReadInt16()));
     this.DamageSection      = binaryReader.ReadShortBlockIndex2();
     this.fieldpad           = binaryReader.ReadBytes(2);
     this.fieldpad0          = binaryReader.ReadBytes(2);
     this.GlobalMaterialName = binaryReader.ReadStringID();
     this.fieldpad1          = binaryReader.ReadBytes(4);
     return(pointerQueue);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取永久素材列表
        /// </summary>
        /// <param name="type">素材类型</param>
        /// <param name="offset">从全部素材的该偏移位置开始返回,0表示从第一个素材 返回</param>
        /// <param name="count">返回素材的数量,取值在1到20之间</param>
        /// <returns></returns>
        public async Task <WXGetMaterialListResponse> GetMaterialList(MaterialTypeEnum type, int offset, int count)
        {
            string typeName = materialTypeMapper[type];

            return(await _client.PostAsync <WXGetMaterialListResponse>("cgi-bin/material/batchget_material",
                                                                       new
            {
                type = typeName,
                offset,
                count
            }));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 获取物料类型的说明
        /// </summary>
        /// <param name="materialType"></param>
        /// <returns></returns>
        public static string GetMaterialTypeString(MaterialTypeEnum materialType)
        {
            string strReturn = string.Empty;

            switch (materialType)
            {
            case MaterialTypeEnum.Y:
                strReturn = "原料";
                break;

            case MaterialTypeEnum.F:
                strReturn = "辅料";
                break;

            case MaterialTypeEnum.AP:
                strReturn = "辅成品";
                break;

            case MaterialTypeEnum.C:
                strReturn = "主成品";
                break;

            case MaterialTypeEnum.P:
                strReturn = "包装材料";
                break;

            case MaterialTypeEnum.Z:
                strReturn = "中间物料";
                break;

            case MaterialTypeEnum.RE:
                strReturn = "渣";
                break;

            case MaterialTypeEnum.WW:
                strReturn = "废水";
                break;

            case MaterialTypeEnum.WL:
                strReturn = "废液";
                break;

            case MaterialTypeEnum.WG:
                strReturn = "废气";
                break;

            default:
                break;
            }
            return(strReturn);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 上传永久素材,流方式
        /// </summary>
        /// <param name="mediaType">素材类型</param>
        /// <param name="stream">数据流</param>
        /// <param name="mimeType">类型</param>
        /// <param name="fileName">文件名称</param>
        /// <param name="title">标题,视频类型时需要提供</param>
        /// <param name="introduction">说明,视频类型时需要提供</param>
        /// <returns>应答</returns>
        public async Task <WXAddMaterialResponse> AddMaterial(MaterialTypeEnum mediaType, Stream stream, string mimeType, string fileName, string title, string introduction)
        {
            Dictionary <string, string> formData = new Dictionary <string, string>();

            if (!string.IsNullOrEmpty(title) || !string.IsNullOrEmpty(introduction))
            {
                formData.Add("description", _jsonHelper.ToJson(new
                {
                    title,
                    introduction
                }));
            }

            NameValueCollection queryString = new NameValueCollection()
            {
                { "type", materialTypeMapper[mediaType] }
            };


            return(await _client.UploadStreamAsync <WXAddMaterialResponse>("cgi-bin/material/add_material",
                                                                           DEFAULT_MEDIA_KEY, stream, fileName, mimeType, "", formData, HttpMethod.Post.Method, queryString));
        }
Ejemplo n.º 7
0
 public string GetMaterialTypeString(MaterialTypeEnum type)
 {
     return(materialTypeMapper[type]);
 }
Ejemplo n.º 8
0
        /// <summary>
        /// 添加临时素材
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="materialType"></param>
        /// <param name="formItems"></param>
        public AddTemporaryMaterialResultModel AddTemporaryMaterial(string accessToken, MaterialTypeEnum materialType, params FormItemModel[] formItems)
        {
            var data = new WeChatDataModel();

            data.SetValue("access_token", accessToken);
            data.SetValue("type", materialType.ToString().ToLower());
            string   url          = $"{Config.WeChatAPIUrl}cgi-bin/media/upload?{data.ToUrlParams()}";
            string   weChatResult = WeChatHttpManager.PostFormData(url, formItems, false, 3000, Config);
            JsonData jsonData     = JsonMapper.ToObject(weChatResult);

            if (WeChatPublicNumberErrorHelper.IsError(jsonData))
            {
                throw WeChatPublicNumberErrorHelper.GetWeChatException(jsonData);
            }
            var result = weChatResult.JsonToObject <AddTemporaryMaterialResultModel>();

            return(result);
        }
Ejemplo n.º 9
0
 public MaterialCondition(MaterialTypeEnum type, int offset, int count)
 {
     this.type   = type.ToString();
     this.offset = offset;
     this.count  = count;
 }