From 80f84f6bd45f1c57c8401af5f8ef5c5ea8de1f57 Mon Sep 17 00:00:00 2001 From: shanj <18996038927@163.com> Date: Wed, 2 Mar 2022 05:02:35 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E5=86=99=E9=80=82=E5=90=88.net?= =?UTF-8?q?=E7=9A=84=E5=8F=82=E6=95=B0=E5=BA=8F=E5=88=97=E5=8C=96=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BBWY.1688SDK/BBWY.1688SDK.csproj | 4 + .../example/param/apiexample/ExampleFamily.cs | 200 ++++++++++-------- .../apiexample/ExampleFamilyPostParam.cs | 104 ++++----- .../example/param/apiexample/ExampleHouse.cs | 136 ++++++------ BBWY.1688SDK/serialize/Json2Deserializer.cs | 2 +- .../serialize/Param2RequestSerializer.cs | 107 ++++++---- 6 files changed, 303 insertions(+), 250 deletions(-) diff --git a/BBWY.1688SDK/BBWY.1688SDK.csproj b/BBWY.1688SDK/BBWY.1688SDK.csproj index fad4a782..ce828eff 100644 --- a/BBWY.1688SDK/BBWY.1688SDK.csproj +++ b/BBWY.1688SDK/BBWY.1688SDK.csproj @@ -5,4 +5,8 @@ BBWY._1688SDK + + + + diff --git a/BBWY.1688SDK/example/param/apiexample/ExampleFamily.cs b/BBWY.1688SDK/example/param/apiexample/ExampleFamily.cs index 8bcf2c54..51580a39 100644 --- a/BBWY.1688SDK/example/param/apiexample/ExampleFamily.cs +++ b/BBWY.1688SDK/example/param/apiexample/ExampleFamily.cs @@ -9,124 +9,136 @@ using System.Text; namespace com.alibaba.china.openapi.client.example.param.apiexample { -[DataContract(Namespace = "com.alibaba.openapi.client")] + [DataContract(Namespace = "com.alibaba.openapi.client")] public class ExampleFamily { - [DataMember(Order = 1)] - private int? familyNumber; - + [DataMember(Order = 1)] + private int? familyNumber; + /** * @return 家庭编号 */ - public int? getFamilyNumber() { - return familyNumber; - } - - /** - * 设置家庭编号 * - * 参数示例:
     
-             * 此参数必填
-          */
-    public void setFamilyNumber(int familyNumber) {
-     	         	    this.familyNumber = familyNumber;
-     	        }
-    
+        public int? getFamilyNumber()
+        {
+            return familyNumber;
+        }
+
+        /**
+         * 设置家庭编号     *
+         * 参数示例:
     
+                 * 此参数必填
+              */
+        public void setFamilyNumber(int familyNumber)
+        {
+            this.familyNumber = familyNumber;
+        }
+
         [DataMember(Order = 2)]
-    private ExamplePerson father;
-    
+        private ExamplePerson father;
+
         /**
        * @return 父亲对象,可以为空
     */
-        public ExamplePerson getFather() {
-               	return father;
-            }
-    
-    /**
-     * 设置父亲对象,可以为空     *
-     * 参数示例:
     
-             * 此参数必填
-          */
-    public void setFather(ExamplePerson father) {
-     	         	    this.father = father;
-     	        }
-    
+        public ExamplePerson getFather()
+        {
+            return father;
+        }
+
+        /**
+         * 设置父亲对象,可以为空     *
+         * 参数示例:
     
+                 * 此参数必填
+              */
+        public void setFather(ExamplePerson father)
+        {
+            this.father = father;
+        }
+
         [DataMember(Order = 3)]
-    private ExamplePerson mother;
-    
+        private ExamplePerson mother;
+
         /**
        * @return 母亲对象,可以为空
     */
-        public ExamplePerson getMother() {
-               	return mother;
-            }
-    
-    /**
-     * 设置母亲对象,可以为空     *
-     * 参数示例:
     
-             * 此参数必填
-          */
-    public void setMother(ExamplePerson mother) {
-     	         	    this.mother = mother;
-     	        }
-    
+        public ExamplePerson getMother()
+        {
+            return mother;
+        }
+
+        /**
+         * 设置母亲对象,可以为空     *
+         * 参数示例:
     
+                 * 此参数必填
+              */
+        public void setMother(ExamplePerson mother)
+        {
+            this.mother = mother;
+        }
+
         [DataMember(Order = 4)]
-    private ExamplePerson[] children;
-    
+        private ExamplePerson[] children;
+
         /**
        * @return 孩子列表
     */
-        public ExamplePerson[] getChildren() {
-               	return children;
-            }
-    
-    /**
-     * 设置孩子列表     *
-     * 参数示例:
     
-             * 此参数必填
-          */
-    public void setChildren(ExamplePerson[] children) {
-     	         	    this.children = children;
-     	        }
-    
+        public ExamplePerson[] getChildren()
+        {
+            return children;
+        }
+
+        /**
+         * 设置孩子列表     *
+         * 参数示例:
     
+                 * 此参数必填
+              */
+        public void setChildren(ExamplePerson[] children)
+        {
+            this.children = children;
+        }
+
         [DataMember(Order = 5)]
-    private ExampleCar[] ownedCars;
-    
+        private ExampleCar[] ownedCars;
+
         /**
        * @return 拥有的汽车信息
     */
-        public ExampleCar[] getOwnedCars() {
-               	return ownedCars;
-            }
-    
-    /**
-     * 设置拥有的汽车信息     *
-     * 参数示例:
     
-             * 此参数必填
-          */
-    public void setOwnedCars(ExampleCar[] ownedCars) {
-     	         	    this.ownedCars = ownedCars;
-     	        }
-    
+        public ExampleCar[] getOwnedCars()
+        {
+            return ownedCars;
+        }
+
+        /**
+         * 设置拥有的汽车信息     *
+         * 参数示例:
     
+                 * 此参数必填
+              */
+        public void setOwnedCars(ExampleCar[] ownedCars)
+        {
+            this.ownedCars = ownedCars;
+        }
+
         [DataMember(Order = 6)]
-    private ExampleHouse myHouse;
-    
+        private ExampleHouse myHouse;
+
         /**
        * @return 所住的房屋信息
     */
-        public ExampleHouse getMyHouse() {
-               	return myHouse;
-            }
-    
-    /**
-     * 设置所住的房屋信息     *
-     * 参数示例:
     
-             * 此参数必填
-          */
-    public void setMyHouse(ExampleHouse myHouse) {
-     	         	    this.myHouse = myHouse;
-     	        }
-    
-    
-  }
+        public ExampleHouse getMyHouse()
+        {
+            return myHouse;
+        }
+
+        /**
+         * 设置所住的房屋信息     *
+         * 参数示例:
     
+                 * 此参数必填
+              */
+        public void setMyHouse(ExampleHouse myHouse)
+        {
+            this.myHouse = myHouse;
+        }
+
+
+    }
 }
\ No newline at end of file
diff --git a/BBWY.1688SDK/example/param/apiexample/ExampleFamilyPostParam.cs b/BBWY.1688SDK/example/param/apiexample/ExampleFamilyPostParam.cs
index 355cd1e1..087c88a8 100644
--- a/BBWY.1688SDK/example/param/apiexample/ExampleFamilyPostParam.cs
+++ b/BBWY.1688SDK/example/param/apiexample/ExampleFamilyPostParam.cs
@@ -9,67 +9,73 @@ using System.Text;
 
 namespace com.alibaba.china.openapi.client.example.param.apiexample
 {
-[DataContract(Namespace = "com.alibaba.openapi.client")]
+    [DataContract(Namespace = "com.alibaba.openapi.client")]
     public class ExampleFamilyPostParam
     {
 
-       [DataMember(Order = 1)]
-    private ExampleFamily family;
-    
+        [DataMember(Order = 1)]
+        private ExampleFamily family;
+
         /**
        * @return 上传Family对象信息
     */
-        public ExampleFamily getFamily() {
-               	return family;
-            }
-    
-    /**
-     * 设置上传Family对象信息     *
-     * 参数示例:
     
-             * 此参数必填
-          */
-    public void setFamily(ExampleFamily family) {
-     	         	    this.family = family;
-     	        }
-    
+        public ExampleFamily getFamily()
+        {
+            return family;
+        }
+
+        /**
+         * 设置上传Family对象信息     *
+         * 参数示例:
     
+                 * 此参数必填
+              */
+        public void setFamily(ExampleFamily family)
+        {
+            this.family = family;
+        }
+
         [DataMember(Order = 2)]
-    private string comments;
-    
+        private string comments;
+
         /**
        * @return 备注信息
     */
-        public string getComments() {
-               	return comments;
-            }
-    
-    /**
-     * 设置备注信息     *
-     * 参数示例:
     
-             * 此参数必填
-          */
-    public void setComments(string comments) {
-     	         	    this.comments = comments;
-     	        }
-    
+        public string getComments()
+        {
+            return comments;
+        }
+
+        /**
+         * 设置备注信息     *
+         * 参数示例:
     
+                 * 此参数必填
+              */
+        public void setComments(string comments)
+        {
+            this.comments = comments;
+        }
+
         [DataMember(Order = 3)]
-    private byte[] houseImg;
-    
+        private byte[] houseImg;
+
         /**
        * @return 房屋信息
     */
-        public byte[] getHouseImg() {
-               	return houseImg;
-            }
-    
-    /**
-     * 设置房屋信息     *
-     * 参数示例:
     
-             * 此参数必填
-          */
-    public void setHouseImg(byte[] houseImg) {
-     	         	    this.houseImg = houseImg;
-     	        }
-    
-    
-  }
+        public byte[] getHouseImg()
+        {
+            return houseImg;
+        }
+
+        /**
+         * 设置房屋信息     *
+         * 参数示例:
     
+                 * 此参数必填
+              */
+        public void setHouseImg(byte[] houseImg)
+        {
+            this.houseImg = houseImg;
+        }
+
+
+    }
 }
\ No newline at end of file
diff --git a/BBWY.1688SDK/example/param/apiexample/ExampleHouse.cs b/BBWY.1688SDK/example/param/apiexample/ExampleHouse.cs
index d865cd9b..728a04de 100644
--- a/BBWY.1688SDK/example/param/apiexample/ExampleHouse.cs
+++ b/BBWY.1688SDK/example/param/apiexample/ExampleHouse.cs
@@ -9,86 +9,94 @@ using System.Text;
 
 namespace com.alibaba.china.openapi.client.example.param.apiexample
 {
-[DataContract(Namespace = "com.alibaba.openapi.client")]
+    [DataContract(Namespace = "com.alibaba.openapi.client")]
     public class ExampleHouse
     {
 
-       [DataMember(Order = 1)]
-    private string location;
-    
+        [DataMember(Order = 1)]
+        private string location;
+
         /**
        * @return 
     */
-        public string getLocation() {
-               	return location;
-            }
-    
-    /**
-     * 设置     *
-     * 参数示例:
     
-             * 此参数必填
-          */
-    public void setLocation(string location) {
-     	         	    this.location = location;
-     	        }
-    
+        public string getLocation()
+        {
+            return location;
+        }
+
+        /**
+         * 设置     *
+         * 参数示例:
     
+                 * 此参数必填
+              */
+        public void setLocation(string location)
+        {
+            this.location = location;
+        }
+
         [DataMember(Order = 2)]
-    private int? areaSize;
-    
+        private int? areaSize;
+
         /**
        * @return 
     */
-        public int? getAreaSize() {
-               	return areaSize;
-            }
-    
-    /**
-     * 设置     *
-     * 参数示例:
     
-             * 此参数必填
-          */
-    public void setAreaSize(int areaSize) {
-     	         	    this.areaSize = areaSize;
-     	        }
-    
+        public int? getAreaSize()
+        {
+            return areaSize;
+        }
+
+        /**
+         * 设置     *
+         * 参数示例:
     
+                 * 此参数必填
+              */
+        public void setAreaSize(int areaSize)
+        {
+            this.areaSize = areaSize;
+        }
+
         [DataMember(Order = 3)]
-    private bool? rent;
-    
+        private bool? rent;
+
         /**
        * @return 
     */
-        public bool? getRent() {
-               	return rent;
-            }
-    
-    /**
-     * 设置     *
-     * 参数示例:
     
-             * 此参数必填
-          */
-    public void setRent(bool rent) {
-     	         	    this.rent = rent;
-     	        }
-    
+        public bool? getRent()
+        {
+            return rent;
+        }
+
+        /**
+         * 设置     *
+         * 参数示例:
     
+                 * 此参数必填
+              */
+        public void setRent(bool rent)
+        {
+            this.rent = rent;
+        }
+
         [DataMember(Order = 4)]
-    private int? rooms;
-    
+        private int? rooms;
+
         /**
        * @return 
     */
-        public int? getRooms() {
-               	return rooms;
-            }
-    
-    /**
-     * 设置     *
-     * 参数示例:
     
-             * 此参数必填
-          */
-    public void setRooms(int rooms) {
-     	         	    this.rooms = rooms;
-     	        }
-    
-    
-  }
+        public int? getRooms()
+        {
+            return rooms;
+        }
+
+        /**
+         * 设置     *
+         * 参数示例:
     
+                 * 此参数必填
+              */
+        public void setRooms(int rooms)
+        {
+            this.rooms = rooms;
+        }
+
+
+    }
 }
\ No newline at end of file
diff --git a/BBWY.1688SDK/serialize/Json2Deserializer.cs b/BBWY.1688SDK/serialize/Json2Deserializer.cs
index 79b9dbe5..2b12b423 100644
--- a/BBWY.1688SDK/serialize/Json2Deserializer.cs
+++ b/BBWY.1688SDK/serialize/Json2Deserializer.cs
@@ -38,7 +38,7 @@ namespace com.alibaba.openapi.client.serialize
         {
 
 
-            istream.Position = 0;
+            //istream.Position = 0;
             DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(ErrorExceptionDesc));
             object resultObj = jsonSerializer.ReadObject(istream);
             ErrorExceptionDesc result = (ErrorExceptionDesc)resultObj;
diff --git a/BBWY.1688SDK/serialize/Param2RequestSerializer.cs b/BBWY.1688SDK/serialize/Param2RequestSerializer.cs
index 2812bdc8..3e9878bb 100644
--- a/BBWY.1688SDK/serialize/Param2RequestSerializer.cs
+++ b/BBWY.1688SDK/serialize/Param2RequestSerializer.cs
@@ -1,6 +1,7 @@
 using com.alibaba.openapi.client.policy;
 using com.alibaba.openapi.client.primitive;
 using com.alibaba.openapi.client.util;
+using Newtonsoft.Json;
 using System;
 using System.Collections.Generic;
 using System.Globalization;
@@ -23,8 +24,9 @@ namespace com.alibaba.openapi.client.serialize
 
         public Dictionary serialize(Object serializer)
         {
-            Dictionary result = serializeNest(serializer);
-            return result;
+            //Dictionary result = serializeNest(serializer);
+            //return result;
+            return serializeParam(serializer);
         }
 
         private Dictionary serializeNest(Object serializer)
@@ -49,57 +51,78 @@ namespace com.alibaba.openapi.client.serialize
                 String tempName = upperFirstCharacter + piName.Substring(1);
                 if (!"ApiId".Equals(tempName))
                 {
-                MethodInfo mi = type.GetMethod("get" + tempName);
-                object value = mi.Invoke(serializer, null);
-                if (value != null)
-                {
-                    object trueValue = null;
-                    if (fieldType.IsAssignableFrom(typeof(bool?))
-                        ||fieldType.IsAssignableFrom(typeof(byte?))
-                        ||fieldType.IsAssignableFrom(typeof(char?))
-                        ||fieldType.IsAssignableFrom(typeof(double?))
-                        ||fieldType.IsAssignableFrom(typeof(float?))
-                        ||fieldType.IsAssignableFrom(typeof(int?))
-                        ||fieldType.IsAssignableFrom(typeof(long?)))
-                    {
-                        trueValue = value;
-                    }
-                    else if (fieldType.IsAssignableFrom(typeof(String)))
+                    MethodInfo mi = type.GetMethod("get" + tempName);
+                    object value = mi.Invoke(serializer, null);
+                    if (value != null)
                     {
-                        if (value.GetType().IsAssignableFrom(typeof(DateTime)))
+                        object trueValue = null;
+                        if (fieldType.IsAssignableFrom(typeof(bool?))
+                            || fieldType.IsAssignableFrom(typeof(byte?))
+                            || fieldType.IsAssignableFrom(typeof(char?))
+                            || fieldType.IsAssignableFrom(typeof(double?))
+                            || fieldType.IsAssignableFrom(typeof(float?))
+                            || fieldType.IsAssignableFrom(typeof(int?))
+                            || fieldType.IsAssignableFrom(typeof(long?)))
+                        {
+                            trueValue = value;
+                        }
+                        else if (fieldType.IsAssignableFrom(typeof(String)))
+                        {
+                            if (value.GetType().IsAssignableFrom(typeof(DateTime)))
+                            {
+                                DateTime dateTime = (DateTime)value;
+                                trueValue = DateUtil.formatForOcean(dateTime);
+                            }
+                            else
+                            {
+                                trueValue = value;
+                            }
+                        }
+                        else if (fieldType.IsAssignableFrom(typeof(DateTime?)))
                         {
                             DateTime dateTime = (DateTime)value;
-                            trueValue = DateUtil.formatForOcean(dateTime);
+                            trueValue = DateUtil.format(dateTime);
+                        }
+                        else if (fieldType.IsAssignableFrom(typeof(Byte[])) || fieldType.IsAssignableFrom(typeof(byte[])))
+                        {
+                            trueValue = Convert.ToBase64String((byte[])value);
                         }
                         else
                         {
-                            trueValue = value;
+                            DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(fieldType);
+                            MemoryStream stream = new MemoryStream();
+                            dataContractJsonSerializer.WriteObject(stream, value);
+                            byte[] dataBytes = new byte[stream.Length];
+                            stream.Position = 0;
+                            stream.Read(dataBytes, 0, (int)stream.Length);
+
+                            string dataString = Encoding.UTF8.GetString(dataBytes);
+                            trueValue = dataString;
                         }
+                        result.Add(piName, trueValue);
                     }
-                    else if (fieldType.IsAssignableFrom(typeof(DateTime?)))
-                    {
-                        DateTime dateTime = (DateTime)value;
-                        trueValue = DateUtil.format(dateTime);
-                    }
-                    else if (fieldType.IsAssignableFrom(typeof(Byte[])) || fieldType.IsAssignableFrom(typeof(byte[])))
-                    {
-                        trueValue = Convert.ToBase64String((byte[])value);
-                    }
-                    else
-                    {
-                        DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(fieldType);
-                        MemoryStream stream = new MemoryStream();
-                        dataContractJsonSerializer.WriteObject(stream, value);
-                        byte[] dataBytes = new byte[stream.Length];
-                        stream.Position = 0;
-                        stream.Read(dataBytes, 0, (int)stream.Length);
 
-                        string dataString = Encoding.UTF8.GetString(dataBytes);
-                        trueValue = dataString;
-                    }
-                    result.Add(piName, trueValue);
                 }
+            }
+            return result;
+        }
 
+        private Dictionary serializeParam(object param)
+        {
+            Dictionary result = new Dictionary();
+            Type type = param.GetType();
+            var properties = type.GetProperties();
+            foreach (var property in properties)
+            {
+                var value = property.GetValue(param);
+                var valueType = value.GetType();
+                if (valueType.IsClass)
+                {
+                    result.Add(property.Name, JsonConvert.SerializeObject(value));
+                }
+                else
+                {
+                    result.Add(property.Name, value);
                 }
             }
             return result;