首页 > 代码库 > C#微信开发之旅(十二):V2告警接口&维权接口

C#微信开发之旅(十二):V2告警接口&维权接口

告警接口,是微信用来通知我们一样警告信息,可以存储到DB定期查看并解决;维权则是用户主动发起的,需要我们处理。。。。

  1      /// <summary>  2         /// 维权通知  3         /// </summary>  4         /// <returns></returns>  5         public void Notice()  6         {  7             #region 用户新增维权  8   9             /* 10              * <xml> 11              * <OpenId><![CDATA[o0pk9uIVnlY-fJkzFKEbQ6LJ4cFc]]></OpenId> 12              * <AppId><![CDATA[wxc04ce1d87dcd13cd]]></AppId> 13              * <TimeStamp>1401206434</TimeStamp> 14              * <MsgType><![CDATA[request]]></MsgType> 15              * <FeedBackId>13275936403980775178</FeedBackId> 16              * <TransId><![CDATA[1218614901201405273313470595]]></TransId> 17              * <Reason><![CDATA[没有收到货品]]></Reason> 18              * <Solution><![CDATA[退款,并不退货]]></Solution> 19              * <ExtInfo><![CDATA[Test 13456780012]]></ExtInfo> 20              * <AppSignature><![CDATA[1f4a626f59f9ae8007158b0a9510e88db56fa80b]]></AppSignature> 21              * <SignMethod><![CDATA[sha1]]></SignMethod> 22              * </xml> 23              */ 24             #endregion 25  26             #region 用户确认处理完毕投诉 27             /* 28              * <xml> 29              * <OpenId><![CDATA[111222]]></OpenId> 30              * <AppId><![CDATA[wwwwb4f85f3a797777]]></AppId> 31              * <TimeStamp>1369743511</TimeStamp> 32              * <MsgType><![CDATA[confirm/reject]]></MsgType> 33              * <FeedBackId><![CDATA[5883726847655944563]]></FeedBackId> 34              * <Reason><![CDATA[商品质量有问题]]></Reason> 35              * <AppSignature><![CDATA[bafe07f060f22dcda0bfdb4b5ff756f973aecffa]]></AppSignature> 36              * <SignMethod><![CDATA[sha1]]></SignMethod> 37              * </xml> 38              */ 39             #endregion 40  41             try 42             { 43                 string xmlString = GetXmlString(Request); 44                 XmlDocument xml = new XmlDocument(); 45                 xml.LoadXml(xmlString); 46                 //记录日志 47  48                 //维权处理 49                 var msgType = xml.SelectSingleNode("/xml/MsgType").InnerText.ToLower(); 50  51                 switch (msgType) 52                 { 53                     case "request": 54                         //用户新增维权   55                         //dosomething() 56                         break; 57                     case "confirm/reject": 58                         //用户确认处理完毕投诉  相关操作 59                         //dosomething() 60                         break; 61                     default: 62                         break; 63                 } 64                 Response.Write("success"); 65             } 66             catch (Exception ex) 67             { 68                 //记录日志 69                 Response.Write(ex.Message); 70             } 71             Response.End(); 72         } 73  74         /// <summary> 75         /// 告警通知 76         /// </summary> 77         /// <returns></returns> 78         public void Warning() 79         { 80             #region Xml格式 81             /* 82              * <xml> 83              * <AppId><![CDATA[wxf8b4f85f3a794e77]]></AppId> 84              * <ErrorType>1001</ErrorType> 85              * <Description><![CDATA[错识描述]]></Description> 86              * <AlarmContent><![CDATA[错误详情]]></AlarmContent> 87              * <TimeStamp>1393860740</TimeStamp> 88              * <AppSignature><![CDATA[f8164781a303f4d5a944a2dfc68411a8c7e4fbea]]></AppSignature> 89              * <SignMethod><![CDATA[sha1]]></SignMethod> 90              * </xml> 91              */ 92             #endregion 93  94             try 95             { 96                 string xmlString = GetXmlString(Request); 97                 XmlDocument xml = new XmlDocument(); 98                 xml.LoadXml(xmlString); 99                 //记录日志100 101                 //写到db 或其他处理102 103                 Response.Write("success");104             }105             catch (Exception ex)106             {107                 //记录日志108                 Response.Write(ex.Message);109             }110             Response.End();111         }112 113         /// <summary>114         /// 获取Post Xml数据115         /// </summary>116         /// <param name="request"></param>117         /// <returns></returns>118         private string GetXmlString(HttpRequestBase request)119         {120             using (System.IO.Stream stream = request.InputStream)121             {122                 Byte[] postBytes = new Byte[stream.Length];123                 stream.Read(postBytes, 0, (Int32)stream.Length);124                 return System.Text.Encoding.UTF8.GetString(postBytes);125             }126         }

 

C#微信开发之旅(十二):V2告警接口&维权接口