/// <summary> /// 取消授权 /// </summary> /// <param name="appid"></param> /// <param name="clientid"></param> /// <returns></returns> public static bool UnauthWechatApp(string appid) { var clientId = "eb17cc2569c74ab7888b1f403972d37d";//测试用 var loggingSessionInfo = Default.GetBSLoggingSession(clientId, "open"); var waiBll = new WApplicationInterfaceBLL(loggingSessionInfo); var wmenuBll = new WMenuBLL(loggingSessionInfo); var userInfo = loggingSessionInfo; userInfo.CurrentLoggingManager.Connection_String = WebConfigurationManager.AppSettings["APConn"]; var customerWxMappingBll = new TCustomerWeiXinMappingBLL(userInfo); var customerId = customerWxMappingBll.GetCustomerIdByAppId(appid); var waiEntitys = new WApplicationInterfaceEntity[] { }; var waiEntity = new WApplicationInterfaceEntity(); var component_Appid = WebConfigurationManager.AppSettings["Component_Appid"]; waiEntitys = waiBll.QueryByEntity(new WApplicationInterfaceEntity { AppID = appid, OpenOAuthAppid = component_Appid, CustomerId = customerId, IsDelete = 0 }, null); if (waiEntitys != null && waiEntitys.Length > 0) { waiEntity = waiEntitys.FirstOrDefault(); //waiEntity.OpenOAuthAppid = null;//置空 //waiBll.Update(waiEntity); waiBll.Delete(waiEntity); //查询参数 List <IWhereCondition> complexCondition = new List <IWhereCondition> { }; complexCondition.Add(new EqualsCondition() { FieldName = "WeiXinID", Value = waiEntity.WeiXinID }); var tempList = wmenuBll.PagedQuery(complexCondition.ToArray(), null, 10, 1); if (tempList.Entities.Length > 0) { foreach (var item in tempList.Entities) { wmenuBll.Delete(item); } } //var wmenuEntitys = wmenuBll.QueryByEntity(new WMenuEntity { WeiXinID = waiEntity.WeiXinID }, null); //if (wmenuEntitys != null && wmenuEntitys.Length > 0) //{ // foreach (var item in wmenuEntitys) // { // wmenuBll.Delete(item); // } //} } return(true); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Write("Hello World"); JIT.Utility.Log.Loggers.Debug(new Utility.Log.DebugLogInfo() { Message = "支付通知接口被调用" }); #region 获取url参数 //签名类型,取值: MD5MD5 、RSA RSA,默认: MD5 var signType = context.Request.QueryString["sign_type"]; //版本号,默认为 1.0 var serviceVersion = context.Request.QueryString["service_version"]; //字符编码 ,取值: GBKGBK 、UTFUTFUTF-8,默认: GBKGBK 。 var inputCharset = context.Request.QueryString["input_charset"]; //签名 var sign = context.Request.QueryString["sign"]; //多密钥支持的序号,默认 1 var signKeyIndex = context.Request.QueryString["sign_key_index"]; //1-即时到账 其他保留 var tradeMode = context.Request.QueryString["trade_mode"]; //支付结果:0—成功 其他保留 var tradeState = context.Request.QueryString["trade_state"]; //支付结果信息,成功时为空 var payInfo = context.Request.QueryString["pay_info"]; //商户号,也即之前步骤的 商户号,也即之前步骤的 partnerid,由微信统一分配的 10 位正整数 (120XXXXXXX)号 var partner = context.Request.QueryString["partner"]; //银行类型,在微信中使用 WX var bankType = context.Request.QueryString["bank_type"]; //银行订单号 var bankBillno = context.Request.QueryString["bank_billno"]; //支付金额,单位为分如果 支付金额,单位为分如果 支付金额,单位为分如果 discount 有值,通知的 total_fee + discount = 请求的 total_fee var totalFee = context.Request.QueryString["total_fee"]; //现金支付币种 ,目前只支持人民币 默认值是 1-人民币 var feeType = context.Request.QueryString["fee_type"]; //支付结果通知 id ,对于某些特定商 户,只返回通知 id ,要求商户据此查询交易结果 var notifyId = context.Request.QueryString["notify_id"]; //交易号, 28 位长的数值,其中前 位长的数值,其中前 10 位为商户号,之后 8位为订单产生 的日期,如 20090415,最后 10 位是流水号。 var transactionId = context.Request.QueryString["transaction_id"]; //商户系统的订单号,与请求一致。 var outTradeNo = context.Request.QueryString["out_trade_no"]; //商户 数据包,原样返回 var attach = context.Request.QueryString["attach"]; //支付完成时间,格式为yyyyMMddhhmmss ,如 2009 年 12 月 27 日 9点 10 分 10 秒表示为 秒表示为 20091227091010。时区为 GMT+8 beijing var timeEnd = context.Request.QueryString["time_end"]; //物流费用,单位分默认0。如果有值,必须保证 transport_fee + product_fee = total_fee var transportFee = context.Request.QueryString["transport_fee"]; //物品费用,单位分。如果有值必须保证 transport_fee + product_fee = total_fee var productFee = context.Request.QueryString["product_fee"]; //折扣价格,单位分.如果有值,通知的 total_fee + discount = 请求的 total_fee var discount = context.Request.QueryString["discount"]; //对应买家账号的一个加密串 var buyerAlias = context.Request.QueryString["buyer_alias"]; #endregion var appSignature = string.Empty; var appId = string.Empty; var isSubscribe = string.Empty; var timeStamp = string.Empty; var nonceStr = string.Empty; var openID = string.Empty; using (var stream = context.Request.InputStream) { using (var rd = new StreamReader(stream, Encoding.UTF8)) { var xmlStr = rd.ReadToEnd(); Loggers.Debug(new DebugLogInfo() { Message = "传入内容:" + xmlStr }); var doc = new XmlDocument(); doc.LoadXml(xmlStr); nonceStr = doc.SelectSingleNode("xml/NonceStr").InnerText; appSignature = doc.SelectSingleNode("xml/AppSignature").InnerText; appId = doc.SelectSingleNode("xml/AppId").InnerText; isSubscribe = doc.SelectSingleNode("xml/IsSubscribe").InnerText; timeStamp = doc.SelectSingleNode("xml/TimeStamp").InnerText; openID = doc.SelectSingleNode("xml/OpenId").InnerText; } } #region var customerWxMappingBll = new TCustomerWeiXinMappingBLL(Default.GetAPLoggingSession("")); var customerId = customerWxMappingBll.GetCustomerIdByAppId(appId); if (customerId == "") { throw new APIException("客户ID为空") { ErrorCode = 121 }; } var currentUserInfo = Default.GetBSLoggingSession(customerId, "1"); var wxPayNoticeEntity = new WXPayNoticeEntity { SignType = signType, Sign = sign, ServiceVersion = serviceVersion, InputCharset = inputCharset, SignKeyIndex = Convert.ToInt32(signKeyIndex), TradeMode = Convert.ToInt32(tradeMode), TradeState = Convert.ToInt32(tradeState), PayInfo = payInfo, Partner = partner, BankType = bankType, BankBillno = bankBillno, TotalFee = Convert.ToInt32(totalFee), FeeType = Convert.ToInt32(feeType), NotifyId = notifyId, TransactionId = transactionId, OutTradeNo = outTradeNo, Attach = attach, TimeEnd = timeEnd, TransportFee = Convert.ToInt32(transportFee), ProductFee = Convert.ToInt32(productFee), Discount = Convert.ToInt32(discount), BuyerAlias = buyerAlias, AppId = appId, TimeStamp = Convert.ToInt32(timeStamp), NonceStr = nonceStr, OpenId = openID, AppSignature = appSignature, IsSubscribe = 1, CustomerId = customerId }; var wxPayNoticeBll = new WXPayNoticeBLL(currentUserInfo); var entity = wxPayNoticeBll.QueryByEntity(new WXPayNoticeEntity() { OutTradeNo = outTradeNo, OpenId = openID }, null); if (entity != null) { wxPayNoticeBll.Delete(entity); } wxPayNoticeBll.Create(wxPayNoticeEntity); //将请求数据记录到表中、方便维权的时候试用 //1.向表中记录该笔支付是否成功,如不成功,将失败原因记录下来【status = 1 成功 0 失败 2 支付金额与订单金额不符】 //2.判断支付是否成功 //if (tradeState == "0")//成功 //{ // //3.根据订单号查询该笔订单的金额是否相符,如不符合,记录信息,查看原因 //} //else//失败 //{ // // //} if (tradeState == "0") { //根据customerid获取channelid; var channelBll = new TPaymentTypeCustomerMappingBLL(currentUserInfo); var channelId = channelBll.GetChannelIdByCustomerId(customerId); var paras = "ChannelID=" + channelId + "&outTradeNo=" + outTradeNo; var url = System.Configuration.ConfigurationManager.AppSettings["wxNativePayNotifyUrl"]; JIT.Utility.Log.Loggers.Debug(new Utility.Log.DebugLogInfo() { Message = url + "?" + paras }); var response = JIT.Utility.Web.HttpClient.PostQueryString(url, paras); JIT.Utility.Log.Loggers.Debug(new Utility.Log.DebugLogInfo() { Message = response }); } #region 向表中记录调用的微信接口 var wxInterfaceLogBll = new WXInterfaceLogBLL(currentUserInfo); var wxInterfaceLogEntity = new WXInterfaceLogEntity(); wxInterfaceLogEntity.LogId = Guid.NewGuid(); wxInterfaceLogEntity.InterfaceUrl = System.Configuration.ConfigurationManager.AppSettings["wxNativePayNotifyUrl"]; wxInterfaceLogEntity.AppId = appId; wxInterfaceLogEntity.OpenId = openID; wxInterfaceLogEntity.RequestParam = wxPayNoticeEntity.ToJSON(); wxInterfaceLogEntity.IsSuccess = 1; wxInterfaceLogBll.Create(wxInterfaceLogEntity); #endregion context.Response.Write("success"); #endregion }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Write("Hello World"); try { string xmlStr = string.Empty; using (var stream = context.Request.InputStream) { using (var rd = new StreamReader(stream, System.Text.Encoding.UTF8)) { xmlStr = rd.ReadToEnd(); JIT.Utility.Log.Loggers.Debug(new Utility.Log.DebugLogInfo() { Message = string.Format("警告通知:{0}", xmlStr) }); } } var doc = new XmlDocument(); doc.LoadXml(xmlStr); var dic = new Dictionary <string, string>(); //遍历参数节点 var list = doc.SelectNodes("xml/*"); foreach (XmlNode item in list) { dic[item.Name] = item.InnerText; } var warning = dic.ToJSON().DeserializeJSONTo <WxWarningInfo>(); var customerWxMappingBll = new TCustomerWeiXinMappingBLL(Default.GetAPLoggingSession("")); var customerId = customerWxMappingBll.GetCustomerIdByAppId(warning.AppId); if (customerId == "") { throw new APIException("客户ID为空") { ErrorCode = 121 }; } var currentUserInfo = Default.GetBSLoggingSession(customerId, "1"); var alarmBll = new WXAlarmNoticeBLL(currentUserInfo); var alarmEntity = new WXAlarmNoticeEntity(); alarmEntity.AlarmNoticeId = Guid.NewGuid(); alarmEntity.AlarmNoticeCode = warning.ErrorType; //错误类型 alarmEntity.AlarmNoticeDesc = warning.AlarmContent; //错误详情 alarmEntity.AlarmNoticeRemark = warning.Description; //错误描述 alarmEntity.AlarmNoticeStatus = 10; alarmEntity.Priority = 10; alarmEntity.CustomerId = customerId; if (warning.ErrorType == "1001") //发货超时 { alarmEntity.ProposalPlan = warning.AlarmContent.Substring(warning.AlarmContent.IndexOf('=') + 1); //微信订单号 } alarmBll.Create(alarmEntity); #region 向表中记录调用的微信接口 var wxInterfaceLogBll = new WXInterfaceLogBLL(currentUserInfo); var wxInterfaceLogEntity = new WXInterfaceLogEntity(); wxInterfaceLogEntity.LogId = Guid.NewGuid(); wxInterfaceLogEntity.InterfaceUrl = "微信公众号配置的警告URL"; wxInterfaceLogEntity.AppId = warning.AppId; wxInterfaceLogEntity.RequestParam = warning.ToJSON(); wxInterfaceLogEntity.IsSuccess = 1; wxInterfaceLogBll.Create(wxInterfaceLogEntity); #endregion context.Response.Write("success"); } catch (Exception ex) { JIT.Utility.Log.Loggers.Debug(new Utility.Log.DebugLogInfo() { Message = ex.Message }); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; try { string xmlStr = string.Empty; using (var stream = context.Request.InputStream) { using (var rd = new StreamReader(stream, System.Text.Encoding.UTF8)) { xmlStr = rd.ReadToEnd(); JIT.Utility.Log.Loggers.Debug(new Utility.Log.DebugLogInfo() { Message = string.Format("用户维权:收到的通知信息:{0}", xmlStr) }); } } var doc = new XmlDocument(); doc.LoadXml(xmlStr); var dic = new Dictionary <string, string>(); var ds = new DataSet(); //遍历参数节点 var list = doc.SelectNodes("xml/*"); foreach (XmlNode item in list) { if (item.Name != "PicInfo") { dic[item.Name] = item.InnerText; } else { //将图片读取到DS中 var stream = new StringReader("<PicInfo>" + item.InnerXml + "</PicInfo>"); var reader = new XmlTextReader(stream); ds.ReadXml(reader); } } #region 维权对象,不带图片 #endregion #region 图片对象 //遍历ds,向图片表插入数据 #endregion var notify = dic.ToJSON().DeserializeJSONTo <WXRightOrdersEntity>(); var customerWxMappingBll = new TCustomerWeiXinMappingBLL(Default.GetAPLoggingSession("")); var customerId = customerWxMappingBll.GetCustomerIdByAppId(notify.AppId); if (customerId == "") { throw new APIException("客户ID为空") { ErrorCode = 121 }; } var currentUserInfo = Default.GetBSLoggingSession(customerId, "1"); var bll = new WXRightOrdersBLL(currentUserInfo); //根据维权单号,查询是否有数据 var entity = bll.QueryByEntity(new WXRightOrdersEntity() { FeedBackId = notify.FeedBackId }, null); #region 验签 ////支付中心URL //var url = System.Configuration.ConfigurationManager.AppSettings["paymentcenterUrl"]; //url = "http://121.199.42.125:6002/DevPayTest.ashx";//测试,正式需删除此行 //var customerID = "e703dbedadd943abacf864531decdac1";//先写死测试 //var paraSign = new Dictionary<string, string>(); //paraSign["openid"] = notify.OpenId; //paraSign["timestamp"] = notify.TimeStamp; //var request = new //{ // AppID = notify.AppId, // ClientID = customerID, // UserID = notify.OpenId, // Parameters = paraSign //}; //string content = string.Format("action=WXGetSign&request={0}", request.ToJSON()); //string resStr = string.Empty; //try //{ // resStr = JIT.Utility.Web.HttpClient.PostQueryString(url, content); //} //catch (Exception ex) //{ // JIT.Utility.Log.Loggers.Exception(new Utility.Log.ExceptionLogInfo(ex)); // throw ex; //} //var dicGetSign = resStr.DeserializeJSONTo<Dictionary<string, object>>(); //if (Convert.ToInt32(dicGetSign["ResultCode"]) < 100) //{ // var dicData = dicGetSign["Datas"].ToJSON().DeserializeJSONTo<Dictionary<string, string>>(); // var sign = dicData["Sign"].ToString(); // if (sign != notify.AppSignature) // throw new Exception(string.Format("验签失败,原:{0}\t新:{1}", notify.AppSignature, sign)); //} //else //{ // throw new Exception(string.Format("错误信息:{0}", dicGetSign["Message"])); //} #endregion var conEntity = bll.QueryByEntity(new WXRightOrdersEntity() { FeedBackId = notify.FeedBackId }, null).FirstOrDefault(); switch (notify.MsgType) { case "request": //新的维权 //TODO:新增记录 JIT.Utility.Log.Loggers.Debug(new Utility.Log.DebugLogInfo() { Message = string.Format("新增一条用户维权:{0}", notify.ToJSON()) }); if (entity != null) { //删除原有的维权单 bll.Delete(entity); } notify.Status = 10; var rightOrderId = Guid.NewGuid(); notify.RightOrdersId = rightOrderId; notify.CustomerId = customerId; bll.Create(notify); var objectImages = new ObjectImagesEntity(); var objectImageList = new List <ObjectImagesEntity>(); var imageBll = new ObjectImagesBLL(currentUserInfo); int i = 0; foreach (DataRow row in ds.Tables[0].Rows) { i++; objectImages.ImageURL = row[0].ToString(); objectImages.ObjectId = Convert.ToString(rightOrderId); objectImages.ImageId = Convert.ToString(Guid.NewGuid()); objectImages.DisplayIndex = i; objectImages.CustomerId = customerId; //将维权单的url插入到图片表中 imageBll.Create(objectImages); } //var feedBackPara = new //{ // PayChannelID = 9, // FeedBackID = notify.FeedBackId, // OpenID = notify.OpenId //}; //var feedBackRequest = new //{ // AppID = notify.AppId, // ClientID = customerID, // UserID = notify.OpenId, // Parameters = paraSign //}; //content = string.Format("action=WXGetUpdateFeedBackUrl&request={0}", feedBackRequest.ToJSON()); //resStr = string.Empty; //try //{ // resStr = JIT.Utility.Web.HttpClient.PostQueryString(url, content); //} //catch (Exception ex) //{ // throw ex; //} //var dicFeedBack = resStr.DeserializeJSONTo<Dictionary<string, object>>(); //if (Convert.ToInt32(dicFeedBack["ResultCode"]) < 100) //{ // var dicData = dicFeedBack["Datas"].ToJSON().DeserializeJSONTo<Dictionary<string, string>>(); // var feedBackUrl = dicData["Url"].ToString(); // string resStrFeedBack = string.Empty; // try // { // resStrFeedBack = JIT.Utility.Web.HttpClient.GetQueryString(feedBackUrl); // dicFeedBack = resStrFeedBack.DeserializeJSONTo<Dictionary<string, object>>(); // } // catch (Exception ex) // { // throw ex; // } //} //else //{ // throw new Exception(string.Format("错误信息:{0}", dicGetSign["Message"])); //} break; case "confirm": //客户同意解决 //TODO:对已有的记录Update JIT.Utility.Log.Loggers.Debug(new Utility.Log.DebugLogInfo() { Message = string.Format("客户同意维权解决:{0}", notify.ToJSON()) }); if (conEntity != null) { conEntity.Status = 50; conEntity.MsgType = "confirm"; conEntity.Reason = notify.Reason; conEntity.TimeStamp = notify.TimeStamp; bll.Update(conEntity); } break; case "reject": //客户拒绝解决 //TODO:对已有的记录Update,同时如何处理?? JIT.Utility.Log.Loggers.Debug(new Utility.Log.DebugLogInfo() { Message = string.Format("客户拒绝维权解决:{0}", notify.ToJSON()) }); if (conEntity != null) { conEntity.Status = 60; conEntity.MsgType = "reject"; conEntity.Reason = notify.Reason; conEntity.TimeStamp = notify.TimeStamp; bll.Update(conEntity); } break; default: break; } #region 向表中记录调用的微信接口 var wxInterfaceLogBll = new WXInterfaceLogBLL(currentUserInfo); var wxInterfaceLogEntity = new WXInterfaceLogEntity(); wxInterfaceLogEntity.LogId = Guid.NewGuid(); wxInterfaceLogEntity.InterfaceUrl = "微信公众号配置的维权URL"; wxInterfaceLogEntity.AppId = notify.AppId; wxInterfaceLogEntity.OpenId = notify.OpenId; wxInterfaceLogEntity.RequestParam = notify.ToJSON(); wxInterfaceLogEntity.IsSuccess = 1; wxInterfaceLogBll.Create(wxInterfaceLogEntity); #endregion } catch (Exception ex) { JIT.Utility.Log.Loggers.Exception(new Utility.Log.ExceptionLogInfo(ex)); context.Response.Write(ex); } }