62,046
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Web;
using tenpay;
namespace OKXR.Payment
{
public class TenPayRMB
{
// Methods
public string GetPayUrl(string okxrorderid, double amount, HttpContext Context, string bankType = "DEFAULT")
{
PayKeyFactory _paykey = new PayKeyFactory();
_paykey.ptype = 100;
_paykey.GetModel();
string bargainor_id = _paykey.puserid;
string key = _paykey.puserkey;
string date = DateTime.Now.ToString("yyyyMMdd");
string strReq = "" + DateTime.Now.ToString("HHmmss") + TenpayUtil.BuildRandomStr(4);
string sp_billno = okxrorderid;
string transaction_id = bargainor_id + date + strReq;
string return_url = "http://" + Configuration.GetConfig().SiteDomain + "/wvvwpay/Ten_Return.aspx";
string spbill_create_ip = getRealIp();
PayRequestHandler reqHandler = new PayRequestHandler(Context);
reqHandler.setKey(key);
reqHandler.init();
reqHandler.setParameter("bargainor_id", bargainor_id);
reqHandler.setParameter("sp_billno", sp_billno);
reqHandler.setParameter("transaction_id", transaction_id);
reqHandler.setParameter("return_url", return_url);
reqHandler.setParameter("desc", "orderId:" + transaction_id);
reqHandler.setParameter("total_fee", Convert.ToString((double)(amount * 100.0)));
reqHandler.setParameter("bank_type", bankType); //银行类型(中介担保时此参数无效)
reqHandler.setParameter("spbill_create_ip", getRealIp());
return reqHandler.getRequestURL();
}
public static string getRealIp()
{
if (HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null)
{
return HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
}
return HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();
}
public void Return(HttpContext Context)
{
PayKeyFactory _paykey = new PayKeyFactory();
_paykey.ptype = 100;
_paykey.GetModel();
string key = _paykey.puserkey;
PayResponseHandler resHandler = new PayResponseHandler(Context);
resHandler.setKey(key);
if (resHandler.isTenpaySign())
{
string transaction_id = resHandler.getParameter("transaction_id");
string total_fee = resHandler.getParameter("total_fee");
string pay_result = resHandler.getParameter("pay_result");
string sp_billno = resHandler.getParameter("sp_billno");
if ("0".Equals(pay_result))
{
decimal _amount = 0M;
decimal.TryParse(total_fee, out _amount);
ulong _okxrorderid = 0;
ulong.TryParse(sp_billno, out _okxrorderid);
PayMentFactory.PayOrder(transaction_id, _okxrorderid, _amount / 100M);
resHandler.doShow("http://" + Configuration.GetConfig().SiteDomain + "/Ten/show_url.aspx");
}
else
{
HttpContext.Current.Response.Write("支付失败");
}
}
else
{
HttpContext.Current.Response.Write("认证签名失败");
}
}
}
}