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 为了能 ...
随机推荐
- adb、pm命令操作apk包
1.adb shell pm list package 打印出来所有安装到手机上的APP包名 2.adb shell pm path com.xxx.xxx 找出安装后的包名应用的apk所在位置 3. ...
- 前端知识点回顾之重点篇——CSS中的BFC
BFC布局(Block Formatting Contexts) 来源:https://www.cnblogs.com/lzbk/p/6057097.html 块级格式化上下文是页面中的一块渲染区域, ...
- Android中图片优化
1.对图片进行压缩:建议使用TinyPNG工具压缩 2.WebP格式(支持4.0以上)可减少文件大小 3.尽量使用NinePatch的PNG 4.图片缓存
- C++代码匈牙利命名规范
一.类 除了异常类等个别情况(不希望用户把该类看作一个普通的.正常的类之情况)外,C++类/结构的命名应该遵循以下准则: C++类的命名 类的名称都要以大写字母“C”开头,后跟一个或多个单词.为 ...
- python之scrapy的debug、shell、settings、pipelines
1.debug了解 2.scrapy shell了解 Scrapy shell是一个交互终端,我们可以在未启动spider的情况下尝试及调试代码,也可以用来测试XPath表达式 使用方法: scrap ...
- 机器学习之DBSCAN聚类算法
可以看该博客:https://www.cnblogs.com/aijianiula/p/4339960.html 1.知识点 """ 基本概念: 1.核心对象:某个点的密 ...
- chrome调试笔记
F12启动调试 1.右键加载按钮可以清空缓存并重新加载,有时候浏览器有缓存,代码更新不会及时反映出来. 2.performance mointer实时查看performance 点击三个竖着的小点,选 ...
- 阿里云安装 fastdfs 总结
还要开放 23000 22122,添加进安全组
- Java集合(4):未获支持的操作及UnsupportedOperationException
执行各种添加和移除的方法在Collection中都是可选操作的,这意味着实现类并不需要为这些方法提供实现.当我们调用这些方法时,将不会执行有意义的行为,而是通常抛出UnsupportedOperati ...
- BN和L2 NORM的区别
bn是拉平各个feature的差异,而l2 norm是拉平各个样本的差异,本来各个样本的模长千变万化,按照距离的概念,差别是很大的,但是l2 norm后,距离就变得有一个上界了,显然样本间差异变小了. ...