建行B2B支付回调参数乱码现象解析
生活随笔
收集整理的這篇文章主要介紹了
建行B2B支付回调参数乱码现象解析
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
建行B2B支付采用Java開發(fā),頁面回調(diào)采用POST提交方式,編碼為GBK。而我們的系統(tǒng)為ASP.NET,編碼UTF-8。通過Request獲取的參數(shù)是亂碼,無奈之下,只能從InputStream解析。解析代碼如下:
?? ???? log.Debug("Request Absolute Uri:" + this.Request.Url.AbsoluteUri);
?????????? ?
??????????? //GBK解析
??????????? BinaryReader reader = new BinaryReader(this.Request.InputStream);
??????????? Byte[] bs = reader.ReadBytes((int)this.Request.InputStream.Length);
??????????? String parameter = HttpUtility.UrlDecode(Encoding.GetEncoding("ISO-8859-1").GetString(bs), Encoding.GetEncoding("GBK"));
??????????? NameValueCollection parameterDic = HttpUtility.ParseQueryString(parameter);
??????????? if (parameterDic != null && parameterDic.Count > 0)
??????????? {
??????????????? foreach (String key in parameterDic.Keys)
??????????????? {
??????????????????? log.Debug("Query Param Key:" + key + " Value:" + parameterDic[key]);
??????????????? }
??????????? }
服務(wù)端通知采用的GET方式,更郁悶的時(shí),建行竟然對中文參數(shù)不做UrlEncode操作,直接用GBK編碼回調(diào)過來,害得我們浪費(fèi)了很長時(shí)間,還是從最原始的字節(jié)碼出發(fā),代碼如下:
?????????? log.Debug("Request Absolute Uri:" + this.Request.Url.AbsoluteUri);
?????????? ?
??????????? IServiceProvider provider = (IServiceProvider)HttpContext.Current;
??????????? HttpWorkerRequest worker = (HttpWorkerRequest)provider.GetService(typeof(HttpWorkerRequest));
??????????? byte[] bs = worker.GetQueryStringRawBytes();
??????????? String queryString = Encoding.GetEncoding("GBK").GetString(bs);
??????????? log.Debug("Query String:" + queryString);
??????????? NameValueCollection querys = HttpUtility.ParseQueryString(queryString);
??????????? if (querys != null && querys.Count > 0)
??????????? {
??????????????? foreach (String key in querys.AllKeys)
??????????????? {
?????????????????? log.Debug("Query Param Key:" + key + " Value:" + querys[key]);
??????????????? }
??????????? }
?? ???? log.Debug("Request Absolute Uri:" + this.Request.Url.AbsoluteUri);
?????????? ?
??????????? //GBK解析
??????????? BinaryReader reader = new BinaryReader(this.Request.InputStream);
??????????? Byte[] bs = reader.ReadBytes((int)this.Request.InputStream.Length);
??????????? String parameter = HttpUtility.UrlDecode(Encoding.GetEncoding("ISO-8859-1").GetString(bs), Encoding.GetEncoding("GBK"));
??????????? NameValueCollection parameterDic = HttpUtility.ParseQueryString(parameter);
??????????? if (parameterDic != null && parameterDic.Count > 0)
??????????? {
??????????????? foreach (String key in parameterDic.Keys)
??????????????? {
??????????????????? log.Debug("Query Param Key:" + key + " Value:" + parameterDic[key]);
??????????????? }
??????????? }
服務(wù)端通知采用的GET方式,更郁悶的時(shí),建行竟然對中文參數(shù)不做UrlEncode操作,直接用GBK編碼回調(diào)過來,害得我們浪費(fèi)了很長時(shí)間,還是從最原始的字節(jié)碼出發(fā),代碼如下:
?????????? log.Debug("Request Absolute Uri:" + this.Request.Url.AbsoluteUri);
?????????? ?
??????????? IServiceProvider provider = (IServiceProvider)HttpContext.Current;
??????????? HttpWorkerRequest worker = (HttpWorkerRequest)provider.GetService(typeof(HttpWorkerRequest));
??????????? byte[] bs = worker.GetQueryStringRawBytes();
??????????? String queryString = Encoding.GetEncoding("GBK").GetString(bs);
??????????? log.Debug("Query String:" + queryString);
??????????? NameValueCollection querys = HttpUtility.ParseQueryString(queryString);
??????????? if (querys != null && querys.Count > 0)
??????????? {
??????????????? foreach (String key in querys.AllKeys)
??????????????? {
?????????????????? log.Debug("Query Param Key:" + key + " Value:" + querys[key]);
??????????????? }
??????????? }
轉(zhuǎn)載于:https://www.cnblogs.com/heroking2000/archive/2010/05/28/1746343.html
總結(jié)
以上是生活随笔為你收集整理的建行B2B支付回调参数乱码现象解析的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql 数据库名称限制_mysql
- 下一篇: 含泪入坑 GMSSL