|
|
using HuizhongLibrary.Log;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Security.Cryptography;
|
|
|
using System.Text;
|
|
|
using WxPayAPI;
|
|
|
|
|
|
namespace HuizhongLibrary.PhonePay
|
|
|
{
|
|
|
public class WeiXinPay
|
|
|
{
|
|
|
public string url { get; set; }
|
|
|
public string key { get; set; }
|
|
|
//https://api.mch.weixin.qq.com/pay/unifiedorder
|
|
|
|
|
|
public WeiXinPay()
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// openid用于调用统一下单接口
|
|
|
/// </summary>
|
|
|
public string openid { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
|
/// access_token用于获取收货地址js函数入口参数
|
|
|
/// </summary>
|
|
|
public string access_token { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
|
/// 商品金额,用于统一下单
|
|
|
/// </summary>
|
|
|
public int total_fee { get; set; }
|
|
|
public string trade_type { get; set; }
|
|
|
/// <summary>
|
|
|
/// 统一下单接口返回结果
|
|
|
/// </summary>
|
|
|
public WxPayData unifiedOrderResult { get; set; }
|
|
|
public WxPayData GetUnifiedOrderResult()
|
|
|
{
|
|
|
//统一下单
|
|
|
WxPayData data = new WxPayData();
|
|
|
data.SetValue("body", "test");
|
|
|
data.SetValue("attach", "test");
|
|
|
data.SetValue("out_trade_no", WxPayApi.GenerateOutTradeNo());
|
|
|
data.SetValue("total_fee", total_fee);
|
|
|
data.SetValue("time_start", DateTime.Now.ToString("yyyyMMddHHmmss"));
|
|
|
data.SetValue("time_expire", DateTime.Now.AddMinutes(10).ToString("yyyyMMddHHmmss"));
|
|
|
data.SetValue("goods_tag", "test");
|
|
|
data.SetValue("trade_type", trade_type);
|
|
|
data.SetValue("openid", openid);
|
|
|
ErrorFollow.TraceWrite("GetUnifiedOrderResult", "openid:", openid);
|
|
|
WxPayData result = WxPayApi.UnifiedOrder(data);
|
|
|
if (!result.IsSet("appid") || !result.IsSet("prepay_id") || result.GetValue("prepay_id").ToString() == "")
|
|
|
{
|
|
|
ErrorFollow.TraceWrite("GetUnifiedOrderResult",this.GetType().ToString(), "UnifiedOrder response error!");
|
|
|
// Log.Error(this.GetType().ToString(), "UnifiedOrder response error!");
|
|
|
// throw new WxPayException("UnifiedOrder response error!");
|
|
|
}
|
|
|
|
|
|
unifiedOrderResult = result;
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
public string unifiedorder(WeiXinPayModel model)
|
|
|
{
|
|
|
//StringBuilder sb = new StringBuilder();
|
|
|
//sb.Append("<xml>");
|
|
|
//sb.Append("<appid>"+model.appid+"</appid>");
|
|
|
//sb.Append("<attach>"+model.attach+"</attach>");
|
|
|
//sb.Append("<body>"+model.body+"</body>");
|
|
|
//sb.Append("<mch_id>" + model.mch_id + "</mch_id>");
|
|
|
//sb.Append("<nonce_str>" + model.nonce_str + "</nonce_str>");
|
|
|
//sb.Append("< notify_url >"+model.notify_url+"</notify_url>");
|
|
|
//if(model.openid!=null&&model.openid!="")
|
|
|
//sb.Append("<openid>"+ model.openid + "</openid>");
|
|
|
//sb.Append("<out_trade_no>"+model.out_trade_no+"</out_trade_no>");
|
|
|
//sb.Append("<spbill_create_ip>"+model.spbill_create_ip+"</spbill_create_ip>");
|
|
|
//sb.Append("<total_fee >"+model.total_fee+"</total_fee>");
|
|
|
//sb.Append("<spbill_create_ip>" + model.spbill_create_ip + "</spbill_create_ip>");
|
|
|
//sb.Append("<trade_type>"+model.trade_type+"</trade_type>");
|
|
|
//sb.Append("<scene_info>{ \"h5_info\": { \"type\":"+model.scene_info.h5_info.type + ",\"wap_name\": " + model.scene_info.h5_info.wap_name + ",\"wap_url\": " + model.scene_info.h5_info.wap_url+"} }</scene_info>");
|
|
|
//sb.Append("<sign>"+model.sign+"</sign>");
|
|
|
//sb.Append("</xml>");
|
|
|
|
|
|
|
|
|
return "";
|
|
|
|
|
|
//< appid > wx2421b1c4370ec43b </ appid >
|
|
|
//< attach > 支付测试 </ attach >
|
|
|
//< body > H5支付测试 </ body >
|
|
|
//< mch_id > 10000100 </ mch_id >
|
|
|
//< nonce_str > 1add1a30ac87aa2db72f57a2375d8fec </ nonce_str >
|
|
|
|
|
|
// < notify_url > http://wxpay.wxutil.com/pub_v2/pay/notify.v2.php</notify_url>
|
|
|
//< openid > oUpF8uMuAJO_M2pxb1Q9zNjWeS6o </ openid >
|
|
|
//< out_trade_no > 1415659990 </ out_trade_no >
|
|
|
//< spbill_create_ip > 14.23.150.211 </ spbill_create_ip >
|
|
|
|
|
|
// < total_fee > 1 </ total_fee >
|
|
|
|
|
|
// < trade_type > MWEB </ trade_type >
|
|
|
|
|
|
// < scene_info >{ "h5_info": { "type":"IOS","app_name": "王者荣耀","package_name": "com.tencent.tmgp.sgame"} }</ scene_info >
|
|
|
|
|
|
// < sign > 0CB01533B8C1EF103065174F50BCA001 </ sign >
|
|
|
|
|
|
// </ xml >
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public class WeiXinPayModel
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public string appid { get; set; }
|
|
|
public string attach { get; set; }
|
|
|
public string mch_id { get; set; }
|
|
|
public string body { 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 scene_info scene_info { get; set; }
|
|
|
public string sign { get; set; }
|
|
|
}
|
|
|
|
|
|
public class scene_info
|
|
|
{
|
|
|
//{"h5_info": {"type":"Wap","wap_url": "https://pay.qq.com","wap_name": "腾讯充值"}}
|
|
|
public h5_info h5_info { get; set; }
|
|
|
}
|
|
|
|
|
|
public class h5_info
|
|
|
{
|
|
|
|
|
|
public string type { get; set; }
|
|
|
public string wap_url { get; set; }
|
|
|
public string wap_name { get; set; }
|
|
|
}
|
|
|
|
|
|
public class Return_info
|
|
|
{
|
|
|
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 prepay_id { get; set; }
|
|
|
public string trade_type { get; set; }
|
|
|
public string mweb_url { get; set; }
|
|
|
// <xml>
|
|
|
// <return_code><![CDATA[SUCCESS]]></return_code>
|
|
|
// <return_msg><![CDATA[OK]]></return_msg>
|
|
|
// <appid><![CDATA[wx2421b1c4370ec43b]]></appid>
|
|
|
// <mch_id><![CDATA[10000100]]></mch_id>
|
|
|
// <nonce_str><![CDATA[IITRi8Iabbblz1Jc]]></nonce_str>
|
|
|
// <sign><![CDATA[7921E432F65EB8ED0CE9755F0E86D72F]]></sign>
|
|
|
// <result_code><![CDATA[SUCCESS]]></result_code>
|
|
|
// <prepay_id><![CDATA[wx201411101639507cbf6ffd8b0779950874]]></prepay_id>
|
|
|
// <trade_type><![CDATA[MWEB]]></trade_type>
|
|
|
// <mweb_url><![CDATA[https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb?prepay_id=wx2016121516420242444321ca0631331346&package=1405458241]]></mweb_url>
|
|
|
//</xml>
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|