static void Main(string[] args)
        {
            YtRequest<RequestHead, RequestBody> Ytrequest = new YtRequest<RequestHead, RequestBody>
            {
                head = new RequestHead
                {
                    version="1.0",
                    product="B10002",
                    merchant="201511043830",
                    outOrderId = "110000000000005",
                    memo="备注信息",
                },
                body = new RequestBody
                {
                    name_card="",
                    id_card="",
                },
            };

            JavaScriptSerializer serializer = new JavaScriptSerializer();
            var prestr = serializer.Serialize(Ytrequest);
            string mysign = Sign(prestr, "N75tkwmnHV1UjZ60YAGK", "utf-8");

            YtSendModel<RequestHead, RequestBody> Ytsend = new YtSendModel<RequestHead, RequestBody>
            {
                request = new YtRequest<RequestHead, RequestBody>
                {
                    head = new RequestHead
                    {
                        version = "1.0",
                        product = "B10002",
                        merchant = "201511043830",
                        outOrderId = "123456",
                        memo = "连连实名认证",
                    },
                    body = new RequestBody
                    {
                        name_card = "min",
                        id_card = "141002465",
                    },
                },
                sign="12321435636",
            };

            string strRequestData = serializer.Serialize(Ytsend);

            Encoding enconding = Encoding.GetEncoding("utf-8");

            byte[] bytedata = enconding.GetBytes(strRequestData);


            HttpWebRequest re = (HttpWebRequest)HttpWebRequest.Create("https://api.udcredit.com/api/credit/v1/get_nauth");
            re.Method = "post";
            re.ContentType = "application/json";

            re.ContentLength = bytedata.Length;
            Stream requestStream = re.GetRequestStream();
            requestStream.Write(bytedata, 0, bytedata.Length);
            requestStream.Close();

            HttpWebResponse httpResponse = (HttpWebResponse)re.GetResponse();
            Stream myStream = httpResponse.GetResponseStream();

            StreamReader reader = new StreamReader(myStream, enconding);
            StringBuilder responseData = new StringBuilder();

            String line;
            while ((line = reader.ReadLine()) != null)
            {
                responseData.Append(line);
            }

            //释放
            myStream.Close();

            string strResult = responseData.ToString();

      
        }

        static  string Sign(string str,string key,string charset)
        {
            str=str+key;
            var sb=new StringBuilder(32);
            MD5 md5=new MD5CryptoServiceProvider();
            var arr=md5.ComputeHash(Encoding.GetEncoding(charset).GetBytes(str));
            foreach (var item in arr)
            {
                sb.Append(item.ToString("x").PadLeft(2, '0'));
            }
            return sb.ToString();
        }

建一个YtSendModel.cs 

public class YtSendModel<Head ,Body>
    {
       public YtRequest<Head, Body> request { get; set; }
       public string sign { get; set; }
    }
   public class YtRequest<Head, Body>
   {
       public Head head { get; set; }
       public Body body { get; set; }
   }
    public class RequestHead
    {
        public string version { get; set; }
        public string product { get; set; }
        public string merchant { get; set; }
        public string outOrderId { get; set; }
        public string memo { get; set; }
    }
    public class RequestBody
    {
        public string name_card { get; set; }
        public string id_card { get; set; }
    }

 

posted on 2016-11-21 17:09  菜鸟Only  阅读(181)  评论(0编辑  收藏  举报