欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SpringMvc微信支付回調(diào)示例代碼

 更新時間:2016年09月30日 16:39:55   投稿:daisy  
微信一直是一個比較熱門的詞匯,今天這篇文章主要介紹的是SpringMvc微信支付回調(diào)的示例代碼,對大家開發(fā)微信支付具有一定的參考借鑒價值,下面來一起看看吧。

介紹

大家都知道微信支付的回調(diào)鏈接要求不能跟參數(shù),但又要接收返回的xml數(shù)據(jù)。我開始使用@RequestBody注解在參數(shù)上,希望能獲取xml數(shù)據(jù),測試失敗。最后使用HttpServletRequest去獲取數(shù)據(jù)成功了。

示例代碼

@RequestMapping("/weixinpay/callback")
public String callBack(HttpServletRequest request){
 InputStream is = request.getInputStream();
 String xml = StreamUtil.inputStream2String(is, "UTF-8")
 /**
 * 后面把xml轉(zhuǎn)成Map根據(jù)數(shù)據(jù)作邏輯處理
 */
}
/**
 * InputStream流轉(zhuǎn)換成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;
}

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望能對大家的學(xué)習(xí)或者工作帶來一定的幫助,如果有疑問大家可以留言交流。

相關(guān)文章

最新評論