//protected static readonly string gateway_url = "http://pay.shunli18.com/gateway";//zhuanyefu //protected static readonly string gateway_url = "http://pay.zhuanyefu.com/gateway"; public BaseTask(ulong appid, DataSerializer serializer, DataSignature signer, string gateway_url) { this.appid = appid; this.serializer = serializer; this.signer = signer; this.gateway_url = gateway_url; }
public void UpdateCustomer(Customer customer) { Guid dataSignature = DataSignature.Current; if (dataSignature == Guid.Empty) { //this is an update method, so no data signature to //compare against is an exception: throw new FaultException <NoDataSignature>(new NoDataSignature()); } Customer currentState = CustomerEntityService.Load(customer); Guid currentDataSignature = DataSignature.Sign(currentState); //if the data signatures match then update: if (currentDataSignature == dataSignature) { CustomerEntityService.Update(customer); } else { //otherwise, throw concurrency violation exception: throw new FaultException <ConcurrencyViolation>(new ConcurrencyViolation()); } }
public ChinaRailwayApp(ulong id, string key, string gateway_url) { this.app_id = id; { var data_serializer = new DataSerializer(new JsonSerializerSettings() { DateFormatString = "yyyy-MM-dd HH:mm:ss.fff", NullValueHandling = NullValueHandling.Ignore, ContractResolver = new Smartunicom.Runtime.Serialization.ContractResolver.JsonSnakeCasePropertyNamesContractResolver() }); var data_signer = new RS256(); data_signer.SetPrivateKey(key); var data_signer_all = new DataSignature(data_signer, data_verifier, data_hs256); { this.order_task = new ChargeTask(this.app_id, data_serializer, data_signer_all, gateway_url); this.payment_task = new PayTask(this.app_id, data_serializer, data_signer_all, gateway_url); this.transfer_task = new TransferTask(this.app_id, data_serializer, data_signer_all, gateway_url); this.webhook_task = new WebHookTask(this.app_id, data_serializer, data_signer_all, gateway_url); this.serializer = new Serializer(data_serializer); } } }
/// <summary> /// Serializes outgoing response using the original formatter, and adding /// the computed DataSignature as a message header /// </summary> /// <param name="messageVersion"></param> /// <param name="parameters"></param> /// <param name="result"></param> /// <returns></returns> public Message SerializeReply(MessageVersion messageVersion, object[] parameters, object result) { //create the message using the standard formatter: Message reply = this.OrginalFormatter.SerializeReply(messageVersion, parameters, result); if (result != null) { //if the result is a DataContract, compute data signature //and add it as a message header: object[] attributes = result.GetType().GetCustomAttributes(typeof(DataContractAttribute), true); if (attributes != null && attributes.Length > 0) { reply.Headers.Add(DataSignature.CreateHeader(result)); } } return(reply); }
/// <summary> /// Deserializes the response message, extracting the DataSignature from the message /// headers and adding it to the XML content of the message's data payload /// </summary> /// <remarks> /// Modifies the XML payload then uses the original formatter to deserialize the message. /// If the original formatter uses DataContractSerializer then the DataContract from the /// message will have the DataSignature header value added to its ExtensionDataObject /// </remarks> /// <param name="message">Incoming message</param> /// <param name="parameters">Parameters</param> /// <returns>Deserialized object</returns> public object DeserializeReply(Message message, object[] parameters) { //get the DataSignature from the message headers: Guid dataSignature = DataSignature.GetDataSignature(message.Headers); if (dataSignature != Guid.Empty) { //TODO - replace with XLINQ XmlDictionaryReader reader = message.GetReaderAtBodyContents(); XmlDocument document = new XmlDocument(); document.Load(reader); //we add the data signature as a node under the document namespace: XmlNode resultNode = document.DocumentElement.FirstChild; XmlElement dataSignatureNode = document.CreateElement(DataSignature.ExtensionDataMember.Name, document.NamespaceURI); dataSignatureNode.InnerText = dataSignature.ToString(); resultNode.InsertAfter(dataSignatureNode, resultNode.LastChild); MemoryStream memStream = new MemoryStream(); document.Save(memStream); memStream.Position = 0; XmlDictionaryReaderQuotas quotas = new XmlDictionaryReaderQuotas(); XmlDictionaryReader xdr = XmlDictionaryReader.CreateTextReader(memStream, quotas); //replace the message - the data signature will be desrialized into //the ExtendedData property of the IExtensibleDataObject: Message replacedMessage = Message.CreateMessage(message.Version, null, xdr); replacedMessage.Headers.CopyHeadersFrom(message.Headers); replacedMessage.Properties.CopyProperties(message.Properties); message = replacedMessage; } //now use the standard formatter - DataContractSerializer will //add the new dataSignature element as an ExtensionData object: return(this.OrginalFormatter.DeserializeReply(message, parameters));; }
public WebHookTask(ulong appid, DataSerializer serializer, DataSignature signer, string gateway_url) : base(appid, serializer, signer, gateway_url) { }