public void TestPreOrder() { UnionPayChannel channel = new UnionPayChannel() { CertificateFilePassword = "******", CertificateFilePath = "D:/cer/630056832596.pfx", MerchantID = "630056832596", PacketEncryptKey = "654321" }; PreOrderRequest req = new PreOrderRequest(); req.SendTime = DateTime.Now; req.SendSeqID = Guid.NewGuid().ToString("N"); req.FrontUrl = "http://www.jitmarketing.cn:8090/TranNotification.ashx"; req.MerchantOrderDesc = "呵呵"; req.Misc = string.Empty; //req.GatewayType = GatewayTypes.WAP; req.TransTimeout = DateTime.Now.AddHours(1); req.BackUrl = "http://www.jitmarketing.cn:8090/TranNotification.ashx"; req.MerchantOrderCurrency = Currencys.RMB; req.MerchantOrderAmt = 1; req.MerchantID = "630056832596"; req.MerchantOrderTime = DateTime.Now.AddMinutes(-5); req.MerchantOrderID = Guid.NewGuid().ToString("N"); req.MerchantUserID = string.Empty; req.MobileNum = "15388157741"; req.CarNum = string.Empty; var rsp = WapGateway.PreOrder(channel, req); Assert.IsTrue(rsp.IsSuccess); }
private void btnQueryOrder_Click(object sender, EventArgs e) { //创建支付通道 UnionPayChannel channel = new UnionPayChannel() { CertificateFilePassword = ConfigurationManager.AppSettings["WAPEncryptCertificateFilePassword"] , CertificateFilePath = ConfigurationManager.AppSettings["WAPEncryptCertificateFilePath"] , MerchantID = ConfigurationManager.AppSettings["WAPMerchantID"] , PacketEncryptKey = "654321" }; //查询订单 QueryOrderRequest req = new QueryOrderRequest(); req.SendTime = DateTime.Now; req.SendSeqID = Guid.NewGuid().ToString("N"); req.TransType = WapTransTypes.PreAuthorization; req.MerchantID = channel.MerchantID; req.MerchantOrderID = this.Session["MerchantOrderID"] as string; req.MerchantOrderTime = this.Session["MerchantOrderTime"] as DateTime?; // try { var rsp = WapGateway.QueryOrder(channel, req); this.txtOrderInfo.Text = rsp.ToString(); } catch (Exception ex) { this.txtOrderInfo.Text = "执行失败:" + Environment.NewLine + ex.Message; } }
public void TestPreOrder() { UnionPayChannel channel = new UnionPayChannel() { CertificateFilePassword = "******", CertificateFilePath = "D:/cer/700000000000001.pfx", MerchantID = "267099633218", PacketEncryptKey = "654321" }; PreOrderRequest req = new PreOrderRequest(); req.SendTime = DateTime.Now; req.SendSeqID = Guid.NewGuid().ToString("N"); req.FrontUrl = "http://www.jitmarketing.cn:8090/TranNotification.ashx"; req.MerchantOrderDesc = "呵呵"; req.Misc = string.Empty; req.Mode = IVRModes.Callback; //req.GatewayType = GatewayTypes.WAP; req.TransTimeout = DateTime.Now.AddHours(1); req.BackUrl = "http://www.jitmarketing.cn:8090/TranNotification.ashx"; req.MerchantOrderCurrency = Currencys.RMB; req.MerchantOrderAmt = 1; req.MerchantID = channel.MerchantID; req.MerchantOrderTime = DateTime.Now.AddMinutes(-5); req.MerchantOrderID = Guid.NewGuid().ToString("N").Substring(0, 30); req.MerchantUserID = string.Empty; req.MobileNum = "18019438327"; req.CarNum = string.Empty; var rsp = IVRGateway.PreOrder(channel, req); Assert.IsTrue(rsp.IsSuccess); }
//static string API_URL = "http://58.246.136.11:8006/wapDetect/gateWay!gate.ac"; #region 工具方法 /// <summary> /// 调用API /// </summary> /// <typeparam name="TRequest">向支付接口发送的请求的类型</typeparam> /// <typeparam name="TResponse"></typeparam> /// <param name="pChannel"></param> /// <param name="pRequest"></param> /// <returns></returns> private static TResponse CallAPI <TRequest, TResponse>(UnionPayChannel pChannel, TRequest pRequest) where TRequest : BaseAPIRequest where TResponse : BaseAPIResponse, new() { //参数校验 if (pChannel == null) { throw new ArgumentNullException("pChannel"); } if (string.IsNullOrWhiteSpace(pChannel.MerchantID)) { throw new ArgumentNullException("pChannel.MerchantID"); } if (pRequest == null) { throw new ArgumentNullException("pRequest"); } // var reqContent = pRequest.GetContent(); var merchantID = EncDecUtil.Base64Encrypt(pChannel.MerchantID); //Base64加密商户ID var desKey = EncDecUtil.GetEncryptKey(pChannel.PacketEncryptKey); //获取实际加密密钥 //采用Base64(RSA(加密密钥))计算出报文中的加密密钥 var encryptedDesKey = EncDecUtil.Base64Encrypt(EncDecUtil.RSAEncrypt(pChannel.CertificateFilePath, pChannel.CertificateFilePassword, desKey + "11111111")); //采用Base64(3DES(报文))加密报文 var encryptedContent = EncDecUtil.Base64Encrypt(EncDecUtil.TripleDESEncrypt(desKey, reqContent)); // var requestContent = merchantID + "|" + encryptedDesKey + "|" + encryptedContent; using (WebClient wc = new WebClient()) { string strResponse = wc.UploadString(IVRGateway.API_URL, requestContent); string[] responseSections = strResponse.Split('|'); string rspCode = responseSections[0]; string rspContent = responseSections[1]; // if (rspCode == "1") { var decRspBytes = EncDecUtil.TripleDESDecrypt(desKey, EncDecUtil.Base64Decrypt(rspContent)); string decRspContent = Encoding.UTF8.GetString(decRspBytes); decRspContent = decRspContent.Replace("\0", string.Empty); TResponse rsp = new TResponse(); rsp.Load(decRspContent); // return(rsp); } else { string errorCode = rspContent; string errorMsg = Encoding.UTF8.GetString(EncDecUtil.Base64Decrypt(responseSections[2])); UnionPayException ex = new UnionPayException(errorMsg); ex.Code = errorCode; throw ex; } } }
private void btnOrder_Click(object sender, EventArgs e) { //创建支付通道 UnionPayChannel channel = new UnionPayChannel() { CertificateFilePassword = ConfigurationManager.AppSettings["IVREncryptCertificateFilePassword"] , CertificateFilePath = ConfigurationManager.AppSettings["IVREncryptCertificateFilePath"] , MerchantID = ConfigurationManager.AppSettings["IVRMerchantID"] , PacketEncryptKey = "654321" }; //下订单 PreOrderRequest req = new PreOrderRequest(); req.SendTime = DateTime.Now; req.SendSeqID = Guid.NewGuid().ToString("N"); req.FrontUrl = ConfigurationManager.AppSettings["IVRFrontUrl"]; //商户平台的页面,用户支付完毕后跳转的页面 req.MerchantOrderDesc = "呵呵"; req.Misc = string.Empty; req.Mode = IVRModes.Callback; req.TransTimeout = DateTime.Now.AddHours(1); req.BackUrl = ConfigurationManager.AppSettings["IVRBackUrl"]; //当用户支付完成后,支付平台回调的交易通知的页面 req.MerchantOrderCurrency = Currencys.RMB; req.MerchantOrderAmt = 1; req.MerchantID = channel.MerchantID; req.MerchantOrderTime = DateTime.Now.AddMinutes(-5); req.MerchantOrderID = Guid.NewGuid().ToString("N").Substring(0, 30); req.MerchantUserID = string.Empty; req.MobileNum = this.txtMobileNO.Text; //消费者的手机号,支付前置会将验证码发送到该手机 req.CarNum = string.Empty; //记录支付请求日志 Loggers.Debug(new DebugLogInfo() { Message = string.Format("[IVR]PreOrder Request={0}", req.GetContent()) }); //支付平台成功接收 var rsp = IVRGateway.PreOrder(channel, req); //重定向到支付页面 if (rsp.IsSuccess) { // this.Session["MerchantOrderID"] = rsp.MerchantOrderID; this.Session["MerchantOrderTime"] = rsp.MerchantOrderTime; // this.ltGotoPay.Text = "订单创建成功,请等待支付平台呼入."; this.ltGotoPay.Mode = LiteralMode.PassThrough; } }
public void TestQueryOrder() { //先发预订单请求 UnionPayChannel channel = new UnionPayChannel() { CertificateFilePassword = "******", CertificateFilePath = "D:/cer/630056832596.pfx", MerchantID = "630056832596", PacketEncryptKey = "654321" }; PreOrderRequest req = new PreOrderRequest(); req.SendTime = DateTime.Now; req.SendSeqID = Guid.NewGuid().ToString("N"); req.FrontUrl = "http://www.jitmarketing.cn:8090/TranNotification.ashx"; req.MerchantOrderDesc = "呵呵"; req.Misc = string.Empty; //req.GatewayType = GatewayTypes.WAP; req.TransTimeout = DateTime.Now.AddHours(1); req.BackUrl = "http://www.jitmarketing.cn:8090/TranNotification.ashx"; req.MerchantOrderCurrency = Currencys.RMB; req.MerchantOrderAmt = 1; req.MerchantID = "630056832596"; req.MerchantOrderTime = DateTime.Now.AddMinutes(-5); req.MerchantOrderID = Guid.NewGuid().ToString("N"); req.MerchantUserID = string.Empty; req.MobileNum = "15388157741"; req.CarNum = string.Empty; var rsp = WapGateway.PreOrder(channel, req); Assert.IsTrue(rsp.IsSuccess); //跳转到支付平台页面 WebClient wc = new WebClient(); string strResponse = wc.UploadString(rsp.RedirectURL, string.Empty); //在查询 QueryOrderRequest req2 = new QueryOrderRequest(); req2.SendTime = DateTime.Now; req2.SendSeqID = Guid.NewGuid().ToString("N"); req2.TransType = WapTransTypes.PreAuthorization; req2.MerchantID = "630056832596"; req2.MerchantOrderID = req.MerchantOrderID; req2.MerchantOrderTime = req.MerchantOrderTime; var rsp2 = WapGateway.QueryOrder(channel, req2); Assert.IsTrue(rsp2.IsSuccess); }
/// <summary> /// 查询订单 /// <remarks> /// <para>商户平台 -> 支付平台</para> /// </remarks> /// </summary> /// <param name="pChannel">调用支付接口的基本设置信息</param> /// <param name="pRequest">订单查询请求</param> /// <returns></returns> public static QueryOrderResponse QueryOrder(UnionPayChannel pChannel, QueryOrderRequest pRequest) { return(IVRGateway.CallAPI <QueryOrderRequest, QueryOrderResponse>(pChannel, pRequest)); }
/// <summary> /// 预订单 /// <remarks> /// <para>商户平台 -> 支付平台</para> /// </remarks> /// </summary> /// <param name="pChannel">调用支付接口的基本设置信息</param> /// <param name="pRequest">预订单请求</param> public static PreOrderResponse PreOrder(UnionPayChannel pChannel, PreOrderRequest pRequest) { return(IVRGateway.CallAPI <PreOrderRequest, PreOrderResponse>(pChannel, pRequest)); }
/// <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); }
public void ProcessRequest(HttpContext context) { try { string strRequest = context.Request.Params["ReqContent"]; //if (string.IsNullOrEmpty(strRequest)) //{ // strRequest = "{\"Token\":\"\",\"CityID\":21,\"UserID\":\"FBEE2CFA-500C-4756-BFAA-000014308165\",\"Locale\":1,\"Parameters\":{\"OrderAmount\":1,\"OrderDesc\":\"测试支付\",\"OrderTime\":\"2013-12-30 16:24:33 367\",\"OrderID\":\"57F2DB3A51EB472AED32E413AA986854\",\"MobileNO\":\"13817218367\",\"PayType\":1}}"; //} var request = strRequest.DeserializeJSONTo <ALDRequest <PayOrderRequest> >(); switch (request.Parameters.PayType.Value) { case 1: #region WAP 下单 { //创建支付通道 UnionPayChannel channel = new UnionPayChannel() { CertificateFilePassword = ConfigurationManager.AppSettings["WAPEncryptCertificateFilePassword"] , CertificateFilePath = ConfigurationManager.AppSettings["WAPEncryptCertificateFilePath"] , MerchantID = ConfigurationManager.AppSettings["WAPMerchantID"] , PacketEncryptKey = "654321" }; //下订单 WAPRequest.PreOrderRequest req = new WAPRequest.PreOrderRequest(); req.SendTime = DateTime.Now; req.SendSeqID = Guid.NewGuid().ToString("N"); req.FrontUrl = ConfigurationManager.AppSettings["WAPFrontUrl"]; //商户平台的页面,用户支付完毕后跳转的页面 req.MerchantOrderDesc = request.Parameters.OrderDesc; req.Misc = string.Empty; req.TransTimeout = DateTime.Now.AddHours(1); req.BackUrl = ConfigurationManager.AppSettings["WAPBackUrl"]; //当用户支付完成后,支付平台回调的交易通知的页面 req.MerchantOrderCurrency = Currencys.RMB; req.MerchantOrderAmt = request.Parameters.OrderAmount; req.MerchantID = channel.MerchantID; req.MerchantOrderTime = DateTime.ParseExact(request.Parameters.OrderTime, "yyyy-MM-dd HH:mm:ss fff", null); req.MerchantOrderID = request.Parameters.OrderID; req.MerchantUserID = string.Empty; req.MobileNum = request.Parameters.MobileNO; //消费者的手机号,支付平台会将验证码发送到该手机 req.CarNum = string.Empty; //记录支付请求日志 Loggers.Debug(new DebugLogInfo() { Message = string.Format("[Wap]PreOrder Request={0}", req.GetContent()) }); //支付平台成功接收 var rsp = WapGateway.PreOrder(channel, req); if (rsp.IsSuccess) { context.Response.Write(rsp.RedirectURL); } } #endregion break; case 2: #region 语音下单 { //创建支付通道 UnionPayChannel channel = new UnionPayChannel() { CertificateFilePassword = ConfigurationManager.AppSettings["IVREncryptCertificateFilePassword"] , CertificateFilePath = ConfigurationManager.AppSettings["IVREncryptCertificateFilePath"] , MerchantID = ConfigurationManager.AppSettings["IVRMerchantID"] , PacketEncryptKey = "654321" }; //下订单 IVRRequest.PreOrderRequest req = new IVRRequest.PreOrderRequest(); req.SendTime = DateTime.Now; req.SendSeqID = Guid.NewGuid().ToString("N"); req.FrontUrl = ConfigurationManager.AppSettings["IVRFrontUrl"]; //商户平台的页面,用户支付完毕后跳转的页面 req.MerchantOrderDesc = request.Parameters.OrderDesc; req.Misc = string.Empty; req.Mode = IVRValueObject.IVRModes.Callback; req.TransTimeout = DateTime.Now.AddHours(1); req.BackUrl = ConfigurationManager.AppSettings["IVRBackUrl"]; //当用户支付完成后,支付平台回调的交易通知的页面 req.MerchantOrderCurrency = Currencys.RMB; req.MerchantOrderAmt = request.Parameters.OrderAmount; req.MerchantID = channel.MerchantID; req.MerchantOrderTime = DateTime.ParseExact(request.Parameters.OrderTime, "yyyy-MM-dd HH:mm:ss fff", null); req.MerchantOrderID = request.Parameters.OrderID; req.MerchantUserID = string.Empty; req.MobileNum = request.Parameters.MobileNO; //消费者的手机号,支付前置会将验证码发送到该手机 req.CarNum = string.Empty; //记录支付请求日志 Loggers.Debug(new DebugLogInfo() { Message = string.Format("[IVR]PreOrder Request={0}", req.GetContent()) }); //支付平台成功接收 var rsp = IVRGateway.PreOrder(channel, req); // if (rsp.IsSuccess) { context.Response.Write("OK"); } else { context.Response.Write("Failed"); } } #endregion break; } } catch (Exception ex) { JIT.Utility.Log.Loggers.Exception(new ExceptionLogInfo(ex)); throw ex; } }