代码:

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运用示例的更多相关文章

  1. C# linq to xml 简单示例

    data.xml <?xml version="1.0" encoding="utf-8" ?> <Data> <Products ...

  2. LINQ for XML简单示例

    LINQ,语言集成查询(Language Integrated Query)是一组用于c#和Visual Basic语言的扩展.它允许开发人员以与查询数据库相同的方式操作内存数据.从技术角度而言,LI ...

  3. LINQ系列:LINQ to XML类

    LINQ to XML由System.Xml.Linq namespace实现,该namespace包含处理XML时用到的所有类.在使用LINQ to XML时需要添加System.Xml.Linq. ...

  4. LINQ系列:LINQ to XML查询

    1. 读取XML文件 XDocument和XElement类都提供了导入XML文件的Load()方法,可以读取XML文件的内容,并转换为XDocument或XElement类的实例. 示例XML文件: ...

  5. [原创]Linq to xml增删改查Linq 入门篇:分分钟带你遨游Linq to xml的世界

    本文原始作者博客 http://www.cnblogs.com/toutou Linq 入门篇(一):分分钟带你遨游linq to xml的世界 本文原创来自博客园 请叫我头头哥的博客, 请尊重版权, ...

  6. LINQ to XML 编程基础

    1.LINQ to XML类 以下的代码演示了如何使用LINQ to XML来快速创建一个xml: 隐藏行号 复制代码 ?创建 XML public static void CreateDocumen ...

  7. Linq学习笔记---Linq to Xml操作

    LINQ to XML的成员, 属性列表: 属性 说明 Document 获取此 XObject 的 XDocument  EmptySequence  获取空的元素集合  FirstAttribut ...

  8. C#学习之Linq to Xml

    前言 我相信很多从事.NET开发的,在.NET 3.5之前操作XML会比较麻烦,但是在此之后出现了Linq to Xml,而今天的主人公就是Linq to Xml,废话不多说,直接进入主题. 题外:最 ...

  9. C#中的Linq to Xml详解

    这篇文章主要介绍了C#中的Linq to Xml详解,本文给出转换步骤以及大量实例,讲解了生成xml.查询并修改xml.监听xml事件.处理xml流等内容,需要的朋友可以参考下 一.生成Xml 为了能 ...

随机推荐

  1. Flume-事务与传输流程

    一.Flume 事务 流程图 Put 事务流程 doPut:将批数据先写入临时缓冲区 putList doCommit:检查 channel 内存队列是否足够合并 doRollback:channel ...

  2. babel 实践

    一.@babel/core var babel = require("@babel/core");babel.transform(code, options, function(e ...

  3. leetcode39 组合总和

    这道题想到的就是dfs,在累加的和大于或等于target时到达递归树的终点. 代码如下: class Solution { public: vector<vector<int>> ...

  4. C++中.cpp和.hpp的区别

    原文地址:https://blog.csdn.net/qzx9059/article/details/89210571 c++中 cpp和hpp我们可以将所有东西都放在一个.cpp文件内,编译器会将这 ...

  5. linux文件结构---转发

    linux各文件夹的作用---转载   linux下的文件结构,看看每个文件夹都是干吗用的/bin 二进制可执行命令 /dev 设备特殊文件 /etc 系统管理和配置文件 /etc/rc.d 启动的配 ...

  6. 九十一:CMS系统之cms用户模型定义

    数据库信息 DEBUG = TrueSQLALCHEMY_DATABASE_URI = 'mysql+pymysql://root:123456@127.0.0.1:3306/test'SQLALCH ...

  7. TCP/IP 和 和 DoD 模型

    TCP/IP 模型也被称作 DoD 模型(Department of Defense Model).TCP/IP 字面上代表了两个协议:TCP(传输控制协议)和 IP(网络之间互联协议).TCP/IP ...

  8. IPv4 ping命令

    IPv4 ping命令 一.Linux操作系统 给一台 Linux 主机分配了一个 IPv4 的 IP地址,如何使用 ping命令 确定该 IP地址 能否 ping 通呢? 1.查看主机的 IPv4 ...

  9. php进程创建慢导致的502

    转自: 作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除地址:http://www.jackxiang.com/post/926 ...

  10. 【JVM学习笔记】Class.forName方法学习

    三个参数的版本的源代码如下 doc文档翻译 使用给定的类加载器(即第3个参数)返回与具有给定字符串名称(第1个参数)的类或接口关联的Class对象.给定类或接口的完全限定名称(以getName返回的相 ...