/// <summary> /// 获取AliPay的支付跳转URL /// </summary> /// <param name="pRequest"></param> /// <returns></returns> public static AliPayWapQueryOrderResponse GetQueryTradeResponse(AliPayWapTokenRequest pRequest, AliPayChannel pChannel) { AliPayWapQueryOrderResponse orderresponse = new AliPayWapQueryOrderResponse(); var str = BaseGeteway.GetResponseStr(pRequest, Geteway); if (!string.IsNullOrEmpty(pChannel.RSA_PublicKey)) { var token = Res_dataDecrypt(str, pChannel, pRequest.InputCharset); } TokenResponse response = new TokenResponse(); var tempdic = AliPayFunction.ParseResponse(str, pRequest.SecID, pChannel.RSA_PrivateKey, pRequest.InputCharset); response.Load(tempdic); orderresponse.TokenResponse = response; AliPayWapQueryTradeRequest tradeRequeset = new AliPayWapQueryTradeRequest(pChannel) { RequestToken = response.Token }; orderresponse.RedirectURL = CreateUrl(tradeRequeset); orderresponse.IsSucess = !string.IsNullOrEmpty(response.ResData); if (!orderresponse.IsSucess) { orderresponse.Message = response.ResError; } return(orderresponse); }
public void TestTrade() { AliPayWapTokenRequest request = new AliPayWapTokenRequest(channel) { CallBackUrl = "http://115.29.186.161:9004/AlipayWapTrade2/Call_Back.aspx", NotifyUrl = "http://115.29.186.161:9004/AlipayWapTrade2/Notify.aspx", OutTradeNo = Guid.NewGuid().ToString().Replace("-", ""), Partner = AliPayConfig.Partner_Royalty, ReqID = Guid.NewGuid().ToString().Replace("-", ""), Subject = "测试fasdf", TotalFee = "0.01", SellerAccountName = AliPayConfig.Seller_Account_Name_Royalty, }; var URL = AliPayWapGeteway.GetQueryTradeResponse(request, channel); }
public void TestGetToken() { AliPayWapTokenRequest request = new AliPayWapTokenRequest(channel) { CallBackUrl = "http://112.124.43.61:7777/AliPay/WebForm1.aspx", NotifyUrl = "http://115.29.186.161:9004/AlipayWapTrade2/Notify.aspx", OutTradeNo = Guid.NewGuid().ToString().Replace("-", ""), Partner = channel.Partner, ReqID = Guid.NewGuid().ToString().Replace("-", ""), Subject = "测试fasdf", TotalFee = "0.01", SellerAccountName = "*****@*****.**", }; var t = AliPayWapGeteway.GetQueryTradeResponse(request, channel); Console.WriteLine(t); }
protected void Button1_Click(object sender, EventArgs e) { var total_fee = Request["total_fee"]; var subject = Request["subject"]; AliPayChannel channel = new AliPayChannel(); AliPayWapTokenRequest request = new AliPayWapTokenRequest(channel) { CallBackUrl = "http://115.29.186.161:9004/AlipayWapTrade2/Call_Back.aspx", NotifyUrl = "http://112.124.43.61:7777/AliPay/NotifyFrm.aspx", OutTradeNo = Guid.NewGuid().ToString().Replace("-", ""), ReqID = Guid.NewGuid().ToString().Replace("-", ""), Subject = string.IsNullOrEmpty(subject) ? "测试" : subject, TotalFee = string.IsNullOrEmpty(total_fee) ? "0.03" : total_fee, SellerAccountName = AliPayConfig.Seller_Account_Name_Royalty, }; var t = AliPayWapGeteway.GetQueryTradeResponse(request, channel); this.Label1.Text = t.RedirectURL; }
/// <summary> /// 记录请求支付日志信息 /// </summary> /// <param name="response"></param> /// <param name="para"></param> /// <param name="bll"></param> /// <param name="entity"></param> /// <param name="channel"></param> /// <returns></returns> private static string CreatePayRecord(CreateOrderResponse response, CreateOrderParameters para, AppOrderBLL bll, AppOrderEntity entity, PayChannelEntity channel) { string url = string.Empty; //用于记录支付平台的请求和响应 string requestJson = string.Empty; string responseJson = string.Empty; var recordBll = new PayRequestRecordBLL(new Utility.BasicUserInfo()); var recordEntity = new PayRequestRecordEntity() { ChannelID = channel.ChannelID, ClientID = entity.AppClientID, UserID = entity.AppUserID }; #region 根据Channel类型创建支付订单 try { switch (channel.PayType) { case 1: recordEntity.Platform = 1; #region 银联Wap支付 UnionPayChannel unionWapPaychannel = channel.ChannelParameters.DeserializeJSONTo <UnionPayChannel>(); PreOrderRequest Wapreq = new PreOrderRequest() { BackUrl = ConfigurationManager.AppSettings["UnionPayWapNotifyUrl"].Trim('?') + string.Format("?ChannelID={0}", channel.ChannelID), FrontUrl = string.IsNullOrEmpty(para.ReturnUrl) ? ConfigurationManager.AppSettings["UnionPayCallBackUrl"] : para.ReturnUrl, MerchantID = unionWapPaychannel.MerchantID, SendTime = DateTime.Now, MerchantOrderCurrency = Currencys.RMB, MerchantOrderDesc = entity.AppOrderDesc, MerchantOrderAmt = entity.AppOrderAmount, MerchantOrderID = entity.OrderID.ToString(), SendSeqID = Guid.NewGuid().ToString("N"), MerchantOrderTime = entity.AppOrderTime }; requestJson = Wapreq.ToJSON(); var unionWapResponse = JIT.Utility.Pay.UnionPay.Interface.Wap.WapGateway.PreOrder(unionWapPaychannel, Wapreq); responseJson = unionWapResponse.ToJSON(); if (unionWapResponse.IsSuccess) { entity.PayUrl = unionWapResponse.RedirectURL; entity.Status = 1; bll.Update(entity); url = unionWapResponse.RedirectURL; Loggers.Debug(new DebugLogInfo() { Message = string.Format("银联Wap创建订单成功{0}【请求】:{1}{0}【响应】:{2}", Environment.NewLine, Wapreq.ToJSON(), unionWapResponse.ToJSON()) }); } else { Loggers.Debug(new DebugLogInfo() { Message = string.Format("银联Wap创建订单失败{0}【请求】:{1}{0}【响应】:{2}", Environment.NewLine, Wapreq.ToJSON(), unionWapResponse.ToJSON()) }); response.ResultCode = 100; response.Message = unionWapResponse.Description; } #endregion break; case 2: recordEntity.Platform = 1; #region 银联语音支付 UnionPayChannel unionIVRPaychannel = channel.ChannelParameters.DeserializeJSONTo <UnionPayChannel>(); JIT.Utility.Pay.UnionPay.Interface.IVR.Request.PreOrderRequest IVRreq = new Utility.Pay.UnionPay.Interface.IVR.Request.PreOrderRequest() { SendTime = DateTime.Now, SendSeqID = Guid.NewGuid().ToString("N"), FrontUrl = string.IsNullOrEmpty(para.ReturnUrl) ? ConfigurationManager.AppSettings["UnionPayCallBackUrl"] : para.ReturnUrl, BackUrl = ConfigurationManager.AppSettings["UnionPayIVRNotifyUrl"].Trim('?') + string.Format("?ChannelID={0}", channel.ChannelID), MerchantOrderDesc = entity.AppOrderDesc, Mode = IVRModes.Callback, TransTimeout = entity.AppOrderTime, MerchantOrderCurrency = Currencys.RMB, MerchantOrderAmt = entity.AppOrderAmount, MerchantID = unionIVRPaychannel.MerchantID, MerchantOrderTime = entity.AppOrderTime, MerchantOrderID = entity.OrderID.ToString(), MobileNum = entity.MobileNO }; requestJson = IVRreq.ToJSON(); var IvrResponse = IVRGateway.PreOrder(unionIVRPaychannel, IVRreq); responseJson = IvrResponse.ToJSON(); if (IvrResponse.IsSuccess) { entity.Status = 1; bll.Update(entity); Loggers.Debug(new DebugLogInfo() { Message = string.Format("银联IVR创建订单成功{0}【请求】:{1}{0}【响应】:{2}", Environment.NewLine, IVRreq.ToJSON(), IvrResponse.ToJSON()) }); } else { Loggers.Debug(new DebugLogInfo() { Message = string.Format("银联IVR创建订单失败{0}【请求】:{1}{0}【响应】:{2}", Environment.NewLine, IVRreq.ToJSON(), IvrResponse.ToJSON()) }); response.ResultCode = 200; response.Message = IvrResponse.Description; } #endregion break; case 3: recordEntity.Platform = 2; #region 阿里Wap支付 AliPayChannel aliPayWapChannel = channel.ChannelParameters.DeserializeJSONTo <AliPayChannel>(); AliPayWapTokenRequest tokenRequest = new AliPayWapTokenRequest(aliPayWapChannel) { CallBackUrl = string.IsNullOrEmpty(para.ReturnUrl) ? ConfigurationManager.AppSettings["AliPayCallBackUrl"] : para.ReturnUrl, NotifyUrl = ConfigurationManager.AppSettings["AlipayWapNotify"].Trim('?') + string.Format("?ChannelID={0}", channel.ChannelID), OutTradeNo = entity.OrderID.ToString(), Partner = aliPayWapChannel.Partner, SellerAccountName = aliPayWapChannel.SellerAccountName, Subject = entity.AppOrderDesc, TotalFee = Math.Round((Convert.ToDecimal(entity.AppOrderAmount) / 100), 2).ToString(), ReqID = Guid.NewGuid().ToString().Replace("-", "") }; requestJson = tokenRequest.ToJSON(); var aliPayWapResponse = AliPayWapGeteway.GetQueryTradeResponse(tokenRequest, aliPayWapChannel); responseJson = aliPayWapResponse.ToJSON(); if (aliPayWapResponse.IsSucess) { entity.PayUrl = aliPayWapResponse.RedirectURL; entity.Status = 1; bll.Update(entity); url = aliPayWapResponse.RedirectURL; Loggers.Debug(new DebugLogInfo() { Message = string.Format("AliPayWap创建订单成功{0}【请求】:{1}{0}【响应】:{2}", Environment.NewLine, tokenRequest.ToJSON(), aliPayWapResponse.ToJSON()) }); } else { Loggers.Debug(new DebugLogInfo() { Message = string.Format("AliPayWap创建订单失败{0}【请求】:{1}{0}【响应】:{2}", Environment.NewLine, tokenRequest.ToJSON(), aliPayWapResponse.ToJSON()) }); response.ResultCode = 300; response.Message = aliPayWapResponse.Message; } #endregion break; case 4: recordEntity.Platform = 2; #region 阿里OffLine支付 AliPayChannel aliPayChannel = channel.ChannelParameters.DeserializeJSONTo <AliPayChannel>(); //根据DynamicID判断是否预定单支付,DynamicID为空或者Null时调用OffLine预订单接口 if (string.IsNullOrWhiteSpace(para.DynamicID)) { OfflineQRCodePreRequest qrRequest = new OfflineQRCodePreRequest(aliPayChannel) { OutTradeNo = entity.OrderID.ToString(), NotifyUrl = ConfigurationManager.AppSettings["AlipayOfflineNotify"].Trim('?') + string.Format("?ChannelID={0}", channel.ChannelID), Subject = entity.AppOrderDesc, TotalFee = Math.Round((Convert.ToDecimal(entity.AppOrderAmount) / 100), 2).ToString(), //下面是测试数据,正式须更改 ExtendParams = new { MACHINE_ID = "BJ_001", //? AGENT_ID = aliPayChannel.AgentID, STORE_TYPE = "0", //? STORE_ID = "12314", //? TERMINAL_ID = "111", //? SHOP_ID = "only" //? }.ToJSON() }; requestJson = qrRequest.ToJSON(); var offlineQrResponse = AliPayOffLineGeteway.OfflineQRPay(qrRequest); responseJson = offlineQrResponse.ToJSON(); if (offlineQrResponse.IsSucess) { entity.Status = 1; entity.PayUrl = offlineQrResponse.PicUrl; bll.Update(entity); response.QrCodeUrl = offlineQrResponse.PicUrl; Loggers.Debug(new DebugLogInfo() { Message = string.Format("AliPayOffline二维码支付创建订单成功{0}【请求】:{1}{0}【响应】:{2}", Environment.NewLine, qrRequest.ToJSON(), offlineQrResponse.ToJSON()) }); } else { Loggers.Debug(new DebugLogInfo() { Message = string.Format("AliPayOffline二维码支付创建订单失败{0}【请求】:{1}{0}【响应】:{2}", Environment.NewLine, qrRequest.ToJSON(), offlineQrResponse.ToJSON()) }); response.ResultCode = 400; response.Message = offlineQrResponse.DetailErrorCode + ":" + offlineQrResponse.DetailErrorDes; } } else { CreateAndPayRequest createAndPayrequest = new CreateAndPayRequest(aliPayChannel) { Subject = entity.AppOrderDesc, TotalFee = Math.Round((Convert.ToDecimal(entity.AppOrderAmount) / 100), 2).ToString(), NotifyUrl = ConfigurationManager.AppSettings["AlipayOfflineNotify"].Trim('?') + string.Format("?ChannelID={0}", channel.ChannelID), OutTradeNo = entity.OrderID.ToString(), DynamicIDType = para.DynamicIDType, DynamicID = para.DynamicID, }; if (!string.IsNullOrEmpty(aliPayChannel.AgentID)) { createAndPayrequest.ExtendParams = (new { AGENT_ID = aliPayChannel.AgentID, MACHINE_ID = "BJ_001", STORE_TYPE = "0", STORE_ID = "BJ_ZZ_001", TERMINAL_ID = "A80001", SHOP_ID = "only" }).ToJSON(); } requestJson = createAndPayrequest.ToJSON(); var offlineCreateAndPayResponse = AliPayOffLineGeteway.OfflineCreateAndPay(createAndPayrequest); responseJson = offlineCreateAndPayResponse.ToJSON(); if (offlineCreateAndPayResponse.IsSuccess) { entity.Status = 2; bll.Update(entity); Loggers.Debug(new DebugLogInfo() { Message = string.Format("AliPayOffline即支付创建订单成功{0}【请求】:{1}{0}【响应】:{2}", Environment.NewLine, createAndPayrequest.ToJSON(), offlineCreateAndPayResponse.ToJSON()) }); } else if (offlineCreateAndPayResponse.ResultCode == ResultCodes.ORDER_SUCCESS_PAY_FAIL.ToString()) { entity.Status = 1; bll.Update(entity); Loggers.Debug(new DebugLogInfo() { Message = string.Format("AliPayOffline即支付创建订单成功{0},支付失败【请求】:{1}{0}【响应】:{2}", Environment.NewLine, createAndPayrequest.ToJSON(), offlineCreateAndPayResponse.ToJSON()) }); } else if (offlineCreateAndPayResponse.ResultCode == ResultCodes.ORDER_SUCCESS_PAY_INPROCESS.ToString()) { entity.Status = 1; bll.Update(entity); Loggers.Debug(new DebugLogInfo() { Message = string.Format("AliPayOffline即支付创建订单成功{0},支付处理中【请求】:{1}{0}【响应】:{2}", Environment.NewLine, createAndPayrequest.ToJSON(), offlineCreateAndPayResponse.ToJSON()) }); } else { Loggers.Debug(new DebugLogInfo() { Message = string.Format("AliPayOffline即支付创建订单失败{0}【请求】:{1}{0}【响应】:{2}", Environment.NewLine, createAndPayrequest.ToJSON(), offlineCreateAndPayResponse.ToJSON()) }); response.ResultCode = 400; response.Message = offlineCreateAndPayResponse.DetailErrorCode + ":" + offlineCreateAndPayResponse.DetailErrorDes; } } #endregion break; case 5: //Native case 6: //微信JS case 7: //微信App recordEntity.Platform = 3; #region 微信Native支付,JS支付 //把channel里的参数传了过去 WeiXinPayHelper helper = new WeiXinPayHelper(channel.ChannelParameters.DeserializeJSONTo <WeiXinPayHelper.Channel>()); entity.PayUrl = ConfigurationManager.AppSettings["WeiXinPrePay"]; entity.NotifyUrl = ConfigurationManager.AppSettings["WeiXinPayNotify"]; WeiXinPayHelper.PrePayResult result = null; if (para.PaymentMode == 1) //PaymentMode=1标示微信扫码支付进入 { helper.channel.trade_type = "NATIVE"; channel.PayType = 5; //走扫码回调返回参数 } Loggers.Debug(new DebugLogInfo() { Message = "isSpPay:" + helper.channel.isSpPay }); if (helper.channel.isSpPay == "1") //isSpPay=1 服务商支付 { result = helper.serPrePay(entity); //统一下单,服务商支付 } else { result = helper.prePay(entity); //统一下单,获取微信网页支付的预支付信息,app支付和js支付是一样的 } Loggers.Debug(new DebugLogInfo() { Message = "微信支付_预支付返回结果:" + result.ToJSON() }); requestJson = helper.prePayRequest; responseJson = helper.prePayResponse; if (result.return_code == "SUCCESS" && result.result_code == "SUCCESS") { if (channel.PayType == 6) { response.WXPackage = helper.getJsParamater(result); } else if (channel.PayType == 7) //后面传的参数和js支付的就不一样了 { response.WXPackage = helper.getAppParamater(result); response.OrderID = entity.OrderID; } else //Native { response.WXPackage = result.ToJSON(); response.QrCodeUrl = result.code_url; } Loggers.Debug(new DebugLogInfo() { Message = "WXPackage:" + response.WXPackage }); } else { response.ResultCode = 101; //支付失败 if (!string.IsNullOrEmpty(result.return_msg)) //不同错误,错误信息位置不同 { response.Message = result.return_msg; } else { response.Message = result.err_code_des; } } #endregion break; case 8: //旺财支付 return(string.Empty); case 9: //新版支付宝扫码支付 #region AliPayChannel aliPayScanChannel = channel.ChannelParameters.DeserializeJSONTo <AliPayChannel>(); RequestScanEntity scRequest = new RequestScanEntity(aliPayScanChannel); scRequest.notify_url = "" + ConfigurationManager.AppSettings["AlipayOfflineNotify"]; RequstScanDetail scanDetail = new RequstScanDetail(); scanDetail.out_trade_no = "" + entity.OrderID; scanDetail.total_amount = "" + Math.Round((Convert.ToDecimal(entity.AppOrderAmount) / 100), 2); scanDetail.seller_id = aliPayScanChannel.Partner; scanDetail.subject = entity.AppOrderDesc; var scResponseJson = AliPayScanGeteway.GetResponseStr(scRequest, scanDetail.ToJSON(), aliPayScanChannel.RSA_PrivateKey); var scResponse = scResponseJson.DeserializeJSONTo <ResponsetScanEntity>(); if (scResponse.alipay_trade_precreate_response.code == "10000") { response.QrCodeUrl = scResponse.alipay_trade_precreate_response.qr_code; Loggers.Debug(new DebugLogInfo() { Message = string.Format("aliPayScanChannel二维码支付创建订单成功{0}【请求】:{1}{0}【响应】:{2}", Environment.NewLine, requestJson, scResponseJson) }); } else { Loggers.Debug(new DebugLogInfo() { Message = string.Format("AliPayOffline二维码支付创建订单失败{0}【请求】:{1}{0}【响应】:{2}", Environment.NewLine, requestJson, scResponseJson) }); response.ResultCode = 400; response.Message = scResponse.alipay_trade_precreate_response.code + ":" + scResponse.alipay_trade_precreate_response.msg; } #endregion break; default: break; } recordEntity.RequestJson = requestJson; recordEntity.ResponseJson = responseJson; recordBll.Create(recordEntity); } catch (Exception ex) { recordEntity.RequestJson = requestJson; recordEntity.ResponseJson = responseJson; recordBll.Create(recordEntity); throw ex; } #endregion return(url); }