public void ProcessRequest(HttpContext context) { try { int interfaceType = Convert.ToInt32(context.Request["interfaceType"]);//1-获取好码归属地 2-获取产品 var UpConfig = GetUpConfig(); if (UpConfig != null) { if (interfaceType == 1) {//查询号码区段 string sPhone = context.Request["sPhone"]; string cid = UpConfig.API_UID; string key = UpConfig.API_KEY; string sign = TenPayHelp.MD5(cid + sPhone + key).ToLower(); string sUrl = string.Format("{0}?cid={1}&ph={2}&sign={3}", UpConfig.MOBILE_QUERY_URL, cid, sPhone, sign); string result = HttpHelper.HttpGet(sUrl); context.Response.ContentType = "text/plain"; context.Response.Write(result); } else {//获取产品接口 string rm = context.Request["rm"] == null ? "0" : context.Request["rm"]; string sPhone = context.Request["sPhone"]; string businessType = context.Request["businessType"];//业务类型(2=手机 5=全国流量 5=省内流量) string cid = UpConfig.API_UID; string key = UpConfig.API_KEY; string sign = TenPayHelp.MD5(cid + sPhone + businessType + key).ToLower(); string sUrl = string.Format("{0}?cid={1}&ph={2}&ct={3}&sign={4}&rm={5}", UpConfig.PRODUCT_QUERY_URL, cid, sPhone, businessType, sign, rm); string result = HttpHelper.HttpGet(sUrl); context.Response.ContentType = "text/plain"; context.Response.Write(result); } } else { var res = new { code = 200, msg = "获取配置信息失败" }; context.Response.ContentType = "text/plain"; context.Response.Write(JsonConvert.SerializeObject(res)); } } catch (Exception e) { logger.Info(e.Message); logger.Fatal(e.Message, e); var res = new { code = 200, msg = "服务错误" }; context.Response.ContentType = "text/plain"; context.Response.Write(JsonConvert.SerializeObject(res)); } }
/// <summary> /// 创建签名 /// </summary> /// <param name="Parameters"></param> /// <param name="sSignKey"></param> /// <returns></returns> public string GetSign(NameValueCollection Parameters, string sSignKey) { StringBuilder Sign = new StringBuilder(); var Keys = new ArrayList(Parameters.Keys); Keys.Sort();//字典排序 foreach (string key in Keys) { if (!string.IsNullOrEmpty(Parameters[key]) && key != "sign") {//拼接成键值对字符串 Sign.Append(key + "=" + Parameters[key] + "&"); } } Sign.Append("key=" + sSignKey); string sign = TenPayHelp.MD5(Sign.ToString()).ToLower(); return(sign); }
public void ProcessRequest(HttpContext context) { string sTipMessage = string.Empty; Message result = new Message(); try { logger.Info("----------------微信退款申请开始---------------------"); string appid = context.Request["appid"]; string out_trade_no = context.Request["out_trade_no"]; string out_refund_no = context.Request["out_refund_no"]; string total_fee = context.Request["total_fee"]; string refund_fee = context.Request["refund_fee"]; string refund_desc = context.Request["refund_desc"]; string sign = context.Request["sign"]; logger.Info(string.Format(@"原始参数:订单号:appid={0}, out_trade_no:{1}, out_refund_no:{2}, totalfee:{3}, refundfee:{4}, refund_desc:{5}, sign:{6}", appid, out_trade_no, out_refund_no, refund_fee, refund_desc, refund_desc, sign)); //签名Key string sSignKey = TenPayHelp.MD5(appid).ToLower(); string newSign = GetSign(context.Request.Form, sSignKey); int totalfee = Convert.ToInt32((Convert.ToDecimal(total_fee) * 100)); int refundfee = Convert.ToInt32((Convert.ToDecimal(refund_fee) * 100)); logger.Info(string.Format(@"微信退款申请的输入参数:订单号:appid={0}, out_trade_no:{1}, out_refund_no:{2}, totalfee:{3} refundfee:{4} refund_desc:{5}", appid, out_trade_no, out_refund_no, totalfee, refundfee, refund_desc)); if (sign == newSign) {//签名认证成功 //获取支付账户信息 var PayAccount = ApiHelper.QueryPayAccount(appid, 2, logger); result = PayRequest.Instance.PayRefund(new TenPayConfig() { appid = PayAccount.Appid, mch_id = PayAccount.Mchid, key = PayAccount.Pubkey, SSLCERT_PATH = PayAccount.CertPath }, out_trade_no, out_refund_no, totalfee, refundfee, refund_desc); sTipMessage = result.data; } else { sTipMessage = "签名验证失败"; } } catch (Exception e) { logger.Info("----------------微信退款申请异常---------------------"); logger.Fatal("异常错误信息:" + e.Message, e); sTipMessage = "System Server Error"; } logger.Info("返回结果:" + sTipMessage); context.Response.Clear(); context.Response.ContentType = "text/plain"; context.Response.Write(sTipMessage); }
public void ProcessRequest(HttpContext context) { try { var result = string.Empty;//返回结果 //创建订单 string requestData = context.Request.Form["orderInfo"]; logger.Info("请求参数:" + requestData); var orderInfo = JsonConvert.DeserializeObject <HWOrder>(requestData); //获取用户的真实IP string ip = context.Request.UserHostAddress; if (context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null) { ip = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].Split(',')[0];//获取用户的真实的IP } orderInfo.user_ip = ip.Split(':')[0]; orderInfo.down_channel_no = ConfigurationManager.AppSettings["jsyh_channel_no"];//获取下游渠道编号 var revOrderResult = Server.SaveOrder(orderInfo, logger); logger.Info(string.Format("订单状态:{0},消息:{1}", revOrderResult.Status, revOrderResult.ResultMsg)); if (revOrderResult.Status) { logger.Info("订单保存成功"); QueryAccountResult accountResult = ApiHelper.QueryPayAccount(revOrderResult.AppId, revOrderResult.AccountType, logger); if (!accountResult.Status) { logger.Info("获取支付信息失败"); result = JsonConvert.SerializeObject(new { success = false, info = "获取支付信息失败" }); } else { //拼接支付信息 HttpUtility.UrlEncode var PayParams = new Dictionary <string, object>(); PayParams.Add("MERCHANTID", accountResult.Appid); //商户代码 PayParams.Add("POSID", accountResult.Mchid); //商户柜台代码 PayParams.Add("BRANCHID", accountResult.Ext1); //分行代码 PayParams.Add("ORDERID", revOrderResult.OrderNo); //商户订单号PAYMENT PayParams.Add("PAYMENT", revOrderResult.PayFee); //付款金额 PayParams.Add("CURCODE", "01"); //币种 PayParams.Add("TXCODE", accountResult.Ext2); //交易码 PayParams.Add("REMARK1", string.Empty); PayParams.Add("REMARK2", string.Empty); PayParams.Add("TYPE", 1); //接口类型 PayParams.Add("PUB", accountResult.Pubkey); PayParams.Add("GATEWAY", 0); //网关类型 默认送0 PayParams.Add("CLIENTIP", string.Empty); PayParams.Add("REGINFO", string.Empty); PayParams.Add("PROINFO", string.Empty); PayParams.Add("REFERER", string.Empty); StringBuilder Sign = new StringBuilder(); foreach (var key in PayParams.Keys) { Sign.AppendFormat("{0}={1}&", key, PayParams[key].ToString()); } string sign = TenPayHelp.MD5(Sign.ToString().TrimEnd('&')).ToLower(); PayParams.Add("TIMEOUT", string.Empty); PayParams.Add("MAC", sign); PayParams.Remove("PUB"); StringBuilder PayInfo = new StringBuilder(); foreach (var key in PayParams.Keys) { PayInfo.AppendFormat("{0}={1}&", key, PayParams[key].ToString()); } string payinfo = PayInfo.ToString().TrimEnd('&'); result = JsonConvert.SerializeObject(new { success = true, info = "支付请求成功", data = payinfo }); } } else { logger.Info("订单保存失败"); result = JsonConvert.SerializeObject(new { success = false, info = "订单保存失败" }); ApiHelper.SetFail(revOrderResult.OrderNo, revOrderResult.ResultMsg, logger); } context.Response.ContentType = "text/plain"; context.Response.Write(result); } catch (Exception e) { logger.Info(e.Message); logger.Fatal(e.Message, e); var res = new { code = 200, info = "服务错误" }; context.Response.ContentType = "text/plain"; context.Response.Write(JsonConvert.SerializeObject(res)); } }
public void ProcessRequest(HttpContext context) { var result = new Message(); try { logger.Info("----------------龙支付退款开始---------------------"); string appid = context.Request["appid"]; string out_trade_no = context.Request["out_trade_no"]; string out_refund_no = context.Request["out_refund_no"]; string total_fee = decimal.Parse(context.Request["total_fee"]).ToString(); string refund_fee = decimal.Parse(context.Request["refund_fee"]).ToString();; string refund_desc = context.Request["refund_desc"]; logger.Info(string.Format(@"龙支付退款的输入参数:appid={0}, out_trade_no:{1}, out_refund_no:{2}, totalfee:{3} refundfee:{4} refund_desc:{5}", appid, out_trade_no, out_refund_no, total_fee, refund_fee, refund_desc)); string sign = context.Request["sign"]; //签名Key string sSignKey = TenPayHelp.MD5(appid).ToLower(); string newSign = GetSign(context.Request.Form, sSignKey); if (newSign == sign) { //获取龙支付账户配置信息 var config = ApiHelper.QueryPayAccount(appid, 4, logger); //拼接退款参数 StringBuilder requestParams = new StringBuilder(); requestParams.Append("<?xml version=\"1.0\" encoding=\"GB2312\" standalone=\"yes\" ?>"); requestParams.AppendFormat(@"<TX> <REQUEST_SN>{0}</REQUEST_SN> <CUST_ID>{1}</CUST_ID> <USER_ID>{2}</USER_ID> <PASSWORD>{3}</PASSWORD> <TX_CODE>5W1004</TX_CODE> <LANGUAGE>CN</LANGUAGE> <TX_INFO> <MONEY>{4}</MONEY> <ORDER>{5}</ORDER> </TX_INFO> <SIGN_INFO>签名信息</SIGN_INFO> <SIGNCERT>签名CA信息</SIGNCERT> </TX>", DateTime.Now.ToString("yyyyMMddHHmmssff"), config.Appid, config.Ext3, config.Ext4, refund_fee, out_trade_no); var respone = TCPHelper.Request(requestParams.ToString(), logger); result.data = respone; } else { result.data = "内部签名验证失败"; } } catch (Exception e) { logger.Info("----------------支付宝退款异常---------------------"); logger.Info("异常错误信息:" + e.Message, e); logger.Fatal("异常错误信息:" + e.Message, e); result.data = "Systyem Server Error"; } context.Response.Clear(); context.Response.ContentType = "text/plain"; context.Response.Write(result.data); }
public void ProcessRequest(HttpContext context) { var result = new Message(); try { logger.Info("----------------支付宝退款---------------------"); string appid = context.Request["appid"]; string out_trade_no = context.Request["out_trade_no"]; string out_refund_no = context.Request["out_refund_no"]; string total_fee = decimal.Parse(context.Request["total_fee"]).ToString(); string refund_fee = decimal.Parse(context.Request["refund_fee"]).ToString();; string refund_desc = context.Request["refund_desc"]; logger.Info(string.Format(@"支付宝退款的输入参数:appid={0}, out_trade_no:{1}, out_refund_no:{2}, totalfee:{3} refundfee:{4} refund_desc:{5}", appid, out_trade_no, out_refund_no, total_fee, refund_fee, refund_desc)); string sign = context.Request["sign"]; //签名Key string sSignKey = TenPayHelp.MD5(appid).ToLower(); string newSign = GetSign(context.Request.Form, sSignKey); if (newSign == sign) { //获取支付宝账户配置信息 var config = ApiHelper.QueryPayAccount(appid, 1, logger); logger.Info(string.Format(@"Appid={0},Prikey={1},Pubkey={2}", config.Appid, config.Prikey, config.Pubkey)); IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", config.Appid, config.Prikey, "json", "1.0", "RSA2", config.Pubkey, "utf-8", false); AlipayTradeRefundRequest request = new AlipayTradeRefundRequest(); AlipayTradeRefundModel model = new AlipayTradeRefundModel(); model.OutTradeNo = out_trade_no; //商户订单号 //"20170821141701640"; model.OutRequestNo = out_refund_no; //退款编号 model.RefundAmount = refund_fee; //退款金额 model.RefundReason = refund_desc; //退款原因 request.SetBizModel(model); AlipayTradeRefundResponse response = client.Execute(request); result.data = response.Body; } else { result.data = "内部签名验证失败"; } } catch (Exception e) { logger.Info("----------------支付宝退款异常---------------------"); logger.Info("异常错误信息:" + e.Message, e); logger.Fatal("异常错误信息:" + e.Message, e); result.data = "Systyem Server Error"; } context.Response.Clear(); context.Response.ContentType = "text/plain"; context.Response.Write(result.data); }