SpringMvc微信付出回調示例代碼。本站提示廣大學習愛好者:(SpringMvc微信付出回調示例代碼)文章只能為提供參考,不一定能成為您想要的結果。以下是SpringMvc微信付出回調示例代碼正文
引見
年夜家都曉得微信付出的回調鏈接請求不克不及跟參數,但又要吸收前往的xml數據。我開端應用@RequestBody注解在參數上,願望能獲得xml數據,測試掉敗。最初應用HttpServletRequest去獲得數據勝利了。
示例代碼
@RequestMapping("/weixinpay/callback")
public String callBack(HttpServletRequest request){
InputStream is = request.getInputStream();
String xml = StreamUtil.inputStream2String(is, "UTF-8")
/**
* 前面把xml轉成Map依據數據作邏輯處置
*/
}
/**
* InputStream流轉換成String字符串
* @param inStream InputStream流
* @param encoding 編碼格局
* @return String字符串
*/
public static String inputStream2String(InputStream inStream, String encoding){
String result = null;
try {
if(inStream != null){
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] tempBytes = new byte[_buffer_size];
int count = -1;
while((count = inStream.read(tempBytes, 0, _buffer_size)) != -1){
outStream.write(tempBytes, 0, count);
}
tempBytes = null;
outStream.flush();
result = new String(outStream.toByteArray(), encoding);
}
} catch (Exception e) {
result = null;
}
return result;
}
總結
以上就是這篇文章的全體內容了,願望能對年夜家的進修或許任務帶來必定的贊助,假如有疑問年夜家可以留言交換。