public class JsEntities { /// <summary> /// 公众号id /// </summary> public string appId { get; set; } /// <summary> /// 时间戳 /// </summary> public string timeStamp { get; set; } /// <summary> /// 随机字符串 /// </summary> public string nonceStr { get; set; } /// <summary> /// 订单详情扩展字符串 /// </summary> public string package { get; set; } /// <summary> /// 签名类型 /// </summary> public string signType { get; set; } /// <summary> /// 签名 /// </summary> public string paySign { get; set; } }
public class UnifyEntities { /// <summary> /// 公众账号ID /// </summary> public string appid { get; set; } /// <summary> /// 微信支付分配的商户号 /// </summary> public string mch_id { get; set; } /// <summary> /// 微信支付分配的终端设备号 /// </summary> public string device_info { get; set; } /// <summary> /// 随机字符串,不长于32位 /// </summary> public string nonce_str { get; set; } /// <summary> /// 签名 /// </summary> public string sign { get; set; } /// <summary> /// 商品描述最大长度127 /// </summary> public string body { get; set; } /// <summary> /// 附加数据,原样返回 /// </summary> public string attach { get; set; } /// <summary> /// 商户系统内部的订单号,32 个字符内、可包含字母,确保在商户系统唯一,详细说明 /// </summary> public string out_trade_no { get; set; } /// <summary> /// 订单总金额,单位为分,不能带小数点 /// </summary> public string total_fee { get; set; } /// <summary> /// 终端IP /// </summary> public string spbill_create_ip { get; set; } /// <summary> /// 交易起始时间 /// </summary> public string time_start { get; set; } /// <summary> /// 交易结束时间 /// </summary> public string time_expire { get; set; } /// <summary> /// 接收微信支付成功通知 /// </summary> public string notify_url { get; set; } /// <summary> /// JSAPI、NATIVE、APP /// </summary> public string trade_type { get; set; } /// <summary> /// 用户在商户appid下的唯一标识,trade_type为JSAPI 时,此参数必传 /// </summary> public string openid { get; set; } /// <summary> /// 只在 trade_type 为 NATIVE 时需要填写。此id为二维码中包含的商品ID,商户自行维护。 /// </summary> public string product_id { get; set; } }
public class UnifyReceive { /// <summary> /// SUCCESS/FAIL此字段是通信标识,非交易标识,交易是否成功需要查看result_code来判断 /// </summary> public string return_code { get; set; } /// <summary> /// 返回信息,如非空,为错误原因 /// </summary> public string return_msg { get; set; } /// <summary> /// 微信分配的公众账号ID /// </summary> public string appid { get; set; } /// <summary> /// 微信支付分配的商户号 /// </summary> public string mch_id { get; set; } /// <summary> /// 随机字符串,不长于32位 /// </summary> public string nonce_str { get; set; } /// <summary> /// 签名 /// </summary> public string sign { get; set; } /// <summary> /// 业务结果 /// </summary> public string result_code { get; set; } /// <summary> /// 预支付ID /// </summary> public string prepay_id { get; set; } /// <summary> /// 交易类型 /// </summary> public string trade_type { get; set; } /// <summary> /// 二维码链接 /// </summary> public string code_url { get; set; } public UnifyReceive(string xml) { XElement doc = XElement.Parse(xml); return_code = doc.Element("return_code").Value; return_msg = doc.Element("return_msg").Value; if (return_code == "SUCCESS") { appid = doc.Element("appid").Value; mch_id = doc.Element("mch_id").Value; nonce_str = doc.Element("nonce_str").Value; sign = doc.Element("sign").Value; result_code = doc.Element("result_code").Value; if (result_code == "SUCCESS") { trade_type = doc.Element("trade_type").Value; prepay_id = doc.Element("prepay_id").Value; if (trade_type == "NATIVE") { code_url = doc.Element("code_url").Value; } trade_type = doc.Element("trade_type").Value; } } } }
TestJs.aspx内容:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="JsPay.aspx.cs" Inherits="WeChatPayDemo.JsPay" %> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <script src="https://code.jquery.com/jquery-1.9.0.js"></script> <script src="https://www.jb51.net/Scripts/wxpay.js"></script> <script> $(function () { $("#submit").click(function () { var OID ="<%=openid%>"; alert(OID); $.get("WxPay/WxPay.ashx?action=jspayparam", { body: $("#body").val(), total_fee: $("#price").val(), out_trade_no: $("#order").val(), trade_type: "JSAPI", msgid: "<%=openid%>" }, function (data) { WxPay.Pay(data.appId, data.timeStamp, data.nonceStr, data.package, data.signType, data.paySign, function () { alert("支付成功"); }); }, "json"); }); }) </script> </head> <body> <form runat="server"> <div> 商品描述:<input type="text" /> 商品价格:<input type="text" /> 订单号:<input type="text" /> <input type="button" value="提交订单" /> </div> </form> </body> </html>
JsPay.aspx.cs代码: