コード例 #1
0
ファイル: Test_Ali.cs プロジェクト: vijayamazon/ezbob
        public void Test_Alibaba0001()
        {
            StringDictionary parameters = new StringDictionary();
            StringBuilder    datas      = new StringBuilder(this.urlPath);

            string json = "{\"bankCode\":\"ezbob\",\"bizType\":\"0001\",\"requestId\":\"000011\",\"aliMemberId\":\"3287122\",\"aId\":\"43623912\",\"loanId\":\"40748200\",\"requestedAmt\":100000.0,\"compEntityType\":\"LLC\",\"compName\":\"A PLAZA DRIVING SCHOOL\",\"compStreetAddr1\":\"926 E LEWELLING BLVD\",\"compCity\":\"HAYWARD\",\"compState\":\"CA\",\"compZip\":\"94541\",\"compPhone\":\"4152224444\",\"compEstablished\":\"2000-04-01\",\"compEmployees\":3,\"compRent\":180.0,\"compOtherLoans\":100.0,\"compOtherLeases\":120.0,\"compOwnershipPercent\":\"20-49%\",\"personalIncome\":499999.0,\"personalStreet1\":\"205 CHURCH ST\",\"personalCity\":\"VINE GROVE\",\"personalState\":\"KY\",\"personalZip\":\"40175\",\"personalPhone\":\"4151230987\",\"firstName\":\"MICHAEL\",\"lastName\":\"ARTE\",\"email\":\"[email protected]\",\"compRevenue\":500000.0,\"compNetProfit\":100000.0,\"compCreLoans\":150.0,\"locOfferStatus\":\"App Submitted\",\"locOfferAmount\":83300.0,\"locOfferDate\":\"2015-02-09\",\"locOfferExpireDate\":\"2015-08-09\",\"locOfferCurrency\":\"GBP\",\"applicationDate\":\"2015-02-09\",\"countryId\":\"UK\"}";

            parameters.Add("data", json);

            var request = new RestRequest(this.urlPath, Method.POST);

            request.AddHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");

            // @TODO: add alphabetical sort for params

            // add json to POST form
            foreach (DictionaryEntry de in parameters)
            {
                request.AddParameter(de.Key.ToString(), de.Value);
                datas.Append(de.Key.ToString()).Append(de.Value);
            }

            // add alphabetical sort for params
            request.Parameters.ForEach(s => Console.WriteLine(s.Name + "=" + s.Value));

            //	Console.WriteLine(datas.ToString());

            //	Console.WriteLine(this.baseUrl);

            Encoding enc = System.Text.Encoding.UTF8;

            // from java: 3B819E81BAC9D0BC46808F58EE3FD64499FF16D1
            // .net		  3B819E81BAC9D0BC46808F58EE3FD64499FF16D1
            using (HMACSHA1 hmacsha1 = new HMACSHA1(enc.GetBytes(this.appSecret))) {
                byte[] digest    = hmacsha1.ComputeHash(datas.ToString().ToStream());
                string signature = MiscUtils.ByteArr2Hex(digest).ToUpper();
                Console.WriteLine("_aop_signature: " + signature);
                request.AddParameter("_aop_signature", signature);
            }
            return;

            var client = new RestClient(this.baseUrl);

            try {
                IRestResponse  response = client.Post(request);
                HttpStatusCode status   = response.StatusCode;
                Console.WriteLine(status);
                Console.WriteLine(response.Content);
            } catch (Exception e) {
                Console.WriteLine(e);
            }
        }
コード例 #2
0
ファイル: TestAlibaba.cs プロジェクト: vijayamazon/ezbob
        [Test]         // WORKING!!!
        public void Test_Alibaba0001()
        {
            //http://119.38.217.38:1680/openapi/param2/1/alibaba.open/partner.feedback/{appKey}
            String urlPath   = "param2/1/alibaba.open/partner.feedback/89978";
            String baseUrl   = "http://119.38.217.38:1680/openapi/";
            String appSecret = "IOVVt8lbOfDE";

            StringDictionary parameters = new StringDictionary();
            StringBuilder    datas      = new StringBuilder(urlPath);

            //string json = "{\"bankCode\": \"ezbob\",\"bizType\": \"0001\",\"requestID\": \"qa345we\",\"aliMemberId\": \"7776789\",\"compEntityType\":\"LLC\", \"compName\":\"blabla\", \"aId\": \"18234\",\"requestedAmt\": 30000.00,\"countryId\": \"UK\","
            //	+ "\"locOfferStatus\":\"Incomplete\", \"firstName\":\"Peter\",	\"lastName\": \"Joe\", \"personalPhone\": \"6176107849\" , \"email\": \"[email protected]\", \"loanId\": \"0\" }";

            string json = "{\"countryId\":\"UK\",\"locOfferCurrency\":\"GBP\",\"aId\":18240,\"aliMemberId\":18240,\"loanId\":null,\"requestedAmt\":5000.0,\"compName\":\"POSITIVE NOISE LTD\",\"compStreetAddr1\":\"42 New Road\",\"compStreetAddr2\":\"\",\"compCity\":\"Rochester\",\"compState\":\"Kent\",\"compZip\":\"ME1 1DX\",\"compPhone\":\"00000000000\",\"compEstablished\":null,\"compEstablishedYears\":\"\",\"compEmployees\":0,\"compEntityType\":\"Limited\",\"compType\":\"\",\"firstName\":\"Martin\",\"lastName\":\"Martin  Young\",\"personalStreet1\":\"23 Priestfields\",\"personalStreet2\":\"\",\"personalCity\":\"Rochester\",\"personalState\":\"Kent\",\"personalZip\":\"ME1 3AB\",\"personalPhone\":\"00000000000\",\"personalphoneAlt\":\"00000000000\",\"email\":\"[email protected]\",\"compRevenue\":630000.0,\"applicationDate\":\"2012-08-27T16:37:06Z\",\"locOfferStatus\":null,\"compRegId\":\"\",\"compDba\":\"\",\"website\":\"\",\"gender\":\"\",\"remarks\":\"\",\"rejectReason\":\"\",\"bankCode\":\"ezbob\",\"requestID\":18158565690,\"bizType\":\"0002\"}";

            parameters.Add("data", json);

            var request = new RestRequest(urlPath, Method.POST);

            request.AddHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");

            // add json to POST form
            foreach (DictionaryEntry de in parameters)
            {
                request.AddParameter(de.Key.ToString(), de.Value);
                datas.Append(de.Key.ToString()).Append(de.Value);
            }
            // add alphabetical sort for params
            request.Parameters.ForEach(s => Console.WriteLine(s.Name + "=" + s.Value));

            Console.WriteLine(datas.ToString());
            Console.WriteLine(baseUrl);

            Encoding enc = Encoding.UTF8;

            using (HMACSHA1 hmacsha1 = new HMACSHA1(enc.GetBytes(appSecret))) {
                byte[] digest    = hmacsha1.ComputeHash(datas.ToString().ToStream());
                string signature = MiscUtils.ByteArr2Hex(digest).ToUpper();
                Console.WriteLine("_aop_signature: " + signature);
                request.AddParameter("_aop_signature", signature);
            }
            var client = new RestClient(baseUrl);

            try {
                IRestResponse  response = client.Post(request);
                HttpStatusCode status   = response.StatusCode;
                Console.WriteLine(status);
                Console.WriteLine(response.Content);
            } catch (Exception e) {
                Console.WriteLine(e);
            }
        }
コード例 #3
0
ファイル: TestAlibaba.cs プロジェクト: vijayamazon/ezbob
        public void Test_AlibabaConnecitvity()
        {
            String urlPath   = "param2/1/alibaba.open/partner.feedback/89978";
            String baseUrl   = "http://119.38.217.38:1680/api/";
            String appSecret = "IOVVt8lbOfDE";

            StringDictionary parameters = new StringDictionary();
            StringBuilder    datas      = new StringBuilder(urlPath);

            parameters.Add("data", "{\"bankCode\":\"ezbob\",\"bizType\":\"0001\"}");
            var request = new RestRequest(urlPath, Method.POST);

            request.AddHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");

            // add json to POST form
            foreach (DictionaryEntry de in parameters)
            {
                request.AddParameter(de.Key.ToString(), de.Value);                // == parameters.Add("data", "{\"bankCode\":\"ezbob\",\"bizType\":\"0001\"}");
                datas.Append(de.Key.ToString()).Append(de.Value);                 // data{\"bankCode\":\"ezbob\",\"bizType\":\"0001\"}
            }
            // datas == {param2/1/alibaba.open/partner.feedback/89978data{"bankCode":"ezbob","bizType":"0001"}}
            //	string datas = "param2/1/alibaba.open/partner.feedback/89978data{\"bankCode\":\"ezbob\",\"bizType\":\"0001\"}";
            Encoding enc = Encoding.UTF8;

            using (HMACSHA1 hmacsha1 = new HMACSHA1(enc.GetBytes(appSecret))) {
                byte[] digest    = hmacsha1.ComputeHash(datas.ToString().ToStream());
                string signature = MiscUtils.ByteArr2Hex(digest).ToUpper();
                Console.WriteLine(signature);
                request.AddParameter("_aop_signature", signature);
            }

            request.Parameters.ForEach(p => Console.WriteLine(p.Name + "=" + p.Value));

            //	signature = "6EBE876BD0885923B2227C89B9F042CC7DA4FEDF";
            var client = new RestClient(baseUrl);

            try {
                IRestResponse  response = client.Execute(request);
                HttpStatusCode status   = response.StatusCode;

                Console.WriteLine(status);
                Console.WriteLine(response.Content);
            } catch (Exception e) {
                Console.WriteLine(e);
            }
        }
コード例 #4
0
ファイル: AlibabaClient.cs プロジェクト: vijayamazon/ezbob
        public IRestResponse SendDecision(JObject obj, AlibabaBusinessType businessType)
        {
            IRestResponse response;

            StringDictionary parameters = new StringDictionary();
            StringBuilder    datas      = new StringBuilder(this.urlPath);

            obj.Add(new JProperty("requestID", new Random().Next(Int32.MaxValue).ToString()));
            obj.Add(new JProperty("bankCode", "ezbob"));
            obj.Add(new JProperty("bizType", businessType.DescriptionAttr()));

            if (businessType == AlibabaBusinessType.APPLICATION_REVIEW)
            {
                obj.Remove("locOfferStatus");
                obj.Remove("locOfferAmount");
                obj.Remove("locOfferDate");
                obj.Remove("locOfferExpireDate");
                obj.Remove("locOfferCurrency");
            }
            else
            {
                obj.Remove("locApproveStatus");
                obj.Remove("locApproveAmount");
                obj.Remove("locApproveDate");
                obj.Remove("locExpireDate");
                obj.Remove("locApproveCurrency");
            }

            string json = JsonConvert.SerializeObject(obj);

            parameters.Add("data", json);

            var request = new RestRequest(this.urlPath, Method.POST);

            request.AddHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");

            // add json to POST form
            foreach (DictionaryEntry de in parameters)
            {
                request.AddParameter(de.Key.ToString(), de.Value);
                datas.Append(de.Key.ToString()).Append(de.Value);
            }

            Encoding enc = Encoding.UTF8;
            string   signature;

            using (HMACSHA1 hmacsha1 = new HMACSHA1(enc.GetBytes(this.appSecret))) {
                byte[] digest = hmacsha1.ComputeHash(datas.ToString().ToStream());
                signature = MiscUtils.ByteArr2Hex(digest).ToUpper();
                request.AddParameter("_aop_signature", signature);
            }

            request.Parameters.ForEach(s => Debug.WriteLine(s.Name + "=" + s.Value));

            var client = new RestClient(this.baseUrl);

            try {
                response = client.Post(request);
                HttpStatusCode status = response.StatusCode;
            } catch (Exception e) {
                // log error TODO
                throw new HttpException(String.Format("Failed to process request to Alibaba for customer {0}, alibabaID {1}, error: {2}", arg0: obj.GetValue("aId"), arg1: obj.GetValue("aliMemberId"), arg2: e));
            }

            return(response);
        }
コード例 #5
0
ファイル: TestAlibaba.cs プロジェクト: vijayamazon/ezbob
        public void Test_Alibaba0001_1()
        {
            //http://119.38.217.38:1680/openapi/param2/1/alibaba.open/partner.feedback/{appKey}
            String urlPath   = "param2/1/alibaba.open/partner.feedback/89978";
            String baseUrl   = "http://119.38.217.38:1680/openapi/";
            String appSecret = "IOVVt8lbOfDE";

            string        param1 = urlPath + "data{";
            StringBuilder datas  = new StringBuilder(param1);

            var request = new RestRequest(urlPath, Method.POST);

            request.AddHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");

            /*string json = @"{
             * bankCode: ""ezbob"" ,
             * ""bizType"": ""0001"",
             * ""requestID"": ""123abcd"",
             * ""aliMemberId"": ""123456789"",
             * ""aId"": ""18234"",
             * ""loanId"": ""12345678"",
             * ""requestedAmt"": 30000.00,
             * ""compName"": ""PJ Coffee Company"",
             * ""compStreetAddr1"": ""880 Boylston St."",
             * ""compStreetAddr2"": """",
             * ""compCity"": ""Boston"",
             * ""compState"": ""MA"",
             * ""compZip"": ""02199"",
             * ""compPhone"": ""6176107849"",
             * ""compEstablished"": ""2010-01-01"",
             * ""compEstablishedYears"": ""3"",
             * ""compEmployees"": 5,
             * ""compEntityType"": ""SOLE_PROPRIETOR"",
             * ""firstName"": ""Peter"",
             * ""lastName"": ""Joe"",
             * ""personalStreet1"": ""880 Boylston St."",
             * ""personalStreet2"": """",
             * ""personalCity"": ""Boston"",
             * ""personalState"": ""MA"",
             * ""personalZip"": ""02199"",
             * ""personalPhone"": ""6176107849"",
             * ""personalPhoneAlt"": """",
             * ""email"": ""*****@*****.**"",
             * ""compRevenue"": 100000.00,
             * ""compNetProfit"": 30000.00,
             * ""compCreLoans"": 0,
             * ""compRent"": 4000.00,
             * ""compOtherLoans"": 0,
             * ""compOtherLeases"": 0,
             * ""personalIncome"": 80000.00,
             * ""compOwnershipPercent"": ""50-80"",
             * ""locApproveStatus"": ""No loan"",
             * ""compType"":""bike shop"",
             * ""applicationDate"": ""2014-12-23 12:00:00 US PT"",
             * ""locOfferStatus"":""Incomplete"",
             * ""locOfferAmount"":""0"",
             * ""locOfferCurrency"":""GBP"",
             * ""locOfferDate"":""Incomplete"",
             * ""locOfferExpireDate"":""Incomplete""
             * }";*/

            /*	status 200
             * name=data, value={"bankCode": "ezbob","bizType": "0001","requestID": "123abcd","aliMemberId": "123456789",	"aId": "18234","requestedAmt": 30000.00,"countryId": "UK","locOfferStatus":"Incomplete"}
             * datas: data{"bankCode": "ezbob","bizType": "0001","requestID": "123abcd","aliMemberId": "123456789","aId": "18234","requestedAmt": 30000.00,"countryId": "UK","locOfferStatus":"Incomplete"}
             * datas finally: [param2/1/alibaba.open/partner.feedback/89978, data{"bankCode": "ezbob","bizType": "0001","requestID": "123abcd","aliMemberId": "123456789",	"aId": "18234","requestedAmt": 30000.00,"countryId": "UK","locOfferStatus":"Incomplete"}]
             * name=_aop_signature, value=F841240BCF4D7AF6F80C0EA7C31436D2B593DD08
             */

            string json = "{\"bankCode\": \"ezbob\",\"bizType\": \"0001\",\"requestID\": \"123abcd\",\"aliMemberId\": \"123456789\",\"aId\": \"18234\",\"requestedAmt\": 30000.00,\"countryId\": \"UK\",\"locOfferStatus\":\"Incomplete\"}";

            var jsonEntries = JObject.Parse(json).Properties().OrderBy(c => c.Name).ToList();

            int lastCount = jsonEntries.Count;

            foreach (var l in jsonEntries)
            {
                lastCount--;
                datas.Append(l);
                if (lastCount > 0)
                {
                    datas.Append(",");
                }
                else
                {
                    datas.Append("}");
                }
            }

            Console.WriteLine(datas.ToString());

            string finaljsonpost = JsonConvert.SerializeObject(datas.ToString().Remove(0, param1.Length - 1));

            Console.WriteLine(finaljsonpost);

            // add json to POST form
            request.AddParameter("data", finaljsonpost);

            /*
             * param2/1/alibaba.open/partner.feedback/89978data{"aId": "18234","aliMemberId": "123456789","bankCode": "ezbob","bizType": "0001","countryId": "UK","locOfferStatus": "Incomplete","requestedAmt": 30000.0,"requestID": "123abcd"}
             * "{\"aId\": \"18234\",\"aliMemberId\": \"123456789\",\"bankCode\": \"ezbob\",\"bizType\": \"0001\",\"countryId\": \"UK\",\"locOfferStatus\": \"Incomplete\",\"requestedAmt\": 30000.0,\"requestID\": \"123abcd\"}"
             * 8F02469CA5FC737D70C78661CF1CDF440E797CBF
             */

            Encoding enc = Encoding.UTF8;

            using (HMACSHA1 hmacsha1 = new HMACSHA1(enc.GetBytes(appSecret))) {
                byte[] digest    = hmacsha1.ComputeHash(datas.ToString().ToStream());
                string signature = MiscUtils.ByteArr2Hex(digest).ToUpper();
                Console.WriteLine(signature);
                request.AddParameter("_aop_signature", signature);
            }

            var client = new RestClient(baseUrl);

            try {
                IRestResponse  response = client.Post(request);
                HttpStatusCode status   = response.StatusCode;
                Console.WriteLine("====" + status);
                Console.WriteLine(response.Content);
            } catch (Exception e) {
                Console.WriteLine(e);
            }
        }