linq to xml运用示例
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using XFK.LYTravel.Common.helper;
using XFK.LYTravel.Infrastructure;
using SFast;
using System.Xml.Linq;
using XFK.LYTravel.Common; namespace XFK.LYTravel.LYTravelApi.Areas.AppMain.Controllers
{
public class WXUnifiedOrderPayController : ApiController
{
public ResponseBase<WXUnifiedPayResp> Post(WXUnifiedPayReq req)
{
AppMainLogHelper.WriteLog("-----进入AppMain-WXUnifiedOrderPay接口!(/api/AppMain/WXUnifiedOrderPay)------");
AppMainLogHelper.WriteLog("入参:" + req._ToJsonStr());
ResponseBase<WXUnifiedPayResp> result = new ResponseBase<WXUnifiedPayResp>();
XElement xe = new XElement("xml",
new XElement("appid", req.appid),
new XElement("attach", req.attach),
new XElement("body", req.body),
new XElement("mch_id", req.mch_id),
new XElement("nonce_str", req.nonce_str),
new XElement("notify_url", req.notify_url),
new XElement("openid", req.openid),
new XElement("out_trade_no", req.out_trade_no),
new XElement("spbill_create_ip", req.spbill_create_ip),
new XElement("total_fee", req.total_fee),
new XElement("trade_type", req.trade_type),
new XElement("scene_info", req.scene_info),
new XElement("sign", req.sign)
);
string xmlStr = xe.ToString();
string url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
AppMainLogHelper.WriteLog(string.Format("发送微信统一下单接口,地址:{0},参数:{1}", url, xmlStr));
string strResp = TrainTicketAPI.PostWebRequest(url, xmlStr);
AppMainLogHelper.WriteLog("返回数据:" + strResp);
XElement xeRet = XElement.Parse(@strResp);
WXUnifiedPayResp resp = new WXUnifiedPayResp();
resp.return_code = xeRet.Descendants("return_code").First().Value;
resp.return_msg = xeRet.Descendants("return_msg").First().Value;
if (resp.return_code == "SUCCESS")
{
resp.appid = xeRet.Descendants("appid").First().Value;
resp.mch_id = xeRet.Descendants("mch_id").First().Value;
resp.nonce_str = xeRet.Descendants("nonce_str").First().Value;
resp.sign = xeRet.Descendants("sign").First().Value;
resp.result_code = xeRet.Descendants("result_code").First().Value;
if (resp.result_code == "SUCCESS")
{
resp.prepay_id = xeRet.Descendants("prepay_id").First().Value;
resp.trade_type = xeRet.Descendants("trade_type").First().Value;
resp.mweb_url = xeRet.Descendants("mweb_url").First().Value;
}
result.resultCode = "200";
result.IsSuccess = true;
result.Message = resp.return_msg;
result.ResultData = resp;
}
else
{
result.resultCode = "201";
result.IsSuccess = false;
result.Message = resp.return_msg;
result.ResultData = null;
} return result;
} } public class WXUnifiedPayReq
{
public string appid { get; set; }
public string attach { get; set; }
public string body { get; set; }
public string mch_id { get; set; }
public string nonce_str { get; set; }
public string notify_url { get; set; }
public string openid { get; set; }
public string out_trade_no { get; set; }
public string spbill_create_ip { get; set; }
public string total_fee { get; set; }
public string trade_type { get; set; }
public string scene_info { get; set; }
public string sign { get; set; }
} public class WXUnifiedPayResp
{
public string return_code { get; set; }
public string return_msg { get; set; }
public string appid { get; set; }
public string mch_id { get; set; }
public string nonce_str { get; set; }
public string sign { get; set; }
public string result_code { get; set; }
public string prepay_id { get; set; }
public string trade_type { get; set; }
public string mweb_url { get; set; }
}
}
参考:
http://skybirdzw.blog.163.com/blog/static/7257062620140244456725/
http://skybirdzw.blog.163.com/blog/static/72570626201402445651865/
linq to xml运用示例的更多相关文章
- C# linq to xml 简单示例
		data.xml <?xml version="1.0" encoding="utf-8" ?> <Data> <Products ... 
- LINQ for XML简单示例
		LINQ,语言集成查询(Language Integrated Query)是一组用于c#和Visual Basic语言的扩展.它允许开发人员以与查询数据库相同的方式操作内存数据.从技术角度而言,LI ... 
- LINQ系列:LINQ to XML类
		LINQ to XML由System.Xml.Linq namespace实现,该namespace包含处理XML时用到的所有类.在使用LINQ to XML时需要添加System.Xml.Linq. ... 
- LINQ系列:LINQ to XML查询
		1. 读取XML文件 XDocument和XElement类都提供了导入XML文件的Load()方法,可以读取XML文件的内容,并转换为XDocument或XElement类的实例. 示例XML文件: ... 
- [原创]Linq to xml增删改查Linq 入门篇:分分钟带你遨游Linq to xml的世界
		本文原始作者博客 http://www.cnblogs.com/toutou Linq 入门篇(一):分分钟带你遨游linq to xml的世界 本文原创来自博客园 请叫我头头哥的博客, 请尊重版权, ... 
- LINQ to XML 编程基础
		1.LINQ to XML类 以下的代码演示了如何使用LINQ to XML来快速创建一个xml: 隐藏行号 复制代码 ?创建 XML public static void CreateDocumen ... 
- Linq学习笔记---Linq to Xml操作
		LINQ to XML的成员, 属性列表: 属性 说明 Document 获取此 XObject 的 XDocument EmptySequence 获取空的元素集合 FirstAttribut ... 
- C#学习之Linq to Xml
		前言 我相信很多从事.NET开发的,在.NET 3.5之前操作XML会比较麻烦,但是在此之后出现了Linq to Xml,而今天的主人公就是Linq to Xml,废话不多说,直接进入主题. 题外:最 ... 
- C#中的Linq to Xml详解
		这篇文章主要介绍了C#中的Linq to Xml详解,本文给出转换步骤以及大量实例,讲解了生成xml.查询并修改xml.监听xml事件.处理xml流等内容,需要的朋友可以参考下 一.生成Xml 为了能 ... 
随机推荐
- vue 动态渲染数据很慢或不渲染
			vue 动态渲染数据很慢或不渲染 原因是因为vue检测速度很慢,因为多层循环了,在VUE 2.x的时候还能渲染出来,1.x的时候压根渲染不出来.解决方式:在动态改变数据的方法,第一行加上 this.$ ... 
- 【Spark机器学习速成宝典】推荐引擎——协同过滤
			目录 推荐模型的分类 ALS交替最小二乘算法:显式矩阵分解 Spark Python代码:显式矩阵分解 ALS交替最小二乘算法:隐式矩阵分解 Spark Python代码:隐式矩阵分解 推荐模型的分类 ... 
- 在HearthRanger中使用Silverfish
			I'm new here and have never used this bot before. But a few days ago I tried it and I liked it :) I ... 
- Android性能优化-电量优化
			前言 电量优化,这个名词在传统PC时代,我们基本很少听见.然而到了诺基亚时代,我们也同样很少关注.直到了移动互联的智能机时代.电量优化才被慢慢的重视起来.可能的原因如下: 移动设备,不能一直使用电源供 ... 
- 使用Fiddler抓取在夜神模拟器上的请求
			一.设置Fiddler代理 1.点击Tools-Fiddler Options进入Fiddler Options页面 2.点击Connections,将Fiddler listens on port设 ... 
- 004-Spring boot 快速入门-项目搭建与启动、SpringBootApplication、启动图标
			一.官方地址 Spring:http://spring.io/ Spring Project:http://spring.io/projects Spring boot:https://project ... 
- [转]Java Jacob操作Excel
			Jacob项目:https://sourceforge.net/projects/jacob-project/ 转自:https://blog.csdn.net/ZY_extreme/article/ ... 
- NLP基础
			1 自然语言处理三大特征抽取器(CNN/RNN/TF)比较 白衣骑士Transformer:盖世英雄站上舞台 华山论剑:三大特征抽取器比较 综合排名情况 以上介绍内容是从几个不同角度来对RNN/CN ... 
- Linux下Apache虚拟主机配置
			Linux下Apache虚拟主机的三种配置.这样可以实现一台主机架构多个独立域名网站.其中基于域名的最为常见.性价比也最高.下面PHP程序员雷雪松详细的讲解下Linux下Apache虚拟主机配置的具体 ... 
- Linux 操作系统常用命令
			常用命令详解 ls 常用选项: -a:列出所有文件,包括以.为开头的隐藏文件. -d ; 列出目录本身,并不包含目录里的内容. -h:和-l一起使用,文件大小容易阅读.文件的实际大小 ls -d/ro ... 
