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()
{
}
///
/// openid用于调用统一下单接口
///
public string openid { get; set; }
///
/// access_token用于获取收货地址js函数入口参数
///
public string access_token { get; set; }
///
/// 商品金额,用于统一下单
///
public int total_fee { get; set; }
public string trade_type { get; set; }
///
/// 统一下单接口返回结果
///
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("");
//sb.Append(""+model.appid+"");
//sb.Append(""+model.attach+"");
//sb.Append(""+model.body+"");
//sb.Append("" + model.mch_id + "");
//sb.Append("" + model.nonce_str + "");
//sb.Append("< notify_url >"+model.notify_url+"");
//if(model.openid!=null&&model.openid!="")
//sb.Append(""+ model.openid + "");
//sb.Append(""+model.out_trade_no+"");
//sb.Append(""+model.spbill_create_ip+"");
//sb.Append(""+model.total_fee+"");
//sb.Append("" + model.spbill_create_ip + "");
//sb.Append(""+model.trade_type+"");
//sb.Append("{ \"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+"} }");
//sb.Append(""+model.sign+"");
//sb.Append("");
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
//< 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; }
//
//
//
//
//
//
//
//
//
//
//
//
}
}