国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Java > 正文

SpringMvc微信支付回調示例代碼

2019-11-26 13:45:59
字體:
來源:轉載
供稿:網友

介紹

大家都知道微信支付的回調鏈接要求不能跟參數,但又要接收返回的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;}

總結

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 林甸县| 新绛县| 谷城县| 永定县| 渭南市| 乌兰县| 洪江市| 巍山| 双辽市| 凉城县| 九江县| 永寿县| 壤塘县| 沙河市| 铜川市| 岳普湖县| 延吉市| 集安市| 宝丰县| 南澳县| 阿拉善左旗| 开江县| 锡林郭勒盟| 安龙县| 聂拉木县| 浙江省| 灵武市| 株洲县| 延长县| 宁波市| 东乌珠穆沁旗| 宁阳县| 泰顺县| 拜城县| 洛隆县| 临武县| 合作市| 乐清市| 泗阳县| 德惠市| 佛教|