Ejemplo n.º 1
0
 public DataSharing(int customerID, AlibabaBusinessType businessType)
 {
     CustomerID        = customerID;
     this.businessType = businessType;
     Result            = new CustomerDataSharing();
     this.sentDataRep  = ObjectFactory.GetInstance <AlibabaSentDataRepository>();
 }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
		public ActionMetaData DataSharing(int customerID, AlibabaBusinessType businessType, int? uwId) {
			Log.Info("ESI: customerID: {0}, finalDecision: {1}", customerID, businessType);
			return Execute<DataSharing>(customerID, uwId, customerID, businessType);
		} // DataSharing
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="aliMember"></param>
        /// <param name="result"></param>
        /// <param name="bizType"></param>
        private void SendRequest(AlibabaBuyer aliMember, CustomerDataSharing result, AlibabaBusinessType bizType)
        {
            if (result == null)
            {
                return;
            }
            if (aliMember == null)
            {
                return;
            }
            if (result.aliMemberId == 0)
            {
                return;
            }
            if (string.IsNullOrEmpty(result.aId))
            {
                return;
            }

            try {
                AlibabaClient client;

                if (CurrentValues.Instance.AlibabaClientEnvironment != null && CurrentValues.Instance.AlibabaClientEnvironment.Value.Contains("Sandbox"))
                {
                    client = new AlibabaClient(CurrentValues.Instance.AlibabaBaseUrl_Sandbox, CurrentValues.Instance.AlibabaUrlPath_Sandbox, CurrentValues.Instance.AlibabaAppSecret_Sandbox);
                }
                else
                {
                    client = new AlibabaClient(CurrentValues.Instance.AlibabaBaseUrl, CurrentValues.Instance.AlibabaUrlPath, CurrentValues.Instance.AlibabaAppSecret);
                }

                IRestResponse response = client.SendDecision(JObject.FromObject(result, new JsonSerializer {
                    DateParseHandling = DateParseHandling.None
                }), bizType);

                AlibabaSentData sent = new AlibabaSentData();
                sent.AlibabaBuyer = aliMember;
                sent.Customer     = sent.AlibabaBuyer.Customer;
                sent.Request      = JsonConvert.SerializeObject(response.Request.Parameters);
                sent.Response     = response.Content;

                var jsonContent = JsonConvert.DeserializeObject(response.Content);
                var objContent  = JObject.Parse(jsonContent.ToString());

                var errCode = objContent.Properties().FirstOrDefault(c => c.Name == "errCode");
                if (errCode != null)
                {
                    sent.ErrorCode = errCode.Value.ToString();
                }

                var errMsg = objContent.Properties().FirstOrDefault(c => c.Name == "errMsg");
                if (errMsg != null)
                {
                    sent.ErrorMessage = errMsg.Value.ToString();
                }

                var signature = response.Request.Parameters.FirstOrDefault(p => p.Name == "_aop_signature");
                if (signature != null)
                {
                    sent.Signature = signature.Value.ToString();
                }

                var btype = objContent.Properties().FirstOrDefault(c => c.Name == "bizType");
                if (btype != null)
                {
                    sent.BizTypeCode = btype.Value.ToString();
                }

                //Add comments
                switch (bizType)
                {
                case AlibabaBusinessType.APPLICATION_WS_3:
                    sent.Comments = "DataSharing Step 3";
                    break;

                case AlibabaBusinessType.APPLICATION:
                    sent.Comments = "DataSharing Wizard Complete";
                    break;
                }

                sent.StatusCode = response.StatusCode.DescriptionAttr();
                sent.SentDate   = DateTime.UtcNow;
                this.sentDataRep.Save(sent);
            } catch (HttpException e) {
                throw new StrategyAlert(this, string.Format("HttpException: Failed to transmit for customer {0}, CustomerDataSharing: {1}, alimember:{2}", CustomerID, result.Stringify(), aliMember.AliId), e);
            } catch (Exception ex) {
                throw new StrategyAlert(this, string.Format("Failed to transmit for customer {0}, CustomerDataSharing: {1}, alimember:{2}", CustomerID, result.Stringify(), aliMember.AliId), ex);
            }
        }