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 为了能 ...
随机推荐
- (转)ON DUPLICATE KEY UPDATE --mysql的一个有趣语法
转自:http://my.oschina.net/iceman/blog/53735?fromerr=3kAEPcQr 如果在INSERT语句末尾指定了ON DUPLICATE KEY UPDATE, ...
- centos7最小安装怎么安装防火墙
CentOS 7.0默认使用的是firewall作为防火墙,需要事先关闭. 关闭firewall: 1 2 3 systemctl stop firewalld.service systemctl d ...
- 质量保障&&质量体系建设
一.质量保障 先引用一段 百度百科 上对软件质量保障的解释:软件质量保障是建立一套有计划,系统的方法,来向管理层保证拟定出的标准.步骤.实践和方法能够正确地被项目所采用.软件质量保证的目的是使软件过程 ...
- [转]html里a标签中href调用js的几种方法
文章转自:https://blog.csdn.net/best_luxi/article/details/45062301 我们常用的在a标签中有点击事件: 1. a href=”javascript ...
- 1. hadoop使用启动命令时报错之分析解决
今天在学习hadoop启动命令的时候,先jps看了下,发现namenode.datanode都开着,所以想要先停止这些服务,结果输入命令后报错:“WARN util.NativeCodeLoader: ...
- 【AMAD】django-cities -- 为Django项目提供国家,城市数据
动机 简介 个人评分 动机 有时候看一些数据库设计,国家数据会存在一个单独的表里面.这种方式读取数据库无疑又要加上一层join,很不划算. 简介 [django-cities]1可用为你提供国家和城市 ...
- pubwin扫描安装
1,注意顺序 先安装一代 FS533 2,在安装精伦 3,在重新注册 PUBWIN 如果还不行一般是注册商没给注册好
- A Mixed Flash Translation Layer Structure for SLC-MLC Combined Flash Memory System
http://blog.sina.com.cn/s/blog_502c8cc40100pztk.html 摘要 1.In this paper, we propose the SLC-MLC mixe ...
- Linux文件属性之Linux文件删除重要原理详解
Linux下文件删除的原理 只要dongdaxiafile(源文件).服务进程.dongdaxiaflie_hard_link(硬链接文件)三个中的任意一个存在文件不会被删除.
- [bzoj1775][Usaco2009 Dec]Vidgame 电视游戏问题_背包dp
1775: [Usaco2009 Dec]Vidgame 电视游戏问题 题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1775 题解: 发 ...